Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/github-backup-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ jobs:

- name: Run the github-backup Worker tests (node --test)
run: |
test_file="infra/github-backup/worker/test/index.test.mjs"
if [ ! -f "$test_file" ]; then
echo "::error::Worker test file missing: $test_file — the suite was not run."
exit 1
fi
node --test "$test_file"
for test_file in \
infra/github-backup/worker/test/index.test.mjs \
infra/github-backup/worker/test/release-version.test.mjs; do
if [ ! -f "$test_file" ]; then
echo "::error::Worker test file missing: $test_file — the suite was not run."
exit 1
fi
done
node --test \
infra/github-backup/worker/test/index.test.mjs \
infra/github-backup/worker/test/release-version.test.mjs
echo "github-backup Worker tests passed."
185 changes: 185 additions & 0 deletions .github/workflows/github-backup-worker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: github-backup Worker release

on:
workflow_dispatch:
inputs:
operation:
description: Upload an inactive version, or promote one exact uploaded version
required: true
type: choice
options:
- upload
- promote
version_id:
description: Required for promote; the full UUID printed by an earlier upload
required: false
type: string

permissions:
contents: read

concurrency:
group: github-backup-worker-release
cancel-in-progress: false

jobs:
request-check:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Restrict releases to main and validate the requested operation
env:
GH_REF: ${{ github.ref }}
OPERATION: ${{ inputs.operation }}
VERSION_ID: ${{ inputs.version_id }}
run: |
set -euo pipefail
if [[ "$GH_REF" != "refs/heads/main" ]]; then
echo "Releases must be dispatched from main (got $GH_REF)." >&2
exit 1
fi
case "$OPERATION" in
upload)
if [[ -n "$VERSION_ID" ]]; then
echo "Leave version_id blank for an upload." >&2
exit 1
fi
;;
promote)
if [[ ! "$VERSION_ID" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ ]]; then
echo "Promotion requires the full UUID printed by an earlier upload." >&2
exit 1
fi
;;
*)
echo "Unknown operation: $OPERATION" >&2
exit 1
;;
esac

upload:
needs: request-check
if: inputs.operation == 'upload'
runs-on: ubuntu-latest
timeout-minutes: 15
environment: developing-today-backup-production
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 24.22.0
cache: npm
cache-dependency-path: infra/github-backup/worker/package-lock.json
- name: Install the pinned cf and Wrangler toolchain
working-directory: infra/github-backup/worker
run: npm ci --no-audit --no-fund
- name: Check pinned toolchain versions
working-directory: infra/github-backup/worker
env:
WRANGLER_WRITE_LOGS: "false"
run: |
set -euo pipefail
test "$(node --version)" = "v24.22.0"
test "$(npm --version)" = "11.19.1"
test "$(./node_modules/.bin/cf --version)" = "1.0.0-rc.1"
test "$(./node_modules/.bin/wrangler --version)" = "4.163.0"
- name: Upload a version without changing traffic
working-directory: infra/github-backup/worker
env:
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
BACKUP_WORKER_BEARER: ${{ secrets.BACKUP_WORKER_BEARER }}
BACKUP_WEBHOOK_SECRET: ${{ secrets.BACKUP_WEBHOOK_SECRET }}
GITHUB_SHA: ${{ github.sha }}
WRANGLER_WRITE_LOGS: "false"
run: |
set -euo pipefail
test -n "$CLOUDFLARE_ACCOUNT_ID"
test -n "$CLOUDFLARE_API_TOKEN"
test -n "$BACKUP_WORKER_BEARER"
test -n "$BACKUP_WEBHOOK_SECRET"
secret_file="$RUNNER_TEMP/backup-worker-secrets.json"
response_file="$RUNNER_TEMP/backup-worker-version.json"
trap 'rm -f "$secret_file" "$response_file"' EXIT
node --input-type=module -e '
import { writeFileSync } from "node:fs";
const values = {
DRAIN_BEARER: process.env.BACKUP_WORKER_BEARER,
GITHUB_WEBHOOK_SECRET: process.env.BACKUP_WEBHOOK_SECRET,
};
writeFileSync(process.argv[1], JSON.stringify(values), { mode: 0o600 });
' "$secret_file"
tag="gha-${GITHUB_SHA:0:12}"
cf --quiet workers versions create \
--worker developing-today-backup \
--tag "$tag" \
--message "GHA upload $GITHUB_SHA" \
--secrets-file "$secret_file" > "$response_file"
version_id=$(node release-version.mjs upload-result "$response_file")
echo "Uploaded inactive version: $version_id" >> "$GITHUB_STEP_SUMMARY"
echo "version_id=$version_id" >> "$GITHUB_OUTPUT"

promote:
needs: request-check
if: inputs.operation == 'promote'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: developing-today-backup-production
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 24.22.0
cache: npm
cache-dependency-path: infra/github-backup/worker/package-lock.json
- name: Install the pinned cf and Wrangler toolchain
working-directory: infra/github-backup/worker
run: npm ci --no-audit --no-fund
- name: Check pinned toolchain versions
working-directory: infra/github-backup/worker
env:
WRANGLER_WRITE_LOGS: "false"
run: |
set -euo pipefail
test "$(node --version)" = "v24.22.0"
test "$(npm --version)" = "11.19.1"
test "$(./node_modules/.bin/cf --version)" = "1.0.0-rc.1"
test "$(./node_modules/.bin/wrangler --version)" = "4.163.0"
- name: Verify the exact version and promote it at 100 percent
working-directory: infra/github-backup/worker
env:
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
VERSION_ID: ${{ inputs.version_id }}
WRANGLER_WRITE_LOGS: "false"
run: |
set -euo pipefail
test -n "$CLOUDFLARE_ACCOUNT_ID"
test -n "$CLOUDFLARE_API_TOKEN"
version_file="$RUNNER_TEMP/backup-worker-version.json"
deployment_file="$RUNNER_TEMP/backup-worker-deployments.json"
trap 'rm -f "$version_file" "$deployment_file"' EXIT
cf --quiet workers versions get "$VERSION_ID" --worker developing-today-backup > "$version_file"
node release-version.mjs verify-version "$version_file" "$VERSION_ID"
versions=$(node --input-type=module -e '
process.stdout.write(JSON.stringify([
{ version_id: process.env.VERSION_ID, percentage: 100 },
]));
')
cf --quiet workers deployments create \
--worker developing-today-backup \
--strategy percentage \
--versions "$versions"
cf --quiet workers deployments list --worker developing-today-backup > "$deployment_file"
node release-version.mjs verify-deployment "$deployment_file" "$VERSION_ID"
health=$(curl --fail --silent --show-error --max-time 15 \
https://developing-today-backup.developing-today.workers.dev/health)
if [[ "$health" != "ok" ]]; then
echo "Worker health endpoint returned an unexpected body after promotion." >&2
exit 1
fi
echo "Health check passed for the promoted version." >> "$GITHUB_STEP_SUMMARY"
36 changes: 36 additions & 0 deletions infra/github-backup/docs/RUNBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,42 @@ The deploy also (re)sets the Worker secrets `DRAIN_BEARER` and
`GITHUB_WEBHOOK_SECRET` from Bitwarden by name; no secret is written
to disk or printed.

### Optional GitHub Actions release path

The manual `github-backup Worker release` workflow is an additional
release path; it does not replace the operator command above. It has
two separate actions: `upload` creates a version and prints its UUID,
while `promote` requires that full UUID, verifies the version has both
secret bindings and the existing `GHB_EVENTS` KV namespace, then creates
a deployment at 100%. Upload does not change traffic. Promotion verifies
the latest deployment and `/health` afterward. It does not create,
delete, or migrate storage, and it does not edit Worker routes.

Before enabling the workflow, configure the GitHub environment
`developing-today-backup-production` in repository settings with at
least one required reviewer and restrict deployments to `main`. Add:

- Environment variable `CLOUDFLARE_ACCOUNT_ID`.
- Environment secret `CLOUDFLARE_API_TOKEN`, using the Workers `Editor`
role scoped to this existing Worker. The workflow does not need
Workers Routes write permission or direct KV access.
- Environment secrets `BACKUP_WORKER_BEARER` and
`BACKUP_WEBHOOK_SECRET`, populated from the existing Bitwarden entries
`github-app.backup-worker-bearer` and
`github-app.backup-webhook-secret`.

Then use Actions → `github-backup Worker release`, select `main`, and
run `upload`. Copy the resulting version UUID into a second manual run
with operation `promote`. The environment approval is required for both
operations. The workflow runs only on manual dispatch from `main`; it
does not receive credentials on pull requests.

The workflow pins `cf@1.0.0-rc.1`, Wrangler `4.163.0`, and Node.js
`24.22.0`. The TypeScript `cloudflare.config.ts` is the `cf` config for
the same Worker; the existing `wrangler.toml` remains in place for the
operator tool and local Wrangler workflows. Keep the worker name,
compatibility date, and KV namespace ID in those two configs aligned.

First time only — the KV namespace the Worker binds:

```sh
Expand Down
15 changes: 15 additions & 0 deletions infra/github-backup/worker/cloudflare.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { bindings, defineConfig } from "cf/config";

export default defineConfig({
worker: {
name: "developing-today-backup",
compatibilityDate: "2024-11-01",
entrypoint: "src/index.js",
env: {
// Keep the existing namespace: this is the webhook queue drained by the laptop.
GHB_EVENTS: bindings.kv({
id: "46b1fe46e6434c5fa509556ed3a53ea2",
}),
},
},
});
Loading