This commit is contained in:
DealSage template sync
2026-09-26 05:57:32 +00:00
parent 36aeaf65c3
commit f176fca2bd
15 changed files with 472 additions and 46 deletions
+15 -9
View File
@@ -11,6 +11,7 @@
# The live pointer only ever moves after the bytes are in place.
set -euo pipefail
. "$(dirname "$0")/lib.sh"
step_start publish
require_env APP_ID DEALSAGE_FUNCTIONS_URL PUBLISH_TOKEN SUPABASE_ANON_KEY
git_context
[ -f dist/index.html ] || die "dist/index.html not found; run the build first"
@@ -21,14 +22,15 @@ checks_json="${CHECKS_RESULT_JSON:-[]}"
alloc_body="$(jq -n \
--arg appId "$APP_ID" --arg sha "$COMMIT_SHA" --arg branch "$BRANCH" \
--arg msg "$COMMIT_MESSAGE" --arg author "$COMMIT_AUTHOR" \
--argjson manifest "$manifest_json" --argjson checks "$checks_json" \
--argjson manifest "$manifest_json" --argjson checks "$checks_json" --arg build "${BUILD_ID:-}" \
'{appId:$appId, action:"allocate", builtBy:"ci", commitSha:$sha, branch:$branch,
commitMessage:$msg, author:$author, manifest:$manifest, checks:$checks}')"
alloc="$(ds_post record-app-version "$alloc_body")" || die "allocate failed"
commitMessage:$msg, author:$author, manifest:$manifest, checks:$checks,
buildId:(if $build == "" then null else $build end)}')"
alloc="$(ds_post record-app-version "$alloc_body")" || fail_build failed "allocate failed"
VERSION="$(jq -r '.version // empty' <<<"$alloc")"
PREFIX="$(jq -r '.r2Prefix // empty' <<<"$alloc")"
UPLOAD_TOKEN="$(jq -r '.uploadToken // empty' <<<"$alloc")"
[ -n "$VERSION" ] && [ -n "$PREFIX" ] || die "allocate returned no version/prefix: $alloc"
[ -n "$VERSION" ] && [ -n "$PREFIX" ] || fail_build failed "allocate returned no version/prefix: $alloc"
log "Allocated v$VERSION for $BRANCH@${COMMIT_SHA:0:7} -> $PREFIX"
mark_failed() {
@@ -38,7 +40,7 @@ mark_failed() {
# --- 2. upload --------------------------------------------------------------
if [ -n "${CUSTOM_APPS_WORKER_URL:-}" ]; then
[ -n "$UPLOAD_TOKEN" ] || { mark_failed "no upload token"; die "allocate returned no uploadToken but CUSTOM_APPS_WORKER_URL is set"; }
[ -n "$UPLOAD_TOKEN" ] || { mark_failed "no upload token"; fail_build failed "allocate returned no uploadToken but CUSTOM_APPS_WORKER_URL is set"; }
log "Uploading through the Worker"
export WORKER="${CUSTOM_APPS_WORKER_URL%/}" UPLOAD_TOKEN APP_ID VERSION
upload_one() { # relative path under dist/
@@ -50,7 +52,7 @@ if [ -n "${CUSTOM_APPS_WORKER_URL:-}" ]; then
}
export -f upload_one
if ! (cd dist && find . -type f | sed 's|^\./||') | xargs -P 6 -n 1 bash -c 'upload_one "$0"'; then
mark_failed "upload failed"; die "Upload failed; v$VERSION marked failed and was not promoted."
mark_failed "upload failed"; fail_build upload_failed "Upload failed; v$VERSION marked failed and was not promoted."
fi
else
require_env R2_ACCOUNT_ID R2_BUCKET R2_ACCESS_KEY_ID R2_SECRET_ACCESS_KEY
@@ -60,23 +62,27 @@ else
AWS_RESPONSE_CHECKSUM_VALIDATION=when_required \
aws s3 sync dist "s3://$R2_BUCKET/${PREFIX%/}" \
--endpoint-url "https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com" --delete; then
mark_failed "upload failed"; die "Upload failed; v$VERSION marked failed and was not promoted."
mark_failed "upload failed"; fail_build upload_failed "Upload failed; v$VERSION marked failed and was not promoted."
fi
fi
log "Uploaded $(find dist -type f | wc -l) files"
# --- 3. promote (DealSage applies the app's publish policy) ------------------
promote="$(ds_post record-app-version "$(jq -n --arg appId "$APP_ID" --argjson v "$VERSION" \
'{appId:$appId, action:"promote", version:$v}')")" || die "promote request failed"
'{appId:$appId, action:"promote", version:$v}')")" || fail_build failed "promote request failed"
promoted="$(jq -r '.promoted // false' <<<"$promote")"
channel="$(jq -r '.channel // empty' <<<"$promote")"
current="$(jq -r '.currentVersion // empty' <<<"$promote")"
if [ "$promoted" = true ]; then
log "v$VERSION is live"
outcome_note="v$VERSION is live"
log "$outcome_note"
else
live_note="nothing is live yet"; [ -n "$current" ] && live_note="live stays at v$current"
outcome_note="v$VERSION kept on ${channel:-branch/$BRANCH}; $live_note"
log "v$VERSION built and kept on channel '${channel:-branch/$BRANCH}' ($live_note); promote it from DealSage when ready"
fi
step_done publish passed "$outcome_note"
report_build_finish built "" "$VERSION" "$promoted"
{
echo "version=$VERSION"; echo "promoted=$promoted"; echo "channel=${channel}"
} >> "${GITHUB_OUTPUT:-/dev/null}"