Build & Deploy / Build & push images (push) Successful in 4m35s
Build & Deploy / Deploy Firestore rules & indexes (push) Successful in 1m34s
Build & Deploy / Deploy to VM (push) Successful in 1m54s
Build & Deploy / Report a failed deploy (push) Skipped
Build & Deploy / Tag release (push) Successful in 5s
VERSION holds MAJOR.MINOR (1.1). The build job works out the next patch (scripts/next-version.sh, integer count) and stamps it into c2-core as DRB_VERSION, which /health returns. The new "Tag release" job tags the commit only after the deploy job succeeds, so a failed deploy's number is reused. Node checkins carry `version`, stored on the node doc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
504 lines
24 KiB
YAML
504 lines
24 KiB
YAML
name: Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
# REGISTRY secret = "git.vpn.cusano.net/logan" (full image prefix)
|
|
REGISTRY: ${{ secrets.REGISTRY }}
|
|
|
|
jobs:
|
|
build:
|
|
name: Build & push images
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.version.outputs.version }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# node-26#49: this build's release, vMAJOR.MINOR.PATCH. Tagged only once
|
|
# the deploy is healthy (job "tag" below), so a failed deploy's number is
|
|
# reused by the next push.
|
|
- name: Work out the release version
|
|
id: version
|
|
run: |
|
|
git fetch --force --tags origin
|
|
TAG="$(bash scripts/next-version.sh)"
|
|
if [ -z "$TAG" ]; then
|
|
TAG="$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -t. -k3,3n | tail -1)"
|
|
fi
|
|
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
|
|
echo "release ${TAG}"
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: git.vpn.cusano.net
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.BUILD_TOKEN }}
|
|
|
|
- name: Build & push c2-core
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./drb-c2-core
|
|
push: true
|
|
build-args: |
|
|
GIT_SHA=${{ gitea.sha }}
|
|
DRB_VERSION=${{ steps.version.outputs.version }}
|
|
tags: |
|
|
${{ env.REGISTRY }}/c2-core:latest
|
|
${{ env.REGISTRY }}/c2-core:${{ gitea.sha }}
|
|
|
|
- name: Build & push discord-bot
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./drb-server-discord-bot
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/discord-bot:latest
|
|
${{ env.REGISTRY }}/discord-bot:${{ gitea.sha }}
|
|
|
|
- name: Build & push frontend
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./drb-frontend
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/frontend:latest
|
|
${{ env.REGISTRY }}/frontend:${{ gitea.sha }}
|
|
build-args: |
|
|
NEXT_PUBLIC_C2_URL=https://api.${{ secrets.DRB_DOMAIN }}
|
|
NEXT_PUBLIC_FIREBASE_API_KEY=${{ secrets.FIREBASE_API_KEY }}
|
|
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${{ secrets.FIREBASE_AUTH_DOMAIN }}
|
|
NEXT_PUBLIC_FIREBASE_PROJECT_ID=${{ secrets.FIREBASE_PROJECT_ID }}
|
|
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${{ secrets.FIREBASE_STORAGE_BUCKET }}
|
|
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${{ secrets.FIREBASE_MESSAGING_SENDER_ID }}
|
|
NEXT_PUBLIC_FIREBASE_APP_ID=${{ secrets.FIREBASE_APP_ID }}
|
|
NEXT_PUBLIC_FIRESTORE_DATABASE=${{ secrets.FIRESTORE_DATABASE }}
|
|
NEXT_PUBLIC_MAP_TILE_URL=https://tile.openstreetmap.org/{z}/{x}/{y}.png
|
|
|
|
deploy:
|
|
name: Deploy to VM
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
# server-26#167: without this, two merges a few minutes apart had two
|
|
# "Deploy to VM" jobs on the VM at once (runs 616/617, 652/656): racing
|
|
# `compose pull && up -d`, one run's prune breaking the other's
|
|
# prune-and-retry, and one run's health check judging the other run's
|
|
# containers. Gitea >= 1.26 honours `concurrency` (go-gitea/gitea#32751;
|
|
# older versions silently ignored it, and 1.26 also dropped the old
|
|
# implicit auto-cancel), the server runs 1.27.3. Job-level so builds still
|
|
# overlap, only the VM part is serialised. cancel-in-progress: false
|
|
# queues instead of killing a run mid-compose; a newer run joining the
|
|
# group replaces any run still waiting, and the Deploy step below skips a
|
|
# run that has stopped being main's tip, so an older SHA never lands after
|
|
# a newer one.
|
|
concurrency:
|
|
group: drb-prod-deploy
|
|
cancel-in-progress: false
|
|
outputs:
|
|
prev_sha: ${{ steps.deploy.outputs.prev_sha }}
|
|
rollback_status: ${{ steps.rollback.outputs.status }}
|
|
rollback_sha: ${{ steps.rollback.outputs.rolled_back_to }}
|
|
|
|
steps:
|
|
- name: Check runner outbound IP
|
|
run: curl -s ifconfig.me
|
|
|
|
- name: Write SSH key
|
|
run: |
|
|
printf '%s\n' "${{ secrets.SSH_PRIVATE_KEY }}" > /tmp/deploy_key
|
|
chmod 600 /tmp/deploy_key
|
|
ssh-keygen -l -f /tmp/deploy_key
|
|
|
|
- name: Deploy
|
|
id: deploy
|
|
run: |
|
|
set -o pipefail
|
|
SSH_RC=0
|
|
OUTPUT=$(ssh -o StrictHostKeyChecking=no \
|
|
-o HostKeyAlgorithms=ssh-ed25519,rsa-sha2-256,rsa-sha2-512 \
|
|
-o ConnectTimeout=15 \
|
|
-v \
|
|
-i /tmp/deploy_key \
|
|
drb@${{ secrets.SERVER_IP }} << 'ENDSSH' | tee /dev/stderr
|
|
set -e
|
|
cd /opt/drb
|
|
|
|
# server-26#129: every deploy pushes 3 freshly SHA-tagged images and
|
|
# nothing ever removed the old ones except a prune that only ran
|
|
# AFTER a successful `compose pull` -- so a run that never got that
|
|
# far (this one) left the leak unaddressed forever. That silently
|
|
# filled the disk to 100% over ~week of deploys (2026-09-12: 29G/29G
|
|
# used, 96 of 100 local images unreferenced, 23.76GB reclaimable) and
|
|
# took `git pull` itself down with "No space left on device" before
|
|
# the deploy could even determine a rollback target. Prune BEFORE
|
|
# doing anything else, not after: `docker image prune -af` only
|
|
# removes images with no container referencing them, so it can never
|
|
# touch what's currently running -- there is nothing here for a
|
|
# mid-flight deploy to lose. Warn-not-fail: a prune failure must not
|
|
# block a deploy that doesn't actually need the space this time.
|
|
docker image prune -af || echo "WARNING: pre-deploy image prune failed (server-26#129) -- disk pressure may persist"
|
|
|
|
# server-26#167: only main's tip deploys. Serialising (the job's
|
|
# concurrency group) stops two runs overlapping, but not an older
|
|
# run going AFTER a newer one (its build finished later, or someone
|
|
# re-ran it), which would silently roll prod back. A superseded run
|
|
# exits clean before pulling or restarting anything; the newer run carries this
|
|
# commit's changes anyway. To deliberately put an older build back,
|
|
# use TAG=<sha> by hand on the VM, not a re-run. Runs AFTER the
|
|
# server-26#129 prune above on purpose: on a full disk `git fetch` can
|
|
# fail too, and that prune must stay the first thing a deploy does.
|
|
git fetch -q origin main
|
|
MAIN_TIP=$(git rev-parse origin/main)
|
|
if [ "$MAIN_TIP" != "${{ gitea.sha }}" ]; then
|
|
echo "SUPERSEDED=$MAIN_TIP"
|
|
exit 0
|
|
fi
|
|
|
|
# Update compose files + mosquitto config
|
|
git pull origin main
|
|
|
|
# server-26#51: Firestore rules/indexes deploy used to be attempted
|
|
# HERE, over SSH, gated on the VM having firebase-tools installed.
|
|
# It never did (no node on the VM), so this silently warned and
|
|
# skipped on every deploy for weeks -- PR #124 even auto-closed
|
|
# #13/#51 as if it were fixed. Moved to a standalone
|
|
# deploy-firestore-rules job below that runs on the Gitea runner
|
|
# itself (which always has node), so it no longer depends on
|
|
# anything being pre-installed on this VM.
|
|
|
|
# server-26#65: capture what is actually live BEFORE switching, so
|
|
# a bad deploy has something concrete to fall back to. This reads
|
|
# from a state file rather than re-deriving it from git log,
|
|
# because a PRIOR deploy could itself have failed and already
|
|
# rolled back to something older than HEAD~1 -- the file is only
|
|
# ever written by the Health check step below, after that step
|
|
# has confirmed the tag it names actually answered /health. A
|
|
# fresh VM with no file yet falls back to :latest, same escape
|
|
# hatch as a manual `up -d` with no TAG set.
|
|
#
|
|
# server-26#156: `cat missing-file || echo latest` only falls back
|
|
# when cat itself fails (nonzero exit) -- a file that EXISTS but is
|
|
# EMPTY (the state this file was found in, 2026-09-20) makes cat
|
|
# succeed with empty output, so PREV_TAG became "" instead of
|
|
# "latest". That "" then failed the emptiness check below and
|
|
# exited 1 -- AFTER git pull + up -d had already succeeded -- which
|
|
# skips the Health check step entirely (later steps don't run after
|
|
# a failure), and Health check is the ONLY thing that ever writes a
|
|
# real value here. Self-perpetuating: every deploy failed the same
|
|
# way forever, with the app itself deploying fine underneath it.
|
|
# ${VAR:-default} covers empty AND unset in one expansion.
|
|
PREV_TAG=$(cat /opt/drb/.last_good_tag 2>/dev/null)
|
|
PREV_TAG="${PREV_TAG:-latest}"
|
|
echo "PREV_TAG=$PREV_TAG"
|
|
|
|
# Deploy THIS commit's images, not :latest. Overlapping runs are
|
|
# normal here, and with :latest whichever finishes last wins for
|
|
# both -- run 544 asserted its own SHA and found run 545's build
|
|
# already serving. compose already supports ${TAG:-latest}, so
|
|
# pinning makes each deploy deterministic and a rollback just a
|
|
# different tag. A later manual `up -d` on the VM without TAG set
|
|
# still falls back to :latest, which is the intended escape hatch.
|
|
export TAG=${{ gitea.sha }}
|
|
|
|
# Pull pre-built images and restart (no build on the VM).
|
|
#
|
|
# The retry is not defensive padding: this exact step failed fifteen
|
|
# deploys in a row (2026-08-18 to 08-20) with containerd unable to
|
|
# extract a layer -- "failed to Lchown ... no such file or directory"
|
|
# -- a corrupted entry in the snapshot store. Pruning clears the bad
|
|
# layer and the second pull succeeds. If it fails again after a
|
|
# prune that is a real problem (check the VM's disk) and should stop
|
|
# the deploy rather than be retried forever.
|
|
COMPOSE="docker compose -f docker-compose.yml -f docker-compose.prod.yml"
|
|
if ! $COMPOSE pull; then
|
|
echo "image pull failed - pruning and retrying once"
|
|
docker image prune -af
|
|
$COMPOSE pull
|
|
fi
|
|
$COMPOSE up -d --remove-orphans
|
|
# server-26#129: -f alone only removes dangling (untagged) images --
|
|
# the SHA-tagged image from every PAST deploy is not dangling, just
|
|
# unreferenced once `up -d` swaps the running container to the new
|
|
# tag, so it survived this indefinitely. -a catches those too; see
|
|
# the pre-pull prune above for why this can't touch anything live.
|
|
docker image prune -af
|
|
ENDSSH
|
|
) || SSH_RC=$?
|
|
echo "$OUTPUT"
|
|
# server-26#167: check SUPERSEDED before the ssh exit status. The
|
|
# remote `exit 0` still came back as ssh exit 1 on the VM (runs 1139,
|
|
# 1144 on 2026-10-04), so under `bash -e` a correct skip was reported
|
|
# as a failed deploy. A superseded run touched nothing, whatever ssh says.
|
|
SUPERSEDED=$(printf '%s\n' "$OUTPUT" | grep '^SUPERSEDED=' | tail -n1 | cut -d'=' -f2 || true)
|
|
if [ -n "$SUPERSEDED" ]; then
|
|
echo "main has moved on to $SUPERSEDED - this run (${{ gitea.sha }}) is superseded, nothing deployed."
|
|
echo "superseded=true" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
if [ "$SSH_RC" -ne 0 ]; then
|
|
echo "Deploy SSH session failed (exit $SSH_RC)."
|
|
exit "$SSH_RC"
|
|
fi
|
|
PREV_TAG=$(printf '%s\n' "$OUTPUT" | grep '^PREV_TAG=' | tail -n1 | cut -d'=' -f2)
|
|
if [ -z "$PREV_TAG" ]; then
|
|
echo "Could not determine the previous tag from deploy output - rollback target unknown."
|
|
exit 1
|
|
fi
|
|
echo "prev_sha=$PREV_TAG" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Health check
|
|
id: health
|
|
# A superseded run deployed nothing, so there is nothing of its own to
|
|
# check, and /health legitimately answers with the newer SHA.
|
|
if: steps.deploy.outputs.superseded != 'true'
|
|
run: |
|
|
# Poll rather than sleep-once: the container has to finish starting,
|
|
# and a fixed sleep is either too short (flaky red) or wastes time on
|
|
# every deploy. A health check that cries wolf gets ignored, which is
|
|
# the failure mode this whole job exists to prevent.
|
|
BODY=""
|
|
for _ in $(seq 1 20); do
|
|
sleep 5
|
|
BODY=$(curl -fsS https://api.${{ secrets.DRB_DOMAIN }}/health) || continue
|
|
case "$BODY" in *"${{ gitea.sha }}"*) break ;; esac
|
|
done
|
|
if [ -z "$BODY" ]; then
|
|
echo "Health check failed: /health never responded"; exit 1
|
|
fi
|
|
echo "$BODY"
|
|
|
|
# Liveness alone is not enough. A deploy can report success while the
|
|
# PREVIOUS container keeps serving -- that is how production ran
|
|
# 08-18 code for two days without a single red run. Assert that the
|
|
# build which answered is the commit we just pushed.
|
|
RUNNING=$(printf '%s' "$BODY" | tr ',' '\n' | grep git_sha | cut -d'"' -f4)
|
|
if [ "$RUNNING" != "${{ gitea.sha }}" ]; then
|
|
echo "Deployed build is '$RUNNING', expected '${{ gitea.sha }}'."
|
|
echo "The container was not actually replaced."
|
|
exit 1
|
|
fi
|
|
|
|
# server-26#65: only now -- confirmed by /health, not by "up -d
|
|
# returned 0" -- record this as the rollback target for the NEXT
|
|
# deploy. A failure to write this is a bookkeeping problem, not a
|
|
# deploy problem, so it warns instead of failing the job (a hard
|
|
# failure here would trigger the Rollback step below against a
|
|
# perfectly good deploy).
|
|
ssh -o StrictHostKeyChecking=no \
|
|
-o HostKeyAlgorithms=ssh-ed25519,rsa-sha2-256,rsa-sha2-512 \
|
|
-o ConnectTimeout=15 \
|
|
-i /tmp/deploy_key \
|
|
drb@${{ secrets.SERVER_IP }} \
|
|
"echo '${{ gitea.sha }}' > /opt/drb/.last_good_tag" \
|
|
|| echo "warning: failed to persist .last_good_tag - next deploy's rollback target may be stale"
|
|
|
|
- name: Rollback on failed health check
|
|
id: rollback
|
|
if: failure()
|
|
run: |
|
|
# server-26#65 decision 3 / board minutes #62: up -d used to be the
|
|
# last word -- a build that passes tests, returns 200, and still
|
|
# corrupts incidents on live traffic would stay live for 12+ hours
|
|
# before a human noticed. This step is what makes that impossible:
|
|
# any failure above (pull, restart, or the health/SHA check) lands
|
|
# here and puts the previously-verified tag back.
|
|
PREV_TAG="${{ steps.deploy.outputs.prev_sha }}"
|
|
if [ -z "$PREV_TAG" ]; then
|
|
echo "No previous tag was captured (Deploy step itself failed before recording one) - cannot roll back automatically."
|
|
echo "status=skipped" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
echo "Rolling back to $PREV_TAG"
|
|
|
|
ssh -o StrictHostKeyChecking=no \
|
|
-o HostKeyAlgorithms=ssh-ed25519,rsa-sha2-256,rsa-sha2-512 \
|
|
-o ConnectTimeout=15 \
|
|
-i /tmp/deploy_key \
|
|
drb@${{ secrets.SERVER_IP }} << ENDSSH
|
|
set -e
|
|
cd /opt/drb
|
|
export TAG=$PREV_TAG
|
|
COMPOSE="docker compose -f docker-compose.yml -f docker-compose.prod.yml"
|
|
if ! \$COMPOSE pull; then
|
|
echo "rollback image pull failed - pruning and retrying once"
|
|
docker image prune -af
|
|
\$COMPOSE pull
|
|
fi
|
|
\$COMPOSE up -d --remove-orphans
|
|
ENDSSH
|
|
|
|
# Re-verify exactly like the forward health check does: liveness
|
|
# alone doesn't prove the rollback took, the SHA has to match the
|
|
# tag we just switched back to.
|
|
BODY=""
|
|
for _ in $(seq 1 12); do
|
|
sleep 5
|
|
BODY=$(curl -fsS https://api.${{ secrets.DRB_DOMAIN }}/health) || continue
|
|
case "$BODY" in *"$PREV_TAG"*) break ;; esac
|
|
done
|
|
|
|
RUNNING=$(printf '%s' "$BODY" | tr ',' '\n' | grep git_sha | cut -d'"' -f4)
|
|
if [ "$RUNNING" != "$PREV_TAG" ]; then
|
|
echo "ROLLBACK FAILED: expected git_sha '$PREV_TAG', got '$RUNNING'."
|
|
echo "Production state is UNKNOWN - check the VM by hand immediately."
|
|
echo "status=failed" >> "$GITHUB_OUTPUT"
|
|
echo "rolled_back_to=$PREV_TAG" >> "$GITHUB_OUTPUT"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Rolled back successfully to $PREV_TAG"
|
|
echo "status=success" >> "$GITHUB_OUTPUT"
|
|
echo "rolled_back_to=$PREV_TAG" >> "$GITHUB_OUTPUT"
|
|
|
|
deploy-firestore-rules:
|
|
name: Deploy Firestore rules & indexes
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
# server-26#167: same race as the app deploy, smaller blast radius: an
|
|
# older run's `firebase deploy` finishing last would put stale rules back.
|
|
# Its own group, so it never waits on the VM deploy.
|
|
concurrency:
|
|
group: drb-prod-firestore-rules
|
|
cancel-in-progress: false
|
|
# Deliberately independent of the `deploy` job (app containers) and its
|
|
# health-check/rollback chain above: a rules/indexes deploy failure has
|
|
# nothing to roll back (there is no previous "build" of a ruleset to
|
|
# revert to via this pipeline) and must never be conflated with an app
|
|
# deploy failure by triggering that job's rollback logic. This job
|
|
# failing is its own, separate red run -- picked up by notify-failure
|
|
# below -- not a signal to touch the running containers.
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Deploy firestore rules and indexes
|
|
env:
|
|
FIREBASE_SA_KEY: ${{ secrets.FIREBASE_SA_KEY }}
|
|
run: |
|
|
set -e
|
|
# server-26#167: only main's tip deploys rules (see the app Deploy
|
|
# step). An unreadable remote falls through to deploying, as before.
|
|
MAIN_TIP=$(git ls-remote origin refs/heads/main | cut -f1)
|
|
if [ -n "$MAIN_TIP" ] && [ "$MAIN_TIP" != "${{ gitea.sha }}" ]; then
|
|
echo "main has moved on to $MAIN_TIP - this run is superseded, rules not deployed."
|
|
exit 0
|
|
fi
|
|
# server-26#51: this used to run over SSH on the deploy VM, gated
|
|
# on the VM having firebase-tools installed. It never did, so it
|
|
# silently warned-and-skipped on every single deploy for weeks.
|
|
# Auth is a dedicated service account (drb-ci-firestore-deploy,
|
|
# roles: Firebase Rules Admin, Cloud Datastore Index Admin,
|
|
# Service Usage Consumer), its JSON key stored as the
|
|
# FIREBASE_SA_KEY secret. Not `firebase login:ci`: those tokens are
|
|
# deprecated and carry the full permissions of whoever minted them.
|
|
# A missing key fails this job LOUDLY (picked up by notify-failure).
|
|
if [ -z "$FIREBASE_SA_KEY" ]; then
|
|
echo "FIREBASE_SA_KEY secret is not set -- cannot deploy Firestore rules/indexes." >&2
|
|
echo "Add the drb-ci-firestore-deploy service account's JSON key as a Gitea Actions secret." >&2
|
|
exit 1
|
|
fi
|
|
export GOOGLE_APPLICATION_CREDENTIALS="$RUNNER_TEMP/firebase-sa.json"
|
|
trap 'rm -f "$GOOGLE_APPLICATION_CREDENTIALS"' EXIT
|
|
( umask 077 && printf '%s' "$FIREBASE_SA_KEY" > "$GOOGLE_APPLICATION_CREDENTIALS" )
|
|
npm install -g firebase-tools
|
|
cd infra/firestore
|
|
firebase deploy --only firestore:rules,firestore:indexes \
|
|
--project ${{ secrets.FIREBASE_PROJECT_ID }} --non-interactive
|
|
|
|
notify-failure:
|
|
name: Report a failed deploy
|
|
needs: [build, deploy, deploy-firestore-rules]
|
|
if: failure()
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Post to Discord
|
|
# A red run in Gitea is only visible to someone who opens Gitea, and
|
|
# nobody did for two days. Same shape as an AI tier dying quietly,
|
|
# which is why both now push a message out of the box instead of
|
|
# waiting to be discovered. No webhook configured => skip quietly
|
|
# rather than fail, since not every deployment will set one.
|
|
env:
|
|
WEBHOOK: ${{ secrets.DEPLOY_ALERT_WEBHOOK }}
|
|
RUN_URL: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_number }}
|
|
SHA: ${{ gitea.sha }}
|
|
ROLLBACK_STATUS: ${{ needs.deploy.outputs.rollback_status }}
|
|
ROLLBACK_SHA: ${{ needs.deploy.outputs.rollback_sha }}
|
|
DEPLOY_RESULT: ${{ needs.deploy.result }}
|
|
RULES_RESULT: ${{ needs.deploy-firestore-rules.result }}
|
|
run: |
|
|
if [ -z "$WEBHOOK" ]; then
|
|
echo "DEPLOY_ALERT_WEBHOOK is not set - skipping notification."
|
|
exit 0
|
|
fi
|
|
python3 - <<'PY' > /tmp/payload.json
|
|
import json, os
|
|
sha = os.environ["SHA"][:8]
|
|
run_url = os.environ["RUN_URL"]
|
|
status = os.environ.get("ROLLBACK_STATUS", "")
|
|
rollback_sha = os.environ.get("ROLLBACK_SHA", "")
|
|
deploy_result = os.environ.get("DEPLOY_RESULT", "")
|
|
rules_result = os.environ.get("RULES_RESULT", "")
|
|
|
|
# deploy-firestore-rules runs independent of the app deploy/rollback
|
|
# chain (see its own job comment), so its failure needs its own
|
|
# branch here -- otherwise this fell through to the generic "Build
|
|
# failed before any deploy was attempted" text even when the app
|
|
# deployed fine and only the Firestore rules/indexes push failed.
|
|
if deploy_result != "failure" and rules_result == "failure":
|
|
detail = "App deploy succeeded; Firestore rules/indexes deploy FAILED (server-26#51). Rules may be stale — check the FIREBASE_SA_KEY secret and the job log."
|
|
|
|
# server-26#65: the old text here unconditionally claimed
|
|
# "production is still running the previous build" -- true only
|
|
# when the pull/restart itself failed. It's false the moment a
|
|
# build passes the SHA check but has a live logic bug (exactly the
|
|
# class of bug the correlator instrumentation exists to catch), or
|
|
# once the deploy job's own rollback path has run. Say what
|
|
# actually happened instead.
|
|
elif status == "success":
|
|
detail = "Automatic rollback to `%s` succeeded. Production is back on the previous good build." % rollback_sha[:8]
|
|
elif status == "failed":
|
|
detail = ("Automatic rollback to `%s` FAILED. Production state is UNKNOWN -- "
|
|
"check the VM by hand immediately.") % rollback_sha[:8]
|
|
elif status == "skipped":
|
|
detail = "No rollback was attempted (no previous tag captured, or build/push failed before any deploy). Check the VM by hand."
|
|
else:
|
|
detail = "Build failed before any deploy was attempted. Production is unchanged."
|
|
|
|
print(json.dumps({"content":
|
|
"**DRB deploy failed** on `%s`\n%s\n%s" % (sha, run_url, detail)}))
|
|
PY
|
|
curl -sS -X POST -H "Content-Type: application/json" \
|
|
--data @/tmp/payload.json "$WEBHOOK" || echo "notification POST failed"
|
|
|
|
# node-26#49: a healthy deploy is a release. Tag it vMAJOR.MINOR.PATCH with
|
|
# the number the build stamped into /health.
|
|
tag:
|
|
name: Tag release
|
|
needs: [build, deploy]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Tag this commit
|
|
env:
|
|
VERSION: ${{ needs.build.outputs.version }}
|
|
run: |
|
|
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "no release version from build ('$VERSION')"; exit 1; }
|
|
git fetch --force --tags origin
|
|
if git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null; then
|
|
echo "v$VERSION already exists"; exit 0
|
|
fi
|
|
git tag "v$VERSION"
|
|
git push origin "refs/tags/v$VERSION"
|
|
echo "released v$VERSION"
|