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 in config.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 Townconfig.json
to point to the repo and vals you plan to sync/deploy
route, e.g. https://username-<ID>.web.val.run/deploy
GITHUB_WEBHOOK_SECRET
GITHUB_TOKEN
env var in this valVALTOWN_TOKEN
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.
NOTE: this can overwrite changes made outside of Val Town, on GitHub/etc.
// This can post to the GitHubSync `/push` webhook; keep this private
import sign from "https://esm.town/v/jxnblk/GitHubSync/sign-webhook";
const secret = Deno.env.get("SECRET") as string;
const url = Deno.env.get("PUSH_URL") as string;
async function pushValsToGitHub() {
const body = "hello";
const signature = await sign(body, secret);
const res = await fetch(url, {
method: "POST",
body,
headers: {
"x-val-signature": signature,
}
})
if (!res.ok) {
console.log(res);
return;
}
const json = await res.json();
console.log(json);
}
pushValsToGitHub();
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 GitHubGITHUB_WEBHOOK_SECRET
: secret for verifying webhooks from GitHubVAL_SECRET
: secret for verifying requests to the /push
endpointThis is the latest version of https://www.val.town/v/jxnblk/gitHubSync. Note: This will currently only work with non-project vals until the SDK supports projects.