Public
GitHubSync
Viewing readonly version: 164View latest version
Webhook to commit vals to GitHub and sync code from GitHub back to Val Town
This example val is synced to this GitHub repo
This val exposes two webhook endpoints:
/push
will copy the contents from a list of vals specified inconfig.json
and push them to a GitHub repo/deploy
is a GitHub webhook URL that will fetch contents from GitHub and update the code on Val Town
- Fork this val
- Edit
config.json
to point to the repo and vals you plan to sync - Create a new repo on GitHub to sync to
- Add a webhook to your repo that points to this val's
/deploy
route, e.g.https://username-<ID>.web.val.run/deploy
- Create a secret for your webhook
- In this val's Environment Variables, add that secret as
GITHUB_WEBHOOK_SECRET
- On GitHub, create a new personal access token
- Ensure the token has read/write access to Contents for the repo
- Copy the access token and add that as the
GITHUB_TOKEN
env var in this val
- Add a new Val Town API token with read/write permissions. Add that token to the val's env vars as
VALTOWN_TOKEN
- Add a
VAL_SECRET
env var to the val. Use this secret to sign the webhook POST request to the/push
endpoint. Use this endpoint to commit vals from Val Town to your GitHub repo.
You can use this example to POST to the /push
endpoint to copy vals to GitHub.
You should keep the code for this private so that only you can push to GitHub.
This example can run manually or use a Cron val
GITHUB_TOKEN
: Read/write GitHub personal access token for reading and writing repo contentsVALTOWN_TOKEN
: ValTown API token (with read/write Vals permissions) for writing updates from GitHub
This is the next version of https://www.val.town/v/jxnblk/gitHubSync
Note: This will currently only work with non-project vals until the SDK supports projects.
- Basic webhook handler w/ secrets
- GitHub commit util
- Val Town SDK to write vals
- Make private val to call sync to GitHub webhook
- auth middleware for export and deploy routes
- Add env vars
- Set up test vals
- Monkey test
- Add setup instructions to readme
- Add example code for private webhook fetch
- Make val and repo public
- Check modified date before export to GitHub??