Skip to content
Merged
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
109 changes: 109 additions & 0 deletions .github/workflows/voice-line-worker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Upload an immutable candidate only. Promotion is a separate approved workflow.
name: Voice line Worker upload

on:
workflow_dispatch:

permissions:
contents: read
actions: read

concurrency:
group: voice-line-worker-upload
cancel-in-progress: false

jobs:
verify-environment:
if: github.repository == 'developing-today/code' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
name: ${{ steps.verify.outputs.name }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 24.22.0
- name: Require existing protected Voice Line environment
id: verify
env:
GH_TOKEN: ${{ github.token }}
VOICE_LINE_ENVIRONMENT: voice-line-worker-upload
run: |
set -euo pipefail
node pm-stack/voice-line-worker/scripts/check-environment.mjs "$VOICE_LINE_ENVIRONMENT"
echo "name=$VOICE_LINE_ENVIRONMENT" >> "$GITHUB_OUTPUT"

upload:
needs: verify-environment
if: github.repository == 'developing-today/code' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 20
environment:
name: ${{ needs.verify-environment.outputs.name }}
env:
CF_SEND_TELEMETRY: "false"
WRANGLER_SEND_METRICS: "false"
CLOUDFLARE_CI_OVERRIDE_WORKER_NAME: ''
WRANGLER_CI_OVERRIDE_NAME: ''
CF_WORKER_NAME: ''
CLOUDFLARE_WORKER_NAME: ''
WRANGLER_WORKER_NAME: ''
CF_MODE: ''
CLOUDFLARE_ENV: ''
WRANGLER_ENV: ''
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 24.22.0

- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0

- name: Stage the pinned CI toolchain without replacing operator files
working-directory: pm-stack/voice-line-worker
run: |
set -euo pipefail
mkdir -p -- .cloudflare
mkdir -m 700 -- .cloudflare/voice-line-release
install -m 644 -- ci/package.json ci/bun.lock .cloudflare/voice-line-release/
cp -R -- src scripts test cloudflare.config.ts tsconfig.json .cloudflare/voice-line-release/
install -m 644 -- ci/deployment-config.check.mjs .cloudflare/voice-line-release/test/deployment-config.test.mjs

- name: Install worker dependencies
working-directory: pm-stack/voice-line-worker/.cloudflare/voice-line-release
run: bun install --frozen-lockfile --ignore-scripts

- name: Test offline worker and deployment contracts
working-directory: pm-stack/voice-line-worker/.cloudflare/voice-line-release
run: |
bun test
node --test test/{deployment-config,deploy-contract,release-safety}.test.mjs
bun run typecheck

- name: Build the Worker with cf
working-directory: pm-stack/voice-line-worker/.cloudflare/voice-line-release
run: npm run cf:build

- name: Upload an immutable Workers Version (no traffic change)
working-directory: pm-stack/voice-line-worker/.cloudflare/voice-line-release
run: npm run upload
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_VOICE_LINE_UPLOAD_TOKEN }}
VOICE_LINE_UPLOAD_RECEIPT: ${{ runner.temp }}/voice-line-upload-receipt.json

- name: Save the exact structured upload receipt
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: voice-line-upload-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/voice-line-upload-receipt.json
retention-days: 14
if-no-files-found: error
133 changes: 133 additions & 0 deletions .github/workflows/voice-line-worker-promote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Promote only a previously uploaded exact version, after environment approval.
name: Voice line Worker promote

on:
workflow_dispatch:
inputs:
version_id:
description: Cloudflare Workers Version UUID printed by the upload run
required: true
type: string
source_sha:
description: Full 40-character source commit SHA printed by the upload run
required: true
type: string
upload_run_id:
description: GitHub Actions run ID printed by the upload run
required: true
type: string
upload_run_attempt:
description: Attempt number printed by the upload run
required: true
type: string
expected_current_version_id:
description: Current 100% serving Version UUID (compare-and-check)
required: true
type: string

permissions:
contents: read
actions: read

concurrency:
group: voice-line-worker-promotion
cancel-in-progress: false

jobs:
verify-environment:
if: github.repository == 'developing-today/code' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
name: ${{ steps.verify.outputs.name }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 24.22.0
- name: Require existing protected Voice Line environment
id: verify
env:
GH_TOKEN: ${{ github.token }}
VOICE_LINE_ENVIRONMENT: voice-line-worker-production
run: |
set -euo pipefail
node pm-stack/voice-line-worker/scripts/check-environment.mjs "$VOICE_LINE_ENVIRONMENT"
echo "name=$VOICE_LINE_ENVIRONMENT" >> "$GITHUB_OUTPUT"

promote:
needs: verify-environment
if: github.repository == 'developing-today/code' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: ${{ needs.verify-environment.outputs.name }}
env:
CF_SEND_TELEMETRY: "false"
WRANGLER_SEND_METRICS: "false"
CLOUDFLARE_CI_OVERRIDE_WORKER_NAME: ''
WRANGLER_CI_OVERRIDE_NAME: ''
CF_WORKER_NAME: ''
CLOUDFLARE_WORKER_NAME: ''
WRANGLER_WORKER_NAME: ''
CF_MODE: ''
CLOUDFLARE_ENV: ''
WRANGLER_ENV: ''
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CANDIDATE_VERSION_ID: ${{ inputs.version_id }}
CANDIDATE_SOURCE_SHA: ${{ inputs.source_sha }}
CANDIDATE_UPLOAD_RUN_ID: ${{ inputs.upload_run_id }}
CANDIDATE_UPLOAD_RUN_ATTEMPT: ${{ inputs.upload_run_attempt }}
EXPECTED_CURRENT_VERSION_ID: ${{ inputs.expected_current_version_id }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 24.22.0

- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0

- name: Stage the pinned CI toolchain without replacing operator files
working-directory: pm-stack/voice-line-worker
run: |
set -euo pipefail
mkdir -p -- .cloudflare
mkdir -m 700 -- .cloudflare/voice-line-release
install -m 644 -- ci/package.json ci/bun.lock .cloudflare/voice-line-release/
cp -R -- src scripts test cloudflare.config.ts tsconfig.json .cloudflare/voice-line-release/
install -m 644 -- ci/deployment-config.check.mjs .cloudflare/voice-line-release/test/deployment-config.test.mjs

- name: Install worker dependencies
working-directory: pm-stack/voice-line-worker/.cloudflare/voice-line-release
run: bun install --frozen-lockfile --ignore-scripts

- name: Validate receipt selector
run: |
set -euo pipefail
[[ "$CANDIDATE_UPLOAD_RUN_ID" =~ ^[1-9][0-9]{0,19}$ ]]
[[ "$CANDIDATE_UPLOAD_RUN_ATTEMPT" =~ ^[1-9][0-9]{0,19}$ ]]

- name: Read exact successful upload attempt receipt
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: voice-line-upload-${{ inputs.upload_run_id }}-${{ inputs.upload_run_attempt }}
repository: developing-today/code
run-id: ${{ inputs.upload_run_id }}
github-token: ${{ github.token }}
path: ${{ runner.temp }}/voice-line-receipt

- name: Verify exact candidate provenance and serving version, then promote
working-directory: pm-stack/voice-line-worker/.cloudflare/voice-line-release
run: npm run promote
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_VOICE_LINE_PROMOTION_TOKEN }}
GH_TOKEN: ${{ github.token }}
VOICE_LINE_UPLOAD_RECEIPT: ${{ runner.temp }}/voice-line-receipt/voice-line-upload-receipt.json
1 change: 1 addition & 0 deletions pm-stack/voice-line-worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cloudflare/
69 changes: 68 additions & 1 deletion pm-stack/voice-line-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,80 @@ bunx tsc --noEmit
bunx wrangler dev # local: AI binding runs remote against the account
```

The checked-in `wrangler.toml` remains the local-development configuration.
Production changes use the pinned Cloudflare `cf` CLI and separate upload and
promotion workflows. Uploading creates an immutable Workers Version and does
not change traffic. Promotion is an explicit, separately approved operation.
The workflows stage their pinned cf/Build Output toolchain from `ci/` in a
disposable directory. This does not replace the package, lockfile, or
`wrangler.toml` used by the existing operator commands.

Use the manual GitHub Actions workflow for version uploads once both protected
environments are configured.
It creates a version tagged with the full source SHA, upload run ID, and
attempt, with the full source SHA in its message. Its receipt binds the UUID
reported by cf to the Worker, an account fingerprint, and the upload attempt;
it is published as an Actions artifact. Upload does not create a deployment
or change the serving split. Check provider Version URL settings separately:
an upload-only operation is not isolated from production resources.

GitHub Actions uploads only from a manually dispatched run on `main`; it runs
the offline tests and build first. Promotion is a different manual workflow,
also limited to `main`, and requires the uploaded Version UUID, its full source
SHA, upload run ID and attempt, and the expected currently serving Version
UUID. Before promotion the workflow checks that the source commit is reachable
from `main`, the candidate
has the exact SHA and upload-run tag plus the full-SHA message, the referenced
upload run succeeded from the expected workflow on `main` at that SHA,
Cloudflare marks it deployable, and the
currently serving deployment is a single 100% version matching the supplied
expected ID. It checks the serving version again immediately before promotion
and verifies that the exact deployment returned by cf is the latest active
deployment and serves the candidate at 100%. The immediate recheck is not an
atomic compare-and-swap against other writers; keep the release window free of
out-of-band deployment changes.

Before enabling either workflow, configure these repository environments
(environment protection and secrets cannot be declared in workflow YAML).
A preflight with only the GitHub workflow read token against the GitHub deployment environment API
halts before the deploy job attaches a missing or insufficiently protected
environment:

1. `voice-line-worker-upload`: allow deployments from `main` only; require an
independent reviewer, prevent self-review, and disallow administrator
bypass; add the environment secret
`CLOUDFLARE_VOICE_LINE_UPLOAD_TOKEN`.
2. `voice-line-worker-production`: allow deployments from `main` only; require
an independent reviewer, prevent self-review, and disallow administrator
bypass; add the environment secret
`CLOUDFLARE_VOICE_LINE_PROMOTION_TOKEN`.
3. Set the non-secret environment variable `CLOUDFLARE_ACCOUNT_ID` in both
environments.

Create separate Cloudflare API tokens with the Individual Workers Editor role
scoped only to the existing `voice-line` Worker. Store them only as the named
environment secrets above. These workflows do not read generic repository or
organization token secrets. The upload job receives only its environment
secret; the promotion job receives only its own secret after the production
environment approval passes.

No voice call or health request is part of either workflow; promotion verifies
the Cloudflare deployment read-back only.

### Existing operator path

If the protected release workflows are not ready, the existing, manually
authorized operator path is still `bun run deploy` from this directory.
That runs the locked Wrangler against `wrangler.toml` and changes serving
traffic. It is not a substitute for approving a production deployment.

Deploy needs (account-side, one time):

1. A Turso database for the ledger; set its URL in `wrangler.toml`
(`TURSO_URL` var) — the schema is created idempotently at runtime.
2. `wrangler secret put TURSO_TOKEN` and
`wrangler secret put STATUS_INGEST_TOKEN`.
3. `bun run deploy`, then push a first queue snapshot:
3. Push a first queue snapshot:
`curl -X POST <worker>/ingest-status -H "Authorization: Bearer $STATUS_INGEST_TOKEN" -d '{"queued":0,"claimed":0,"parked":0,"blocked":0}'`

## Protocol
Expand Down
Loading