Skip to content

[Automated] Draft docs (kagent): controller/push: hot reload signing keys with staged activation #1079

[Automated] Draft docs (kagent): controller/push: hot reload signing keys with staged activation

[Automated] Draft docs (kagent): controller/push: hot reload signing keys with staged activation #1079

Workflow file for this run

name: Preview
# Runs on every PR to main. Builds the combined site (Hugo docs + Next.js
# marketing Worker) and uploads it as an isolated Worker VERSION with its own
# preview URL. It deliberately uses `wrangler versions upload`, NOT `deploy`, so
# production traffic is never shifted — the currently-deployed version keeps
# serving prod. Promotion to production happens only via production.yaml
# (on merge to main).
on:
pull_request:
types:
- opened
- synchronize
- reopened
branches:
- main
# Cancel superseded preview runs for the same PR.
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
# Declared explicitly so the comment step below does not depend on whatever
# the repo-wide default token permission happens to be.
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v7.0.1
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: 22.x
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: '1.24'
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.160.1'
extended: true
- name: Install dependencies
run: |
npm ci
cd docs-site && npm ci
# Builds the Hugo docs, injects them into public/docs, then builds the
# OpenNext Worker (which bundles public/ as static assets). HUGO=hugo uses
# the Hugo installed above instead of the local hugo160 alias.
- name: Build (Hugo docs + inject into /docs + Worker)
run: make build HUGO=hugo
# Derive a stable preview alias from the PR branch name. Cloudflare preview
# aliases must be a valid subdomain label (lowercase alphanumerics and
# hyphens), and `<alias>-<worker>` must stay under the 63-char DNS limit, so
# sanitize and cap the length.
- name: Compute preview alias from branch name
id: alias
env:
HEAD_REF: ${{ github.head_ref }}
run: |
alias=$(echo "$HEAD_REF" \
| tr '[:upper:]' '[:lower:]' \
| sed 's/[^a-z0-9-]/-/g; s/-\{2,\}/-/g; s/^-*//; s/-*$//' \
| cut -c1-40)
echo "alias=$alias" >> "$GITHUB_OUTPUT"
echo "Preview alias: $alias"
- name: Upload preview version (does NOT touch production)
id: deploy
uses: cloudflare/wrangler-action@v4
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# Upload a new Worker version and get a preview URL WITHOUT shifting
# production traffic. `deploy` promotes the version to 100% live, so PR
# runs were redeploying prod. `versions upload` keeps prod on the
# currently-deployed version; production is deployed only by
# production.yaml (on merge to main).
#
# --preview-alias gives a STABLE, branch-named preview URL
# (<alias>-<worker>.<subdomain>.workers.dev) that updates in place on
# each push, instead of a new per-version hostname every time.
command: versions upload --minify --preview-alias ${{ steps.alias.outputs.alias }}
- name: Print website URLs
env:
# Per-version URL (changes each push) from the wrangler-action output;
# stable alias URL built from the branch alias + fixed worker/subdomain.
VERSION_URL: ${{ steps.deploy.outputs.deployment-url }}
ALIAS: ${{ steps.alias.outputs.alias }}
run: |
echo "Version Preview URL: ${VERSION_URL}"
echo "Version Preview Alias URL: https://${ALIAS}-kagent-website.solo-io.workers.dev"
# Put the same URLs on the PR itself, so a reviewer never has to open this
# job's log to find the preview. The comment is keyed on an HTML marker:
# the first push creates it, every later push edits that same comment in
# place rather than piling up a new one per run.
#
# Fork PRs are skipped. They cannot reach the Cloudflare secrets, so the
# upload step above fails before this one runs; the guard just makes the
# intent explicit.
- name: Comment preview URLs on the PR
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.number }}
VERSION_URL: ${{ steps.deploy.outputs.deployment-url }}
ALIAS: ${{ steps.alias.outputs.alias }}
COMMIT: ${{ github.event.pull_request.head.sha }}
run: |
MARKER='<!-- preview-urls -->'
BODY=$(cat <<EOF
$MARKER
### Docs preview
| Link | Points at |
| --- | --- |
| [Branch preview](https://${ALIAS}-kagent-website.solo-io.workers.dev) | The newest push to this branch. Updates in place. |
| [Commit preview](${VERSION_URL}) | \`${COMMIT:0:7}\` only. Frozen. |
Both are uploaded Worker versions and serve no production traffic.
EOF
)
ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" --paginate \
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"${MARKER}\"))) | .id" | head -1)
if [ -n "$ID" ]; then
gh api -X PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${ID}" -f body="$BODY"
else
gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" -f body="$BODY"
fi