feat(release): stage exact SHA on dev before automatic production
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
# Gitea push main -> production only if the identical SHA is live on release dev.
|
||||
set -euo pipefail
|
||||
|
||||
sha="${EXPECTED_SHA:?EXPECTED_SHA is required}"
|
||||
test "${EXPECTED_REF:-}" = refs/heads/main
|
||||
test "$(git rev-parse HEAD)" = "$sha"
|
||||
checkout=$(pwd -P)
|
||||
stage=/home/mcp-user/smeta-web-release
|
||||
prod=/home/mcp-user/smeta-web
|
||||
index=data/real_corpus/estimates_ext_index.json
|
||||
marker=/data_safe/backups/smeta-web/release-ready.json
|
||||
log="/data_safe/backups/smeta-web/release-prod-${sha:0:12}.log"
|
||||
|
||||
exec 9>/tmp/smeta-release-deploy.lock
|
||||
flock -w 1800 9
|
||||
test "$(git -C "$prod" branch --show-current)" = main
|
||||
remote=$(HTTPS_PROXY= HTTP_PROXY= NO_PROXY='*' git -C "$prod" ls-remote --exit-code origin refs/heads/main | cut -f1)
|
||||
test "$remote" = "$sha"
|
||||
HTTPS_PROXY= HTTP_PROXY= NO_PROXY='*' git -C "$prod" fetch -q origin main
|
||||
git -C "$prod" merge-base --is-ancestor HEAD "$sha"
|
||||
python3 "$checkout/scripts/release_gate.py" verify "$sha" "$stage" "$prod/$index" "$marker"
|
||||
systemctl is-active --quiet smeta-web-release
|
||||
curl -fsS --noproxy '*' http://127.0.0.1:8106/health | grep -q '"status":"ok"'
|
||||
index_before=$(sha256sum "$prod/$index" | cut -d' ' -f1)
|
||||
env_before=$(sha256sum "$prod/.env" | cut -d' ' -f1)
|
||||
|
||||
# Fresh full gate for this exact main push; the dev approval can be days old.
|
||||
cp "$prod/$index" "$checkout/$index"
|
||||
sqlite3 "$prod/smeta-web.db" ".backup $checkout/smeta-web.db"
|
||||
APP_DIR="$checkout" COPY_DIR=/home/mcp-user/smeta-prod-auto-predeploy \
|
||||
bash "$checkout/scripts/predeploy-tests.sh" > "$log" 2>&1 || {
|
||||
tail -30 "$log" >&2
|
||||
exit 1
|
||||
}
|
||||
test "$(head -n 1 "$checkout/.predeploy-stamp")" = "$sha"
|
||||
test "$(sha256sum "$prod/$index" | cut -d' ' -f1)" = "$index_before"
|
||||
test "$(sha256sum "$prod/.env" | cut -d' ' -f1)" = "$env_before"
|
||||
test "$(HTTPS_PROXY= HTTP_PROXY= NO_PROXY='*' git -C "$prod" ls-remote --exit-code origin refs/heads/main | cut -f1)" = "$sha"
|
||||
python3 "$checkout/scripts/release_gate.py" verify "$sha" "$stage" "$prod/$index" "$marker"
|
||||
cp "$checkout/.predeploy-stamp" "$prod/.predeploy-stamp"
|
||||
APP_DIR="$prod" bash "$prod/scripts/deploy.sh"
|
||||
|
||||
test "$(git -C "$prod" rev-parse HEAD)" = "$sha"
|
||||
test "$(sha256sum "$prod/$index" | cut -d' ' -f1)" = "$index_before"
|
||||
test "$(sha256sum "$prod/.env" | cut -d' ' -f1)" = "$env_before"
|
||||
systemctl is-active --quiet smeta-web
|
||||
curl -fsS --noproxy '*' http://127.0.0.1:8101/health | grep -q '"status":"ok"'
|
||||
(cd "$prod" && set -a && . ./.env && set +a &&
|
||||
python3 -c 'import health_checks; assert health_checks.check_unpriced_runs().ok')
|
||||
canary=$(cd "$prod" && CANARY_DRY_RUN=1 \
|
||||
JOURNEY_STATE=/tmp/smeta-release-journey.state bash scripts/journey_canary.sh)
|
||||
printf '%s\n' "$canary"
|
||||
[[ "$canary" == *' OK journey:'* ]]
|
||||
echo "RELEASE_PROD_OK sha=$sha log=$log"
|
||||
Reference in New Issue
Block a user