This is a CloudFlare Worker responsible for assisting in deploying a diary generated by Diary Generator if it's hosted on CloudFlare Pages.
On top of the usual CloudFlare pages built-in automatic deploying on
push events,
this worker runs every day at 00:00 causing a redeployment, allowing the diary
generator to publish any new entries that needs publishing.
It also expects GitHub release event webhooks to a /github
endpoint; on a new
release being published this will also cause a redeployment of the diary. This
is used to automatically listen to new releases of diary generator itself.
The code in this codebase does all of this for
Game Dev Diary but it can be setup
to be used for other diaries. If you would like to setup your own copy of all
this shenanigans feel free to reach out! You will likely need me to set up a
webhook for you on Diary Generator since GitHub allows only repository owners to
set up webhooks.
Or you set it up to only do the daily re-deployments
There are currently 3 environmental variables and 4 secrets necessary to run this worker.
ACCOUNT_ID
the account id where the pages deployment livesPROJECT_NAME
the project name for the pages deploymentDISCORD_WEBHOOK_ID
by default this project logs its messages via a Discord webhook since CloudFlare workers have no log retention. This is that webhook's id
EMAIL
the email of the account where the pages deployment livesAUTH_KEY
the global authorization key for the account where the pages deployment livesWEBHOOK_SECRET
the secret setup for the GitHub webhook used for signing and verifying the webhook requestsDISCORD_WEBHOOK_TOKEN
the Discord webhook's token
This project uses deno for everything! (and wrangler of course is needed, the more Rust the merrier after all). First project for me using deno ever and it was very much a pleasure to use. In fact there was an iteration of this project originally in Node that I gave up on quickly because I didn't feel like setting up jest and babel just to be able to run my tests.
To run tests:
deno test tests/
To build:
wrangler build
# or
mkdir -p target && deno bundle src/worker.ts target/worker.js
To format
deno fmt
To lint
deno lint
All without any complex build configurations! Thanks to Deno maintainers for the lovely project ❤️
Although CloudFlare recently related an update to pages to allow them to include a worker alongside them, it's still lacking in a lot of features (for example setting up secrets). So I went with keeping this in its own repository for now, it's also a bit simpler here since pages have a limited amount of monthly builds while workers can be deployed infinitely for free so we wouldn't wanna waste our builds to update the worker.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in diary generator by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.