Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Build Desktop release candidates alongside final validation (#647)

Deebecddeaca539
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index a47fc18dc..16bfefc84 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -1,4 +1,5 @@
name: Release desktop
+run-name: Desktop ${{ inputs.prepare_only && 'candidate' || inputs.test_candidate_reuse && 'promotion check' || inputs.test_publication && 'publication check' || 'release' }} ${{ inputs.version || github.ref_name }}
# Cut a release by pushing a tag: git tag -a v1.0.51_desktop -F notes.md && git push origin v1.0.51_desktop
# (or `make release-desktop` from the repo root, which does exactly that).
@@ -37,12 +38,14 @@ name: Release desktop
# manifest references them, but delete gs://<bucket>/harness/desktop/<dry-run-version>/ afterwards.
on:
+ schedule:
+ - cron: '13 4 * * *' # remove unused candidate packages after seven days
push:
tags: ['v*_desktop']
workflow_dispatch:
inputs:
version:
- description: 'Version to publish (X.Y.Z)'
+ description: 'Release or candidate version (X.Y.Z)'
required: true
metadata_path:
description: 'Manifest to write. Leave as-is for a real release; metadata-test.json for a dry run.'
@@ -52,15 +55,24 @@ on:
description: 'Only test publication against disposable fixture objects; no app build or product release'
type: boolean
default: false
+ prepare_only:
+ description: 'Build and verify a candidate during final validation; publish nothing to users'
+ type: boolean
+ default: false
+ test_candidate_reuse:
+ description: 'Promote a matching candidate to disposable paths, verify and delete it; no product release'
+ type: boolean
+ default: false
permissions:
contents: read
+ actions: read # authenticate the candidate run and its immutable receipt artifact
id-token: write # only used by the Workload Identity Federation variant of the auth steps below
concurrency:
# Different versions build concurrently. Only publish+verification takes the
# shared manifest lock below; a whole-workflow lock added 4m35s to 1.2.47.
- group: desktop-release-${{ github.ref }}-${{ inputs.version }}
+ group: desktop-release-${{ github.ref }}-${{ inputs.version }}-${{ inputs.prepare_only }}-${{ inputs.test_candidate_reuse }}
cancel-in-progress: false
env:
@@ -81,12 +93,16 @@ jobs:
# Resolve and validate before anything expensive starts. A malformed tag fails here in seconds
# rather than 25 minutes into a notarized build.
version:
- if: ${{ !inputs.test_publication }}
+ if: ${{ github.event_name != 'schedule' && !inputs.test_publication }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.resolve.outputs.version }}
metadata_path: ${{ steps.resolve.outputs.metadata_path }}
scratch_prefix: ${{ steps.resolve.outputs.scratch_prefix }}
+ artifact_prefix: ${{ steps.resolve.outputs.artifact_prefix }}
+ artifact_base_url: ${{ steps.resolve.outputs.artifact_base_url }}
+ candidate_prefix: ${{ steps.resolve.outputs.candidate_prefix }}
+ test_prefix: ${{ steps.resolve.outputs.test_prefix }}
steps:
- id: resolve
# Through env, never `${{ }}` inline in run:. Git permits quotes, backticks and $() in a
@@ -95,7 +111,14 @@ jobs:
REF_NAME: ${{ github.ref_name }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_METADATA_PATH: ${{ inputs.metadata_path }}
+ PREPARE_ONLY: ${{ inputs.prepare_only }}
+ TEST_REUSE: ${{ inputs.test_candidate_reuse }}
run: |
+ set -euo pipefail
+ if [[ "$PREPARE_ONLY" = true && "$TEST_REUSE" = true ]]; then
+ echo '::error::prepare_only and test_candidate_reuse are separate runs'
+ exit 1
+ fi
# A tag push names the ref "vX.Y.Z_desktop"; workflow_dispatch's input.version is already
# bare. Strip both so $ver is always X.Y.Z — the suffix routes the tag to this workflow
# and is never part of the published version.
@@ -106,15 +129,37 @@ jobs:
exit 1
fi
meta="${INPUT_METADATA_PATH:-harness/desktop/metadata.json}"
+ artifact_prefix="harness/desktop/$ver"
+ artifact_base_url=https://cdn.autonomous.ai
+ candidate_prefix=""
+ test_prefix=""
+ if [[ "$PREPARE_ONLY" = true ]]; then
+ candidate_prefix="harness/desktop-candidates/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-$(openssl rand -hex 16)"
+ artifact_prefix="$candidate_prefix"
+ artifact_base_url="https://storage.googleapis.com/$GCS_BUCKET"
+ elif [[ "$TEST_REUSE" = true ]]; then
+ test_prefix="harness/desktop/.candidate-check/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
+ meta="$test_prefix/metadata.json"
+ artifact_prefix="$test_prefix/artifacts"
+ artifact_base_url="https://storage.googleapis.com/$GCS_BUCKET"
+ fi
echo "version=$ver" >> "$GITHUB_OUTPUT"
echo "metadata_path=$meta" >> "$GITHUB_OUTPUT"
- echo "scratch_prefix=harness/desktop/.ci/${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT"
- echo "Publishing **$ver** to \`$meta\`" >> "$GITHUB_STEP_SUMMARY"
+ echo "scratch_prefix=harness/desktop/.ci/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" >> "$GITHUB_OUTPUT"
+ echo "artifact_prefix=$artifact_prefix" >> "$GITHUB_OUTPUT"
+ echo "artifact_base_url=$artifact_base_url" >> "$GITHUB_OUTPUT"
+ echo "candidate_prefix=$candidate_prefix" >> "$GITHUB_OUTPUT"
+ echo "test_prefix=$test_prefix" >> "$GITHUB_OUTPUT"
+ echo "Desktop **$ver** · candidate=$PREPARE_ONLY · disposable promotion=$TEST_REUSE" >> "$GITHUB_STEP_SUMMARY"
# Reject duplicate/older versions and broken credentials before expensive builds.
preflight:
needs: version
runs-on: ubuntu-latest
+ timeout-minutes: 24 # follows an existing candidate for at most its 20-minute budget
+ outputs:
+ reused: ${{ steps.candidate.outputs.reused }}
+ candidate_prefix: ${{ steps.candidate.outputs.candidate_prefix }}
steps:
- uses: actions/checkout@v7
with:
@@ -122,6 +167,8 @@ jobs:
/.github/actions/setup-gcloud/
/scripts/publish-desktop-manifest.py
/scripts/verify-desktop-release.py
+ /scripts/desktop-release-candidate.py
+ /scripts/record-ci-validation.py
sparse-checkout-cone-mode: false
# GCP auth, WITHOUT a long-lived key — the same pattern release.yml and production-be-build.yaml
# already run. A service-account JSON key is a bearer credential with no expiry: it is only as
@@ -162,14 +209,37 @@ jobs:
echo "$GITHUB_RUN_ID" | gcloud storage cp - "$probe"
gcloud storage rm "$probe"
+ - name: Reuse a matching verified candidate, or build normally
+ id: candidate
+ if: ${{ !inputs.prepare_only }}
+ env:
+ GH_TOKEN: ${{ github.token }}
+ VERSION: ${{ needs.version.outputs.version }}
+ DESTINATION: ${{ needs.version.outputs.artifact_prefix }}
+ SCRATCH_PREFIX: ${{ needs.version.outputs.scratch_prefix }}
+ TEST_REUSE: ${{ inputs.test_candidate_reuse }}
+ run: |
+ args=()
+ [[ "$TEST_REUSE" != true ]] || args+=(--require-candidate)
+ python3 scripts/desktop-release-candidate.py reuse --version "$VERSION" \
+ --destination "$DESTINATION" --scratch "$SCRATCH_PREFIX" "${args[@]}"
+ - uses: actions/upload-artifact@v4
+ if: ${{ hashFiles('desktop-candidate-reuse.json') != '' }}
+ with:
+ name: desktop-candidate-reuse
+ path: desktop-candidate-reuse.json
+
# Compile the universal app once, then derive the two renderer bundles. Both
# retain arm64+x86_64; their packaging/notarization/uploads run in parallel.
build-macos:
needs: [version, preflight]
+ if: needs.preflight.outputs.reused != 'true'
runs-on: macos-15
timeout-minutes: 60 # two notarization submissions per build (zip, then dmg) — see RELEASE.md
env:
MACOS_METADATA_PREFIX: ${{ needs.version.outputs.scratch_prefix }}
+ ARTIFACT_PREFIX: ${{ needs.version.outputs.artifact_prefix }}
+ CDN_ASSET_BASE_URL: ${{ needs.version.outputs.artifact_base_url }}
defaults:
run:
working-directory: desktop
@@ -212,7 +282,7 @@ jobs:
set -euo pipefail
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
python3 scripts/build-macos-variants.py "$VERSION" \
- --metadata-prefix "$MACOS_METADATA_PREFIX"
+ --metadata-prefix "$MACOS_METADATA_PREFIX" --artifact-prefix "$ARTIFACT_PREFIX"
- uses: actions/upload-artifact@v4
if: always()
@@ -228,6 +298,7 @@ jobs:
build-linux:
needs: [version, preflight]
+ if: needs.preflight.outputs.reused != 'true'
runs-on: ${{ matrix.runner }}
timeout-minutes: 45
strategy:
@@ -244,6 +315,8 @@ jobs:
env:
TARGET_ARCH: ${{ matrix.arch }}
METADATA_PATH: ${{ needs.version.outputs.scratch_prefix }}/linux-${{ matrix.arch }}.json
+ GCS_PATH: ${{ needs.version.outputs.artifact_prefix }}/Harness-linux-${{ matrix.arch }}.AppImage
+ CDN_ASSET_BASE_URL: ${{ needs.version.outputs.artifact_base_url }}
defaults:
run:
working-directory: desktop
@@ -297,7 +370,8 @@ jobs:
# The only job that touches the REAL manifest, and the only one that can, because it is the only
# one that runs after every build has finished.
publish:
- needs: [version, build-macos, build-linux]
+ needs: [version, preflight, build-macos, build-linux]
+ if: ${{ always() && !inputs.prepare_only && needs.version.result == 'success' && needs.preflight.result == 'success' && (needs.preflight.outputs.reused == 'true' || (needs.build-macos.result == 'success' && needs.build-linux.result == 'success')) }}
runs-on: ubuntu-latest
timeout-minutes: 8
concurrency:
@@ -364,7 +438,9 @@ jobs:
# disagree with the one the app actually installs. The notes link to the real ones instead.
github-release:
needs: [version, publish]
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
+ # success() also inspects skipped ancestors: an explicitly successful
+ # publisher must reach this job even when candidate reuse skipped builds.
+ if: ${{ always() && needs.version.result == 'success' && needs.publish.result == 'success' && ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || inputs.test_candidate_reuse) }}
runs-on: ubuntu-latest
permissions:
contents: write # narrower than the workflow default only here, where a release is created
@@ -374,6 +450,7 @@ jobs:
fetch-depth: 1
- name: Take the release notes from the tag
+ if: github.event_name == 'push'
env:
REF_NAME: ${{ github.ref_name }}
VERSION: ${{ needs.version.outputs.version }}
@@ -431,7 +508,12 @@ jobs:
EOF
echo "::group::RELEASE_NOTES.md"; cat RELEASE_NOTES.md; echo "::endgroup::"
+ - name: Confirm promotion reaches the release-page stage
+ if: inputs.test_candidate_reuse
+ run: echo 'Promoted packages passed public verification; product Release creation is disabled for this disposable check.'
+
- uses: softprops/action-gh-release@v2
+ if: github.event_name == 'push'
with:
# Three products release from this repo; a raw "v1.2.3_desktop" title reads worse than this.
name: Harness Desktop ${{ needs.version.outputs.version }}
@@ -441,13 +523,18 @@ jobs:
# precisely when scratch manifests are left behind — the builds that DID succeed have already
# written theirs. `if: always()` here means the prefix is cleared whatever happened upstream.
cleanup:
- needs: [version, build-macos, build-linux, publish]
+ needs: [version, preflight, build-macos, build-linux, candidate, publish]
if: ${{ always() && needs.version.result == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
- sparse-checkout: /.github/actions/setup-gcloud/
+ sparse-checkout: |
+ /.github/actions/setup-gcloud/
+ /scripts/desktop-release-candidate.py
+ /scripts/record-ci-validation.py
+ /scripts/publish-desktop-manifest.py
+ /scripts/verify-desktop-release.py
sparse-checkout-cone-mode: false
- name: Authenticate to GCP (workload identity federation)
uses: google-github-actions/auth@v2
@@ -459,6 +546,85 @@ jobs:
env:
SCRATCH_PREFIX: ${{ needs.version.outputs.scratch_prefix }}
run: gcloud storage rm -r "gs://${GCS_BUCKET}/${SCRATCH_PREFIX}" || true
+ - name: Remove failed or consumed candidate packages and disposable promotion objects
+ env:
+ OWN_CANDIDATE: ${{ needs.version.outputs.candidate_prefix }}
+ REUSED_CANDIDATE: ${{ needs.preflight.outputs.candidate_prefix }}
+ CANDIDATE_RESULT: ${{ needs.candidate.result }}
+ PUBLISH_RESULT: ${{ needs.publish.result }}
+ TEST_PREFIX: ${{ needs.version.outputs.test_prefix }}
+ run: |
+ set -euo pipefail
+ if [[ -n "$OWN_CANDIDATE" && "$CANDIDATE_RESULT" != success ]]; then
+ python3 scripts/desktop-release-candidate.py remove --prefix "$OWN_CANDIDATE" || true
+ fi
+ if [[ -n "$REUSED_CANDIDATE" && "$PUBLISH_RESULT" = success ]]; then
+ python3 scripts/desktop-release-candidate.py remove --prefix "$REUSED_CANDIDATE"
+ fi
+ if [[ -n "$TEST_PREFIX" ]]; then
+ [[ "$TEST_PREFIX" = "harness/desktop/.candidate-check/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" ]]
+ gcloud storage rm --recursive "gs://${GCS_BUCKET}/${TEST_PREFIX}/"
+ fi
+
+ # Same build/signing path and production updater settings. Only the storage
+ # destination differs. A successful receipt binds six verified generations to
+ # this complete source tree, version, workflow run and attempt.
+ candidate:
+ needs: [version, build-macos, build-linux]
+ if: ${{ inputs.prepare_only }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 8
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ sparse-checkout: |
+ /.github/actions/setup-gcloud/
+ /scripts/desktop-release-candidate.py
+ /scripts/record-ci-validation.py
+ /scripts/publish-desktop-manifest.py
+ /scripts/verify-desktop-release.py
+ sparse-checkout-cone-mode: false
+ - uses: google-github-actions/auth@v2
+ with:
+ workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
+ service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
+ - uses: ./.github/actions/setup-gcloud
+ - name: Verify all six candidate downloads and seal their source identity
+ env:
+ VERSION: ${{ needs.version.outputs.version }}
+ PREFIX: ${{ needs.version.outputs.candidate_prefix }}
+ SCRATCH_PREFIX: ${{ needs.version.outputs.scratch_prefix }}
+ run: |
+ mkdir -p parts
+ gcloud storage cp "gs://${GCS_BUCKET}/${SCRATCH_PREFIX}/*.json" parts/
+ python3 scripts/desktop-release-candidate.py seal --version "$VERSION" --prefix "$PREFIX" --parts parts
+ - uses: actions/upload-artifact@v4
+ with:
+ name: desktop-release-candidate-${{ github.run_attempt }}
+ path: desktop-release-candidate.json
+ if-no-files-found: error
+ retention-days: 7
+
+ expire-candidates:
+ if: github.event_name == 'schedule'
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ sparse-checkout: |
+ /.github/actions/setup-gcloud/
+ /scripts/desktop-release-candidate.py
+ /scripts/record-ci-validation.py
+ /scripts/publish-desktop-manifest.py
+ /scripts/verify-desktop-release.py
+ sparse-checkout-cone-mode: false
+ - uses: google-github-actions/auth@v2
+ with:
+ workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
+ service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
+ - uses: ./.github/actions/setup-gcloud
+ - run: python3 scripts/desktop-release-candidate.py expire
# This mode exercises actual GCS generation preconditions using tiny fixture
# artifacts under its own run prefix. All product build/publish jobs are skipped.
@@ -474,6 +640,9 @@ jobs:
/scripts/publish-desktop-manifest.py
/scripts/verify-desktop-release.py
/scripts/check-desktop-publication-gcs.py
+ /scripts/check-desktop-candidate-gcs.py
+ /scripts/desktop-release-candidate.py
+ /scripts/record-ci-validation.py
/scripts/tests/desktop_publication_fixture.py
/desktop/scripts/upload-desktop.sh
/desktop/scripts/upload-desktop-linux.sh
@@ -485,3 +654,5 @@ jobs:
- uses: ./.github/actions/setup-gcloud
- name: Exercise publication against a disposable GCS prefix
run: python3 scripts/check-desktop-publication-gcs.py "$GCS_BUCKET"
+ - name: Exercise candidate sealing, promotion and expiration against disposable objects
+ run: python3 scripts/check-desktop-candidate-gcs.py
diff --git a/AGENTS.md b/AGENTS.md
index 870ba5237..15b18e356 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -26,3 +26,8 @@ validation and shipping, use [docs/validation-and-release.md](docs/validation-an
`scripts/record-ci-validation.py RUN_ID --scope SCOPE --pr PR_NUMBER`; retain routine
results in its ignored receipt and the PR body instead of another documentation
commit. Resolve any source differences explicitly before reusing that evidence.
+- For an authorized Desktop release, start `make release-desktop ARGS="--prepare"`
+ from the final pushed PR branch alongside validation and review. It prepares
+ verified packages without publishing; merge and release only after checks pass.
+ Avoid starting candidates while implementation is still changing. The release
+ automatically reuses a matching source tree/version and otherwise builds normally.
diff --git a/Makefile b/Makefile
index 51e7f9c92..f6aea2cae 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,7 @@ release-backend:
## release-desktop: tag this commit vX.Y.Z_desktop and push the tag — CI builds both macOS builds
## and both Linux architectures, publishes to GCS, and cuts the GitHub Release. The version is bumped
## from max(last git tag, live harness/desktop/metadata.json). ARGS="--dry-run" to preview,
+## ARGS="--prepare" to package a pushed PR head during final checks, without publishing,
## ARGS="--minor" for a forced-update minor bump, ARGS="X.Y.Z" for an explicit version. The by-hand
## escape hatches (upload-desktop, upload-desktop-linux, upload-node-runtime, upload-tmux-runtime) live in desktop/Makefile.
release-desktop:
diff --git a/desktop/RELEASE.md b/desktop/RELEASE.md
index 949892832..b85d4f858 100644
--- a/desktop/RELEASE.md
+++ b/desktop/RELEASE.md
@@ -17,10 +17,22 @@ make release-desktop ARGS="--dry-run" # print the version it would cut and
make release-desktop ARGS="--minor" # bump the MINOR version, per the usual semver convention
make release-desktop ARGS="1.3.0" # release an explicit version
make release-desktop ARGS="--notes-file notes.md" # hand-written release notes
+make release-desktop ARGS="--prepare" # package the final pushed PR head during tests/review; publish nothing
+make release-desktop ARGS="--wait" # release, then follow this exact tag through public verification
```
-Nothing is built locally and no GCS credentials are needed: the only things the script touches are
-git and a public HTTPS read of the manifest.
+Nothing is built locally and no GCS credentials are needed. The script uses Git and a public
+HTTPS read of the manifest; `--prepare` and `--wait` also need the authenticated `gh` CLI.
+
+For an authorized release, run `--prepare` once the final implementation is pushed to its PR
+branch, while the required tests and review run. It selects the next version by the same rules
+as a release, builds/signs/notarizes all platforms in CI, and verifies all six downloads at an
+isolated candidate path. It creates neither a release tag nor a product manifest/Release page.
+After checks pass, merge and release that same version normally. CI reuses the candidate only
+when the complete source tree and version match; a clean squash is supported. Changed code,
+build inputs or version require a new build. Candidate packaging does not replace application
+tests or authorize publication. See the [validation guide](../docs/validation-and-release.md#package-desktop-while-final-checks-run)
+for identity checks, bounded waiting, expiration and disposable promotion validation.
**Why the version comes from two places.** `scripts/release-desktop.sh` takes the highest of the last
git tag and the highest version in the live `metadata.json`, across every `desktop-*` key. Publishing
diff --git a/desktop/scripts/release-desktop.sh b/desktop/scripts/release-desktop.sh
index a7d108367..69a4575c2 100755
--- a/desktop/scripts/release-desktop.sh
+++ b/desktop/scripts/release-desktop.sh
@@ -15,6 +15,7 @@
# bash scripts/release-desktop.sh --notes-file f.md # hand-written release notes instead of the
# # generated commit list
# bash scripts/release-desktop.sh --wait # finish when this tag is live and verified
+# bash scripts/release-desktop.sh --prepare # package the pushed PR head during final checks; no publication
#
# THE NEXT VERSION COMES FROM TWO SOURCES, AND BOTH MATTER. Git tags alone are not enough: this repo
# had one tag (v1.0.52) while the live manifest was already serving 1.0.61, because
@@ -36,10 +37,11 @@ GCS_BUCKET="${GCS_BUCKET:-s3-autonomous-upgrade-3}"
GCS_PUBLIC_BASE_URL="${GCS_PUBLIC_BASE_URL:-https://storage.googleapis.com/${GCS_BUCKET}}"
METADATA_PATH="${METADATA_PATH:-harness/desktop/metadata.json}"
META_URL="${META_URL:-${GCS_PUBLIC_BASE_URL%/}/${METADATA_PATH#/}}"
-BRANCH="${BRANCH:-main}"
+BRANCH="${BRANCH:-}"
DRY_RUN=0
WAIT=0
+PREPARE=0
DO_MINOR=0
ALLOW_NO_MANIFEST=0
NEW_VER=""
@@ -51,6 +53,7 @@ for arg in "$@"; do
case "$arg" in
--dry-run) DRY_RUN=1 ;;
--wait) WAIT=1 ;;
+ --prepare) PREPARE=1 ;;
--minor) DO_MINOR=1 ;;
--allow-no-manifest) ALLOW_NO_MANIFEST=1 ;;
--notes-file) want_notes_file=1 ;;
@@ -60,8 +63,15 @@ for arg in "$@"; do
*) NEW_VER="$arg" ;;
esac
done
-if [ "$WAIT" -eq 1 ]; then
- command -v gh >/dev/null 2>&1 || { echo 'ERROR --wait requires gh' >&2; exit 1; }
+if [ "$PREPARE" -eq 1 ]; then
+ [ "$WAIT" -eq 0 ] || { echo 'ERROR --prepare starts a candidate; use --wait when releasing after merge' >&2; exit 1; }
+ BRANCH="${BRANCH:-$(git branch --show-current)}"
+ [ -n "$BRANCH" ] || { echo 'ERROR --prepare needs a pushed branch' >&2; exit 1; }
+else
+ BRANCH="${BRANCH:-main}"
+fi
+if [ "$WAIT" -eq 1 ] || { [ "$PREPARE" -eq 1 ] && [ "$DRY_RUN" -eq 0 ]; }; then
+ command -v gh >/dev/null 2>&1 || { echo 'ERROR --wait and --prepare require gh' >&2; exit 1; }
fi
[ "$want_notes_file" -eq 0 ] || { echo "ERROR --notes-file needs a path" >&2; exit 1; }
@@ -120,6 +130,10 @@ if ! git merge-base --is-ancestor "$HEAD_SHA" "origin/$BRANCH" 2>/dev/null; then
echo "ERROR HEAD is not on origin/$BRANCH — push the commit first, or CI will build a commit nobody else has." >&2
exit 1
fi
+if [ "$PREPARE" -eq 1 ] && [ "$HEAD_SHA" != "$(git rev-parse "origin/$BRANCH")" ]; then
+ echo 'ERROR --prepare must run at the pushed branch tip so CI packages exactly this source' >&2
+ exit 1
+fi
# --- current version, source 1: the highest release tag in git ---
# The brace group keeps `set -e` from killing the script when grep legitimately matches nothing.
@@ -251,6 +265,13 @@ if [ "$DRY_RUN" -eq 1 ]; then
exit 0
fi
+if [ "$PREPARE" -eq 1 ]; then
+ gh workflow run release-desktop.yml --ref "$BRANCH" -f version="$VER" -f prepare_only=true
+ echo " Candidate $VER started on $HEAD_SHA. No tag or product manifest was published."
+ echo " Continue validation/review, merge, then release $VER normally; matching packages are reused automatically."
+ exit 0
+fi
+
# --- tag and push ---
git tag -a "$TAG" --cleanup=verbatim -F "$NOTES"
git push origin "$TAG"
diff --git a/docs/validation-and-release.md b/docs/validation-and-release.md
index 25f9732ce..9f315ebdd 100644
--- a/docs/validation-and-release.md
+++ b/docs/validation-and-release.md
@@ -68,6 +68,48 @@ their own key, with the full SDK for the exact same version as a fallback. Cache
preparation covers macOS and both Linux architectures. Signing, notarization and
artifact checks remain required.
+### Package Desktop while final checks run
+
+When the final implementation is pushed, start `make release-desktop ARGS="--prepare"`
+on that PR branch alongside its required tests and review. This chooses the next
+version using the same tags/live-manifest rules as a release, then dispatches a
+candidate build. Use an explicit version with `--prepare` when preparing a minor
+bump. The candidate uses the release's normal macOS and Linux build, signing and
+notarization steps and production updater settings. It writes only to a random
+candidate prefix, verifies all six downloads, and retains a small receipt in
+GitHub Actions. It neither tags nor updates the product manifest or Release page.
+
+After validation and review pass, merge and release that version normally. The
+workflow automatically looks for a candidate with the same version and complete
+Git source tree. A clean squash preserves that tree; any source, dependency,
+toolchain-pin or workflow change requires another build. The workflow checks the
+producer run's successful completion, repository, workflow, source, attempt and
+immutable receipt digest. Promotion copies only the exact object generations
+whose sizes and SHA-256 hashes were verified, with atomic no-overwrite conditions.
+The normal version check, serialized manifest publication and six public-download
+checks still apply. Candidate packaging never substitutes for application tests
+or authorizes a merge or release.
+
+A matching in-progress candidate may finish while release preflight waits, bounded
+by twenty minutes from the candidate's creation. An absent, failed, expired or changed
+candidate falls back to the normal build. If a matching candidate is still live at
+that deadline, preflight stops with its run link; follow that same build, then rerun
+the existing release workflow (all jobs, so per-attempt paths are refreshed) after
+it passes. A deadline or failed status poll does not start another
+copy of a known live build.
+Once any promotion copy starts, failure
+stops the release rather than rebuilding over partially copied immutable objects.
+Do not launch repeated candidates while implementation is still changing. A new
+version published in the meantime also invalidates the planned version; prepare
+the newly selected version instead.
+
+Unused candidates expire after seven days; a daily job deletes only recognized
+old candidate objects at their listed generations. Failed candidates and consumed
+candidates are removed by their owning workflow. For process maintenance, dispatch
+`test_candidate_reuse=true` for the same branch/version after its candidate passes:
+it requires reuse, promotes to disposable paths, verifies all six downloads, then
+removes those objects and the consumed candidate. It cannot publish a product.
+
Native TUI CI tests and builds the shipped musl target in the same Cargo output
directory. Dependency caches are keyed by target, Rust toolchain, and Cargo inputs;
cache hits still run every test. The ten native TUI fixtures run two at a time,
diff --git a/scripts/check-desktop-candidate-gcs.py b/scripts/check-desktop-candidate-gcs.py
new file mode 100644
index 000000000..1d13e55e9
--- /dev/null
+++ b/scripts/check-desktop-candidate-gcs.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python3
+"""Exercise candidate sealing/promotion using six tiny run-owned GCS objects."""
+from datetime import datetime, timedelta, timezone
+import hashlib
+import importlib.util
+import json
+import os
+from pathlib import Path
+import secrets
+import tempfile
+
+spec = importlib.util.spec_from_file_location('candidate', Path(__file__).with_name('desktop-release-candidate.py'))
+candidate = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(candidate)
+
+
+def main():
+ identity = candidate.context()
+ bucket = os.environ['GCS_BUCKET']
+ candidate.check_bucket(bucket)
+ run = f'{identity["run_id"]}-{identity["run_attempt"]}'
+ prefix = f'harness/desktop-candidates/{run}-{secrets.token_hex(16)}'
+ destination = f'harness/desktop/.candidate-check/{run}/artifacts'
+ scratch = f'harness/desktop/.ci/{run}'
+ version = '0.0.1'
+ uri = f'gs://{bucket}/harness/desktop/.candidate-check/{run}/metadata.json'
+ gcloud = candidate.publisher.gcloud
+ try:
+ with tempfile.TemporaryDirectory(prefix='candidate-gcs-check-') as folder:
+ root = Path(folder)
+ entries = {}
+ for key, filename in candidate.FILES.items():
+ data = f'Candidate fixture {key}\n'.encode()
+ file = root / filename
+ file.write_bytes(data)
+ entries[key] = dict(version=version, size=len(data), sha256=hashlib.sha256(data).hexdigest(),
+ url=f'https://storage.googleapis.com/{bucket}/{prefix}/{filename}')
+ gcloud('storage', 'cp', *[str(root / file) for file in candidate.FILES.values()],
+ f'gs://{bucket}/{prefix}/', '--if-generation-match=0')
+ for name, keys in candidate.publisher.PARTS.items():
+ (root / name).write_text(json.dumps({key: entries[key] for key in keys}))
+ receipt = candidate.seal(version, bucket, prefix, root, identity)
+ candidate.check_sources(receipt)
+ candidate.promote(receipt, destination, scratch)
+ print('PASS: seal six source generations and promote their exact bytes', flush=True)
+ promoted = root / 'promoted'
+ promoted.mkdir()
+ gcloud('storage', 'cp', f'gs://{bucket}/{scratch}/*.json', str(promoted) + '/')
+ candidate.publisher.publish(uri, version, promoted, allow_initialize=True)
+ checked = candidate.verification.verify(version, uri.replace('gs://', 'https://storage.googleapis.com/'))
+ assert checked['status'] == 'passed', checked
+ print('PASS: publish and verify all six promoted fixture downloads', flush=True)
+ destination_uris = [f'gs://{bucket}/{destination}/{filename}' for filename in candidate.FILES.values()]
+ before = [candidate.describe(path)['generation'] for path in destination_uris]
+ try:
+ candidate.promote(receipt, destination, scratch)
+ except RuntimeError as error:
+ assert '412' in str(error) or 'GcsPreconditionFailedError' in str(error), error
+ else:
+ raise AssertionError('promotion overwrote an immutable destination')
+ assert [candidate.describe(path)['generation'] for path in destination_uris] == before
+ print('PASS: a second promotion fails the atomic destination precondition', flush=True)
+
+ # Verify the actual SDK listing schema and generation-qualified delete
+ # command, restricted to this run's disposable objects.
+ listed = json.loads(gcloud('storage', 'objects', 'list', f'gs://{bucket}/{prefix}/**', '--raw', '--format=json'))
+ now = datetime.now(timezone.utc)
+ assert candidate.expired_objects(listed, now) == [], listed
+ expired = candidate.expired_objects(listed, now + timedelta(days=8))
+ assert len(expired) == 6 and all(item.startswith(prefix + '/') for item in expired), listed
+ gcloud('storage', 'rm', f'gs://{bucket}/{expired[0]}')
+ print('PASS: recent objects retained; expiry recognizes all six and deletes the selected generation', flush=True)
+ finally:
+ # No configurable product paths: all three prefixes are constructed from
+ # this workflow's own run/attempt and random token above.
+ errors = []
+ for owned in (prefix, scratch, f'harness/desktop/.candidate-check/{run}'):
+ try:
+ gcloud('storage', 'rm', '--recursive', f'gs://{bucket}/{owned}/')
+ except RuntimeError as error:
+ # A failure before upload may leave a prefix empty. Continue
+ # through every owned prefix even when one removal fails.
+ if '404' not in str(error) and 'matched no objects' not in str(error):
+ errors.append(str(error))
+ if errors:
+ raise RuntimeError('fixture cleanup failed: ' + '; '.join(errors))
+ return 0
+
+
+if __name__ == '__main__':
+ raise SystemExit(main())
diff --git a/scripts/desktop-release-candidate.py b/scripts/desktop-release-candidate.py
new file mode 100644
index 000000000..478b0e14a
--- /dev/null
+++ b/scripts/desktop-release-candidate.py
@@ -0,0 +1,362 @@
+#!/usr/bin/env python3
+"""Seal, find and promote verified Desktop packages without rebuilding them.
+
+A candidate is evidence about bytes, never permission to merge or publish. The
+release still requires the normal validation, version and publication gates.
+"""
+import argparse
+from concurrent.futures import ThreadPoolExecutor
+from datetime import datetime, timedelta, timezone
+import hashlib
+import importlib.util
+import io
+import json
+import os
+from pathlib import Path
+import re
+import subprocess
+import sys
+import tempfile
+import time
+import zipfile
+
+
+def sibling(name):
+ spec = importlib.util.spec_from_file_location(name.replace('-', '_'), Path(__file__).with_name(name + '.py'))
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+publisher = sibling('publish-desktop-manifest')
+Client = sibling('record-ci-validation').Client
+verification = publisher.verification
+WORKFLOW = '.github/workflows/release-desktop.yml'
+FILES = dict(zip(verification.KEYS, (
+ 'Harness-macos.zip', 'Harness-macos.dmg', 'Harness-macos-arm64.zip',
+ 'Harness-macos-arm64.dmg', 'Harness-linux-x64.AppImage', 'Harness-linux-arm64.AppImage',
+)))
+PREFIX = r'harness/desktop-candidates/([1-9][0-9]*)-([1-9][0-9]*)-[0-9a-f]{32}'
+RETENTION = timedelta(days=7)
+MAX_AGE_SECONDS = 1200
+
+
+class CandidatePendingError(RuntimeError):
+ """The observed build is still live; a deadline is not a failed build."""
+
+
+def require(condition, message):
+ if not condition:
+ raise ValueError(message)
+
+
+def timestamp(value):
+ parsed = datetime.fromisoformat(value.replace('Z', '+00:00'))
+ require(parsed.tzinfo is not None, 'timestamp must include its timezone')
+ return parsed
+
+
+def git(value):
+ return subprocess.check_output(['git', 'rev-parse', value], text=True, timeout=10).strip()
+
+
+def context():
+ repository = os.environ['GITHUB_REPOSITORY']
+ run, attempt = (int(os.environ[key]) for key in ('GITHUB_RUN_ID', 'GITHUB_RUN_ATTEMPT'))
+ require(re.fullmatch(r'[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+', repository), 'invalid repository')
+ require(run > 0 and attempt > 0, 'invalid run identity')
+ sha = git('HEAD')
+ require(sha == os.environ['GITHUB_SHA'], 'checkout differs from workflow source')
+ return dict(repository=repository, run_id=run, run_attempt=attempt, source_sha=sha, source_tree=git('HEAD^{tree}'))
+
+
+def check_prefix(prefix, run=None, attempt=None):
+ match = re.fullmatch(PREFIX, prefix)
+ require(match is not None, 'invalid candidate object prefix')
+ if run is not None:
+ require((int(match[1]), int(match[2])) == (run, attempt), 'candidate prefix belongs to another run/attempt')
+ return prefix
+
+
+def check_bucket(bucket):
+ require(re.fullmatch(r'[a-z0-9][a-z0-9._-]+', bucket), 'invalid bucket')
+
+
+def describe(uri):
+ return json.loads(publisher.gcloud('storage', 'objects', 'describe', uri, '--format=json'))
+
+
+def seal(version, bucket, prefix, parts, identity):
+ """Verify immutable source generations and retain their hashes in GitHub."""
+ check_bucket(bucket)
+ check_prefix(prefix, identity['run_id'], identity['run_attempt'])
+ entries = publisher.read_parts(parts, version)
+ sources = {}
+ for key, entry in entries.items():
+ name = f'{prefix}/{FILES[key]}'
+ require(entry['url'] == f'https://storage.googleapis.com/{bucket}/{name}', 'candidate URL differs from its owned object')
+ sources[key] = f'gs://{bucket}/{name}'
+ # Candidate downloads must remain removable; promotion restores immutable
+ # release headers on the destination objects only.
+ publisher.gcloud('storage', 'objects', 'update', *sources.values(), '--cache-control=private, max-age=0, no-store')
+ pinned = {}
+ with ThreadPoolExecutor(max_workers=3) as pool:
+ descriptions = dict(zip(sources, pool.map(describe, sources.values())))
+ for key, entry in entries.items():
+ metadata = descriptions[key]
+ generation = str(metadata.get('generation', ''))
+ require(re.fullmatch(r'[1-9][0-9]*', generation), 'missing source generation')
+ require(int(metadata.get('size', -1)) == entry['size'], 'source size differs from the build manifest')
+ pinned[key] = dict(entry, generation=generation, url=entry['url'] + '?generation=' + generation)
+ with ThreadPoolExecutor(max_workers=3) as pool:
+ results = list(pool.map(lambda item: verification.verify_artifact(item, 90), pinned.items()))
+ require(all(item['status'] == 'passed' for item in results), 'candidate downloads failed verification')
+ return dict(schema=1, status='passed', version=version, bucket=bucket, prefix=prefix,
+ created_at=verification.utc_now(), **identity, artifacts=pinned)
+
+
+def check_run(run, repository, version):
+ require(run.get('repository', {}).get('full_name', '').lower() == repository.lower(), 'candidate repository mismatch')
+ require(run.get('path') == WORKFLOW and run.get('event') == 'workflow_dispatch', 'candidate workflow mismatch')
+ require(run.get('display_title') == f'Desktop candidate {version}', 'candidate mode/version mismatch')
+ require(re.fullmatch(r'[0-9a-f]{40}', run.get('head_sha', '')), 'candidate has no source commit')
+ require(type(run.get('id')) is int and run['id'] > 0 and type(run.get('run_attempt')) is int and run['run_attempt'] > 0,
+ 'candidate has no run/attempt identity')
+
+
+def read_receipt(artifact, archive, run, repository, version, tree, bucket, now):
+ name = f'desktop-release-candidate-{run["run_attempt"]}'
+ provenance = artifact.get('workflow_run', {})
+ require(artifact.get('name') == name and artifact.get('expired') is False
+ and provenance.get('id') == run['id'] and provenance.get('head_sha') == run['head_sha'],
+ 'candidate artifact identity mismatch')
+ require(artifact.get('digest') == 'sha256:' + hashlib.sha256(archive).hexdigest(), 'candidate archive digest mismatch')
+ require(len(archive) <= 65536, 'candidate archive is too large')
+ with zipfile.ZipFile(io.BytesIO(archive)) as bundle:
+ require(bundle.namelist() == ['desktop-release-candidate.json']
+ and bundle.infolist()[0].file_size <= 65536, 'unexpected candidate archive contents')
+ receipt = json.loads(bundle.read('desktop-release-candidate.json'))
+ require(isinstance(receipt, dict) and receipt.get('schema') == 1 and receipt.get('status') == 'passed', 'candidate did not pass')
+ expected = dict(repository=repository, run_id=run['id'], run_attempt=run['run_attempt'],
+ source_sha=run['head_sha'], source_tree=tree, version=version, bucket=bucket)
+ require(all(receipt.get(key) == value for key, value in expected.items()), 'candidate source/version/run differs from release')
+ created = timestamp(receipt['created_at'])
+ require(timestamp(run['created_at']) <= created <= now and now - created < RETENTION, 'candidate is expired or has invalid timestamps')
+ prefix = check_prefix(receipt['prefix'], run['id'], run['run_attempt'])
+ entries = receipt['artifacts']
+ require(isinstance(entries, dict) and set(entries) == set(FILES), 'candidate does not contain exactly six artifacts')
+ verification.entries_for_version(entries, version)
+ for key, entry in entries.items():
+ generation = entry.get('generation', '')
+ require(isinstance(generation, str) and re.fullmatch(r'[1-9][0-9]*', generation), 'invalid candidate generation')
+ require(entry['url'] == f'https://storage.googleapis.com/{bucket}/{prefix}/{FILES[key]}?generation={generation}',
+ 'candidate artifact is outside its generation-pinned prefix')
+ return receipt
+
+
+def check_jobs(run, jobs):
+ required = {'version', 'preflight', 'build-macos', 'build-linux (ubuntu-22.04, x64)',
+ 'build-linux (ubuntu-22.04-arm, arm64)', 'candidate', 'cleanup'}
+ require(required <= {job['name'] for job in jobs}, 'candidate build/verification jobs are missing')
+ for job in jobs:
+ require(job.get('run_id') == run['id'] and job.get('head_sha') == run['head_sha']
+ and 1 <= job.get('run_attempt', 0) <= run['run_attempt'], 'candidate job identity mismatch')
+ require(job.get('status') == 'completed' and job.get('conclusion') in {'success', 'skipped'}, 'candidate job did not pass')
+ if job['name'] in required:
+ require(job['conclusion'] == 'success', 'required candidate job was skipped')
+ require(all(step.get('conclusion') in {'success', 'skipped'} for step in job.get('steps', [])), 'candidate contains a failed step')
+
+
+def find_candidate(client, version, tree, bucket, current_run, wait_seconds=MAX_AGE_SECONDS):
+ """Look at a bounded recent set. Never wait past a candidate's build budget."""
+ now = datetime.now(timezone.utc)
+ runs = client.api('actions/workflows/release-desktop.yml/runs?event=workflow_dispatch&per_page=30')['workflow_runs']
+ # A completed candidate with identical bytes is immediately usable even if
+ # someone has unnecessarily started another build of the same tree/version.
+ runs.sort(key=lambda run: (run.get('conclusion') != 'success', -run['id']))
+ for listed in runs:
+ if listed.get('display_title') != f'Desktop candidate {version}' or listed.get('id') == current_run:
+ continue
+ run = client.api(f'actions/runs/{listed["id"]}')
+ check_run(run, client.repository, version)
+ original_source = run['head_sha']
+ if now - timestamp(run['created_at']) >= RETENTION:
+ continue
+ commit = client.api(f'git/commits/{run["head_sha"]}')
+ if commit.get('tree', {}).get('sha') != tree:
+ continue
+ # A clean squash changes the commit but preserves this complete tree,
+ # including the SDK pin, actions, packaging scripts and workflow itself.
+ end = time.monotonic() + max(0, min(wait_seconds, MAX_AGE_SECONDS - (now - timestamp(run['created_at'])).total_seconds()))
+ while run['status'] != 'completed' and time.monotonic() < end:
+ print(f'Waiting for matching candidate {run["id"]} ({run["status"]})', flush=True)
+ time.sleep(min(10, max(0, end - time.monotonic())))
+ try:
+ run = client.api(f'actions/runs/{listed["id"]}')
+ check_run(run, client.repository, version)
+ require(run['head_sha'] == original_source and run['id'] == listed['id'], 'candidate source changed while waiting')
+ except (OSError, KeyError, TypeError, ValueError, RuntimeError, subprocess.SubprocessError) as error:
+ raise CandidatePendingError(
+ f'Cannot confirm the matching candidate has finished: https://github.com/{client.repository}/actions/runs/{listed["id"]}. '
+ 'Follow that same run; no duplicate build was started.') from error
+ if run.get('status') != 'completed':
+ raise CandidatePendingError(
+ f'Candidate is still {run["status"]}: https://github.com/{client.repository}/actions/runs/{run["id"]}. '
+ 'Follow that run and retry release after it passes; no duplicate build was started.')
+ if run.get('conclusion') != 'success':
+ continue
+ jobs = client.api(f'actions/runs/{run["id"]}/jobs?filter=latest&per_page=100')
+ require(jobs['total_count'] == len(jobs['jobs']), 'candidate job list is incomplete')
+ check_jobs(run, jobs['jobs'])
+ artifacts = client.api(f'actions/runs/{run["id"]}/artifacts?per_page=100')['artifacts']
+ selected = [item for item in artifacts if item['name'] == f'desktop-release-candidate-{run["run_attempt"]}']
+ require(len(selected) == 1 and selected[0].get('size_in_bytes', 65537) <= 65536, 'candidate receipt is missing or too large')
+ artifact = selected[0]
+ archive = client.command('api', f'repos/{client.repository}/actions/artifacts/{artifact["id"]}/zip', binary=True)
+ receipt = read_receipt(artifact, archive, run, client.repository, version, tree, bucket, datetime.now(timezone.utc))
+ latest = client.api(f'actions/runs/{run["id"]}')
+ require(all(latest.get(key) == run.get(key) for key in ('id', 'head_sha', 'run_attempt', 'status', 'conclusion')),
+ 'candidate run changed while collecting it')
+ return receipt
+ return None
+
+
+def source_uri(receipt, key):
+ return f'gs://{receipt["bucket"]}/{receipt["prefix"]}/{FILES[key]}#{receipt["artifacts"][key]["generation"]}'
+
+
+def check_sources(receipt):
+ with ThreadPoolExecutor(max_workers=3) as pool:
+ descriptions = dict(zip(FILES, pool.map(lambda key: describe(source_uri(receipt, key)), FILES)))
+ for key, metadata in descriptions.items():
+ entry = receipt['artifacts'][key]
+ require(str(metadata.get('generation')) == entry['generation'] and int(metadata.get('size', -1)) == entry['size'],
+ 'candidate source disappeared or changed')
+
+
+def promote(receipt, destination, scratch):
+ """Copy pinned generations, never overwrite any release artifact."""
+ bucket, version = receipt['bucket'], receipt['version']
+ require(destination == f'harness/desktop/{version}' or
+ re.fullmatch(r'harness/desktop/\.candidate-check/[1-9][0-9]*-[1-9][0-9]*/artifacts', destination), 'invalid promotion destination')
+ require(re.fullmatch(r'harness/desktop/\.ci/[1-9][0-9]*-[1-9][0-9]*', scratch), 'invalid scratch prefix')
+ def copy(key):
+ publisher.gcloud('storage', 'cp', source_uri(receipt, key), f'gs://{bucket}/{destination}/{FILES[key]}',
+ '--if-generation-match=0', '--cache-control=public, max-age=31536000, immutable')
+ with ThreadPoolExecutor(max_workers=3) as pool:
+ list(pool.map(copy, FILES))
+ base = 'https://cdn.autonomous.ai' if destination == f'harness/desktop/{version}' else f'https://storage.googleapis.com/{bucket}'
+ with tempfile.TemporaryDirectory(prefix='desktop-candidate-parts-') as folder:
+ for name, keys in publisher.PARTS.items():
+ entries = {key: {field: receipt['artifacts'][key][field] for field in ('version', 'size', 'sha256')} for key in keys}
+ for key, entry in entries.items():
+ entry['url'] = f'{base}/{destination}/{FILES[key]}'
+ path = Path(folder) / name
+ path.write_text(json.dumps(entries) + '\n')
+ publisher.gcloud('storage', 'cp', str(path), f'gs://{bucket}/{scratch}/{name}', '--if-generation-match=0',
+ '--content-type=application/json', '--cache-control=no-cache, no-store, must-revalidate')
+
+
+def expired_objects(objects, now):
+ """Select only old, known candidate objects, pinned to listed generations."""
+ groups = {}
+ for item in objects:
+ name = item.get('name', '')
+ prefix, _, filename = name.rpartition('/')
+ if re.fullmatch(PREFIX, prefix):
+ groups.setdefault(prefix, []).append((filename, item))
+ expired = []
+ for prefix, items in groups.items():
+ selected = []
+ for filename, item in items:
+ generation = str(item.get('generation', ''))
+ created = item.get('creation_time', item.get('timeCreated', ''))
+ if filename not in FILES.values() or not re.fullmatch(r'[1-9][0-9]*', generation):
+ break
+ try:
+ if now - timestamp(created) < RETENTION:
+ break
+ except (TypeError, ValueError):
+ break
+ selected.append(f'{prefix}/{filename}#{generation}')
+ else:
+ expired.extend(selected)
+ return expired
+
+
+def output(name, value):
+ if destination := os.environ.get('GITHUB_OUTPUT'):
+ with open(destination, 'a') as stream:
+ stream.write(f'{name}={value}\n')
+
+
+def main(argv=None):
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('operation', choices=('seal', 'reuse', 'remove', 'expire'))
+ parser.add_argument('--bucket', default=os.environ.get('GCS_BUCKET', 's3-autonomous-upgrade-3'))
+ parser.add_argument('--version')
+ parser.add_argument('--prefix')
+ parser.add_argument('--parts', type=Path)
+ parser.add_argument('--destination')
+ parser.add_argument('--scratch')
+ parser.add_argument('--require-candidate', action='store_true')
+ parser.add_argument('--wait-seconds', type=int, choices=range(0, MAX_AGE_SECONDS + 1), default=MAX_AGE_SECONDS)
+ args = parser.parse_args(argv)
+ check_bucket(args.bucket)
+ if args.operation == 'remove':
+ check_prefix(args.prefix)
+ publisher.gcloud('storage', 'rm', '--recursive', f'gs://{args.bucket}/{args.prefix}/')
+ return 0
+ if args.operation == 'expire':
+ objects = json.loads(publisher.gcloud('storage', 'objects', 'list', f'gs://{args.bucket}/harness/desktop-candidates/**', '--raw', '--format=json'))
+ selected = expired_objects(objects, datetime.now(timezone.utc))
+ if selected:
+ publisher.gcloud('storage', 'rm', *[f'gs://{args.bucket}/{path}' for path in selected])
+ print(f'Removed {len(selected)} expired candidate objects')
+ return 0
+ publisher.version_tuple(args.version)
+ identity = context()
+ if args.operation == 'seal':
+ require(args.parts is not None, 'sealing requires platform manifests')
+ receipt = seal(args.version, args.bucket, args.prefix, args.parts, identity)
+ Path('desktop-release-candidate.json').write_text(json.dumps(receipt, indent=2) + '\n')
+ print('All six candidate downloads passed; no product manifest was published')
+ return 0
+ started = time.monotonic()
+ client = Client(identity['repository'], started + args.wait_seconds + 90)
+ try:
+ receipt = find_candidate(client, args.version, identity['source_tree'], args.bucket, identity['run_id'], args.wait_seconds)
+ if receipt:
+ check_sources(receipt)
+ except CandidatePendingError:
+ raise
+ except (OSError, KeyError, TypeError, ValueError, RuntimeError, subprocess.SubprocessError, zipfile.BadZipFile) as error:
+ print(f'Candidate unavailable; use a fresh build: {error}', flush=True)
+ receipt = None
+ if receipt is None:
+ output('reused', 'false')
+ require(not args.require_candidate, 'disposable promotion check requires a matching successful candidate')
+ return 0
+ # From the first destination write onward, failure is fatal. Rebuilding after
+ # a partial immutable copy could leave mixed packages under one version.
+ promote(receipt, args.destination, args.scratch)
+ output('reused', 'true')
+ output('candidate_prefix', receipt['prefix'])
+ result = dict(status='passed', version=args.version, source_tree=identity['source_tree'],
+ candidate_run=receipt['run_id'], candidate_attempt=receipt['run_attempt'],
+ duration_seconds=round(time.monotonic() - started, 3))
+ Path('desktop-candidate-reuse.json').write_text(json.dumps(result, indent=2) + '\n')
+ message = f'Reused all six verified packages from candidate {receipt["run_id"]} in {result["duration_seconds"]}s'
+ print(message)
+ if summary := os.environ.get('GITHUB_STEP_SUMMARY'):
+ with open(summary, 'a') as stream:
+ stream.write(message + '\n')
+ return 0
+
+
+if __name__ == '__main__':
+ try:
+ sys.exit(main())
+ except (OSError, KeyError, TypeError, ValueError, RuntimeError, subprocess.SubprocessError) as error:
+ print(f'error: {error}', file=sys.stderr)
+ sys.exit(1)
diff --git a/scripts/tests/test_desktop_release_candidate.py b/scripts/tests/test_desktop_release_candidate.py
new file mode 100644
index 000000000..6a4ec0e8e
--- /dev/null
+++ b/scripts/tests/test_desktop_release_candidate.py
@@ -0,0 +1,347 @@
+"""Candidate identity, artifact promotion and bounded discovery contracts."""
+import copy
+from datetime import datetime, timedelta, timezone
+import hashlib
+import importlib.util
+import io
+import json
+import os
+from pathlib import Path
+import tempfile
+import unittest
+from unittest.mock import patch
+import zipfile
+
+ROOT = Path(__file__).resolve().parents[2]
+spec = importlib.util.spec_from_file_location('candidate', ROOT / 'scripts/desktop-release-candidate.py')
+candidate = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(candidate)
+
+REPOSITORY = 'owner/project'
+BUCKET = 'fixture-bucket'
+SHA = 'a' * 40
+TREE = 'b' * 40
+PREFIX = 'harness/desktop-candidates/123-1-' + 'c' * 32
+VERSION = '1.2.55'
+NOW = datetime.now(timezone.utc)
+
+
+def make_receipt():
+ entries = {}
+ for index, (key, filename) in enumerate(candidate.FILES.items(), 1):
+ payload = key.encode()
+ entries[key] = dict(version=VERSION, size=len(payload), sha256=hashlib.sha256(payload).hexdigest(),
+ generation=str(index), url=f'https://storage.googleapis.com/{BUCKET}/{PREFIX}/{filename}?generation={index}')
+ return dict(schema=1, status='passed', version=VERSION, bucket=BUCKET, prefix=PREFIX, repository=REPOSITORY,
+ run_id=123, run_attempt=1, source_sha=SHA, source_tree=TREE,
+ created_at=(NOW - timedelta(seconds=10)).isoformat(), artifacts=entries)
+
+
+def make_run():
+ return dict(id=123, run_attempt=1, head_sha=SHA, path=candidate.WORKFLOW, event='workflow_dispatch',
+ repository=dict(full_name=REPOSITORY), display_title=f'Desktop candidate {VERSION}',
+ status='completed', conclusion='success', created_at=(NOW - timedelta(minutes=1)).isoformat())
+
+
+def archive_receipt(receipt):
+ archive = io.BytesIO()
+ with zipfile.ZipFile(archive, 'w') as bundle:
+ bundle.writestr('desktop-release-candidate.json', json.dumps(receipt))
+ data = archive.getvalue()
+ artifact = dict(id=99, name='desktop-release-candidate-1', expired=False, size_in_bytes=len(data),
+ workflow_run=dict(id=123, head_sha=SHA), digest='sha256:' + hashlib.sha256(data).hexdigest())
+ return artifact, data
+
+
+def make_jobs():
+ return [dict(name=name, id=index, run_id=123, run_attempt=1, head_sha=SHA, status='completed', conclusion='success',
+ steps=[dict(conclusion='success')]) for index, name in enumerate(
+ ['version', 'preflight', 'build-macos', 'build-linux (ubuntu-22.04, x64)',
+ 'build-linux (ubuntu-22.04-arm, arm64)', 'candidate', 'cleanup'])]
+
+
+class FakeGithub:
+ repository = REPOSITORY
+
+ def __init__(self):
+ self.run = make_run()
+ self.receipt = make_receipt()
+ self.artifact, self.archive = archive_receipt(self.receipt)
+ self.tree = TREE
+ self.jobs = make_jobs()
+ self.calls = []
+ self.run_reads = 0
+
+ def api(self, path):
+ self.calls.append(path)
+ if path.startswith('actions/workflows/'):
+ return dict(workflow_runs=[copy.deepcopy(self.run)])
+ if path.startswith('git/commits/'):
+ return dict(tree=dict(sha=self.tree))
+ if '/artifacts?' in path:
+ return dict(artifacts=[copy.deepcopy(self.artifact)])
+ if '/jobs?' in path:
+ return dict(total_count=len(self.jobs), jobs=copy.deepcopy(self.jobs))
+ if path == 'actions/runs/123':
+ self.run_reads += 1
+ return copy.deepcopy(self.run)
+ raise AssertionError(path)
+
+ def command(self, *args, binary=False):
+ assert args == ('api', f'repos/{REPOSITORY}/actions/artifacts/99/zip') and binary
+ return self.archive
+
+
+class CandidateIdentityTests(unittest.TestCase):
+ def read(self, receipt=None, artifact_change=None, **overrides):
+ receipt = receipt or make_receipt()
+ artifact, archive = archive_receipt(receipt)
+ if artifact_change:
+ artifact_change(artifact)
+ args = dict(run=make_run(), repository=REPOSITORY, version=VERSION, tree=TREE, bucket=BUCKET, now=NOW)
+ args.update(overrides)
+ return candidate.read_receipt(artifact, archive, **args)
+
+ def test_clean_squash_with_identical_tree_keeps_artifacts(self):
+ receipt = self.read()
+ self.assertEqual(receipt['source_sha'], SHA)
+ self.assertEqual(receipt['source_tree'], TREE)
+ # The release commit may differ; its complete tree is the contract.
+ client = FakeGithub()
+ self.assertEqual(candidate.find_candidate(client, VERSION, TREE, BUCKET, 456), receipt)
+
+ def test_source_version_and_repository_changes_cannot_reuse(self):
+ for field, value in [('tree', 'd' * 40), ('version', '1.2.56'), ('repository', 'other/project'), ('bucket', 'other-bucket')]:
+ with self.subTest(field=field), self.assertRaises(ValueError):
+ self.read(**{field: value})
+
+ def test_receipt_requires_all_six_verified_objects_with_exact_paths(self):
+ mutations = [
+ lambda r: r.update(status='failed'), lambda r: r.update(schema=2),
+ lambda r: r.update(run_attempt=2), lambda r: r.update(source_sha='e' * 40),
+ lambda r: r.update(prefix=PREFIX.replace('/123-', '/124-')),
+ lambda r: r['artifacts'].pop('desktop-linux-arm64'),
+ lambda r: r['artifacts'].update(extra=r['artifacts']['desktop-macos']),
+ lambda r: r['artifacts']['desktop-macos'].update(size=True),
+ lambda r: r['artifacts']['desktop-macos'].update(sha256='bad'),
+ lambda r: r['artifacts']['desktop-macos'].update(generation='0'),
+ lambda r: r['artifacts']['desktop-macos'].update(url='https://example.com/other.zip'),
+ lambda r: r['artifacts']['desktop-macos'].update(url=r['artifacts']['desktop-macos']['url'].split('?')[0]),
+ lambda r: r.update(created_at=(NOW + timedelta(seconds=1)).isoformat()),
+ lambda r: r.update(created_at=(NOW - timedelta(days=8)).isoformat()),
+ ]
+ for index, change in enumerate(mutations):
+ with self.subTest(index=index), self.assertRaises(ValueError):
+ receipt = make_receipt()
+ change(receipt)
+ self.read(receipt)
+
+ def test_github_artifact_provenance_and_digest_are_required(self):
+ for field, value in [('name', 'unrelated'), ('expired', True), ('digest', 'sha256:' + 'f' * 64),
+ ('workflow_run', dict(id=456, head_sha=SHA)), ('workflow_run', dict(id=123, head_sha='f' * 40))]:
+ with self.subTest(field=field), self.assertRaises(ValueError):
+ self.read(artifact_change=lambda a: a.update({field: value}))
+
+ def test_no_candidate_for_failed_incomplete_changed_or_old_build(self):
+ for change in ['failed', 'different-tree', 'different-version', 'old']:
+ with self.subTest(change=change):
+ client = FakeGithub()
+ if change == 'failed': client.run['conclusion'] = 'failure'
+ if change == 'different-tree': client.tree = 'd' * 40
+ if change == 'different-version': client.run['display_title'] = 'Desktop candidate 1.2.56'
+ if change == 'old': client.run['created_at'] = (NOW - timedelta(days=8)).isoformat()
+ with patch.object(candidate.time, 'sleep') as sleep:
+ self.assertIsNone(candidate.find_candidate(client, VERSION, TREE, BUCKET, 456, wait_seconds=0))
+ sleep.assert_not_called()
+
+ def test_builds_and_verification_cannot_be_missing_skipped_or_failed(self):
+ for change in ['missing', 'skipped', 'failed-step', 'wrong-source']:
+ with self.subTest(change=change), self.assertRaises(ValueError):
+ client = FakeGithub()
+ if change == 'missing': client.jobs.pop()
+ if change == 'skipped': client.jobs[2]['conclusion'] = 'skipped'
+ if change == 'failed-step': client.jobs[2]['steps'][0]['conclusion'] = 'failure'
+ if change == 'wrong-source': client.jobs[2]['head_sha'] = 'f' * 40
+ candidate.find_candidate(client, VERSION, TREE, BUCKET, 456)
+
+ def test_wait_follows_one_live_run_without_starting_another(self):
+ client = FakeGithub()
+ client.run.update(status='in_progress', conclusion=None)
+ def finish(seconds):
+ client.run.update(status='completed', conclusion='success')
+ with patch.object(candidate.time, 'sleep', side_effect=finish) as sleep:
+ result = candidate.find_candidate(client, VERSION, TREE, BUCKET, 456)
+ self.assertEqual(result['run_id'], 123)
+ self.assertEqual(sleep.call_count, 1)
+ self.assertTrue(all(path.startswith(('actions/', 'git/')) for path in client.calls))
+
+ def test_an_old_in_progress_run_does_not_get_another_wait_budget(self):
+ client = FakeGithub()
+ client.run.update(status='in_progress', conclusion=None,
+ created_at=(NOW - timedelta(seconds=candidate.MAX_AGE_SECONDS + 1)).isoformat())
+ with patch.object(candidate.time, 'sleep') as sleep:
+ with self.assertRaisesRegex(candidate.CandidatePendingError, 'actions/runs/123'):
+ candidate.find_candidate(client, VERSION, TREE, BUCKET, 456)
+ sleep.assert_not_called()
+
+ def test_pending_deadline_stops_release_without_dispatching_a_replacement(self):
+ client = FakeGithub()
+ client.run.update(status='queued', conclusion=None)
+ with patch.object(candidate.time, 'sleep') as sleep:
+ with self.assertRaises(candidate.CandidatePendingError):
+ candidate.find_candidate(client, VERSION, TREE, BUCKET, 456, wait_seconds=0)
+ sleep.assert_not_called()
+ receipt = make_receipt()
+ identity = {key: receipt[key] for key in ['repository', 'run_id', 'run_attempt', 'source_sha', 'source_tree']}
+ with patch.object(candidate, 'context', return_value=identity), \
+ patch.object(candidate, 'find_candidate', side_effect=candidate.CandidatePendingError('still live')), \
+ patch.object(candidate, 'output') as output, patch.object(candidate, 'promote') as promote:
+ with self.assertRaises(candidate.CandidatePendingError):
+ candidate.main(['reuse', '--version', VERSION, '--bucket', BUCKET])
+ output.assert_not_called()
+ promote.assert_not_called()
+
+ def test_rerun_during_collection_cannot_reuse_an_old_receipt(self):
+ client = FakeGithub()
+ original = client.api
+ def api(path):
+ data = original(path)
+ if path == 'actions/runs/123' and client.run_reads == 2:
+ data['run_attempt'] = 2
+ return data
+ client.api = api
+ with self.assertRaisesRegex(ValueError, 'changed while collecting'):
+ candidate.find_candidate(client, VERSION, TREE, BUCKET, 456)
+
+ def test_failed_observation_of_a_live_build_never_triggers_another_build(self):
+ client = FakeGithub()
+ client.run.update(status='in_progress', conclusion=None)
+ original = client.api
+ def api(path):
+ if path == 'actions/runs/123' and client.run_reads:
+ raise RuntimeError('temporary GitHub outage')
+ return original(path)
+ client.api = api
+ with patch.object(candidate.time, 'sleep'):
+ with self.assertRaisesRegex(candidate.CandidatePendingError, 'Cannot confirm'):
+ candidate.find_candidate(client, VERSION, TREE, BUCKET, 456)
+
+ def test_other_workflow_or_repository_cannot_produce_a_candidate(self):
+ for field, value in [('path', '.github/workflows/desktop-internal-build.yml'), ('event', 'pull_request'),
+ ('repository', dict(full_name='untrusted/fork'))]:
+ with self.subTest(field=field), self.assertRaises(ValueError):
+ client = FakeGithub()
+ client.run[field] = value
+ candidate.find_candidate(client, VERSION, TREE, BUCKET, 456)
+
+ def test_copy_failure_is_fatal_and_never_becomes_a_fresh_build(self):
+ receipt = make_receipt()
+ identity = {key: receipt[key] for key in ['repository', 'run_id', 'run_attempt', 'source_sha', 'source_tree']}
+ with patch.object(candidate, 'context', return_value=identity), \
+ patch.object(candidate, 'find_candidate', return_value=receipt), \
+ patch.object(candidate, 'check_sources'), \
+ patch.object(candidate, 'output') as output, \
+ patch.object(candidate, 'promote', side_effect=RuntimeError('partial immutable copy')):
+ with self.assertRaisesRegex(RuntimeError, 'partial immutable copy'):
+ candidate.main(['reuse', '--version', VERSION, '--bucket', BUCKET])
+ output.assert_not_called()
+
+ def test_lookup_failure_falls_back_but_disposable_check_requires_reuse(self):
+ receipt = make_receipt()
+ identity = {key: receipt[key] for key in ['repository', 'run_id', 'run_attempt', 'source_sha', 'source_tree']}
+ with patch.object(candidate, 'context', return_value=identity), \
+ patch.object(candidate, 'find_candidate', side_effect=RuntimeError('API unavailable')), \
+ patch.object(candidate, 'output') as output, patch.object(candidate, 'promote') as promote:
+ self.assertEqual(candidate.main(['reuse', '--version', VERSION, '--bucket', BUCKET]), 0)
+ output.assert_called_with('reused', 'false')
+ with self.assertRaisesRegex(ValueError, 'requires a matching'):
+ candidate.main(['reuse', '--version', VERSION, '--bucket', BUCKET, '--require-candidate'])
+ promote.assert_not_called()
+
+
+class CandidatePromotionTests(unittest.TestCase):
+ def test_copies_pinned_bytes_and_preserves_canonical_manifest_contract(self):
+ receipt = make_receipt()
+ objects = {candidate.source_uri(receipt, key): key.encode() for key in candidate.FILES}
+ # A different current object cannot change which generation is copied.
+ objects.update({uri.split('#')[0]: b'changed after verification' for uri in list(objects)})
+ calls = []
+ def gcloud(*args):
+ self.assertEqual(args[:2], ('storage', 'cp'))
+ source, destination = args[2:4]
+ self.assertIn('--if-generation-match=0', args)
+ if destination in objects:
+ raise RuntimeError('412: destination exists')
+ objects[destination] = objects[source] if source.startswith('gs://') else Path(source).read_bytes()
+ calls.append(args)
+ return ''
+ with patch.object(candidate.publisher, 'gcloud', side_effect=gcloud):
+ candidate.promote(receipt, f'harness/desktop/{VERSION}', 'harness/desktop/.ci/456-1')
+ before = copy.deepcopy(objects)
+ with self.assertRaisesRegex(RuntimeError, 'destination exists'):
+ candidate.promote(receipt, f'harness/desktop/{VERSION}', 'harness/desktop/.ci/456-1')
+ self.assertEqual(before, objects)
+ for key, filename in candidate.FILES.items():
+ self.assertEqual(objects[f'gs://{BUCKET}/harness/desktop/{VERSION}/{filename}'], key.encode())
+ with tempfile.TemporaryDirectory() as folder:
+ for name in candidate.publisher.PARTS:
+ (Path(folder) / name).write_bytes(objects[f'gs://{BUCKET}/harness/desktop/.ci/456-1/{name}'])
+ entries = candidate.publisher.read_parts(Path(folder), VERSION)
+ self.assertTrue(all(entry['url'].startswith(f'https://cdn.autonomous.ai/harness/desktop/{VERSION}/') for entry in entries.values()))
+ self.assertFalse(any('metadata.json' in call[3] for call in calls))
+
+ def test_destinations_and_source_generations_are_checked_before_writes(self):
+ receipt = make_receipt()
+ with patch.object(candidate.publisher, 'gcloud') as gcloud:
+ for destination in ['harness/desktop/1.2.54', 'harness/desktop', '../anything', PREFIX]:
+ with self.subTest(destination=destination), self.assertRaises(ValueError):
+ candidate.promote(receipt, destination, 'harness/desktop/.ci/456-1')
+ gcloud.assert_not_called()
+ with patch.object(candidate, 'describe', return_value=dict(generation='999', size=14)):
+ with self.assertRaises(ValueError):
+ candidate.check_sources(receipt)
+
+ def test_source_check_uses_every_pinned_generation(self):
+ receipt = make_receipt()
+ seen = []
+ def describe(uri):
+ seen.append(uri)
+ key = next(key for key in candidate.FILES if uri == candidate.source_uri(receipt, key))
+ return receipt['artifacts'][key]
+ with patch.object(candidate, 'describe', side_effect=describe):
+ candidate.check_sources(receipt)
+ self.assertEqual(set(seen), {candidate.source_uri(receipt, key) for key in candidate.FILES})
+
+ def test_sealing_rejects_missing_platform_or_wrong_source_url(self):
+ receipt = make_receipt()
+ identity = {key: receipt[key] for key in ['repository', 'run_id', 'run_attempt', 'source_sha', 'source_tree']}
+ with tempfile.TemporaryDirectory() as folder:
+ path = Path(folder)
+ for name, keys in candidate.publisher.PARTS.items():
+ part = {key: dict(receipt['artifacts'][key], url='https://example.com/unverified') for key in keys}
+ (path / name).write_text(json.dumps(part))
+ with patch.object(candidate.publisher, 'gcloud') as gcloud:
+ with self.assertRaisesRegex(ValueError, 'owned object'):
+ candidate.seal(VERSION, BUCKET, PREFIX, path, identity)
+ gcloud.assert_not_called()
+ (path / 'linux-arm64.json').unlink()
+ with self.assertRaisesRegex(ValueError, 'four platform manifests'):
+ candidate.seal(VERSION, BUCKET, PREFIX, path, identity)
+
+ def test_cleanup_never_selects_production_recent_unknown_or_unpinned_objects(self):
+ def object_at(prefix, name, days=8, generation='17'):
+ return dict(name=f'{prefix}/{name}', generation=generation, creation_time=(NOW - timedelta(days=days)).isoformat())
+ filename = candidate.FILES['desktop-macos']
+ old = object_at(PREFIX, filename)
+ self.assertEqual(candidate.expired_objects([old], NOW), [f'{PREFIX}/{filename}#17'])
+ self.assertEqual(candidate.expired_objects([object_at('harness/desktop/1.2.54', filename)], NOW), [])
+ self.assertEqual(candidate.expired_objects([old, object_at(PREFIX, candidate.FILES['desktop-linux-x64'], days=1)], NOW), [])
+ self.assertEqual(candidate.expired_objects([old, object_at(PREFIX, 'unrecognized.txt')], NOW), [])
+ self.assertEqual(candidate.expired_objects([object_at(PREFIX, filename, generation='')], NOW), [])
+ for prefix in ['harness/desktop', '', PREFIX + '/../1.2.54', PREFIX + '/nested']:
+ with self.subTest(prefix=prefix), self.assertRaises(ValueError):
+ candidate.check_prefix(prefix)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/scripts/tests/test_desktop_release_notes.py b/scripts/tests/test_desktop_release_notes.py
index e55cdc06f..f42ece9d0 100644
--- a/scripts/tests/test_desktop_release_notes.py
+++ b/scripts/tests/test_desktop_release_notes.py
@@ -1,6 +1,7 @@
"""Exercise normal shallow tag notes and the legacy full-history fallback."""
import os
from pathlib import Path
+import re
import subprocess
import tempfile
import textwrap
@@ -41,12 +42,14 @@ class DesktopReleaseNotesTests(unittest.TestCase):
git("tag", "-f", tag, "HEAD", cwd=checkout)
workflow = (ROOT / ".github/workflows/release-desktop.yml").read_text()
block = workflow.split(" - name: Take the release notes from the tag\n", 1)[1]
- script = textwrap.dedent(block.split(" run: |\n", 1)[1].split(" - uses: softprops/", 1)[0])
+ script = textwrap.dedent(re.split(r"\n - (?:name|uses):", block.split(" run: |\n", 1)[1], maxsplit=1)[0])
env = dict(os.environ, REF_NAME=tag, VERSION="1.2.2")
result = subprocess.run(["bash", "-e", "-c", script], cwd=checkout, env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertNotIn("here-document", result.stderr)
notes = (checkout / "RELEASE_NOTES.md").read_text()
self.assertIn("## Downloads", notes)
+ self.assertNotIn('echo "::group::', notes)
self.assertEqual(git("rev-parse", "--is-shallow-repository", cwd=checkout), "true" if annotated else "false")
if annotated:
self.assertTrue(notes.startswith("Reviewed release notes"))
diff --git a/scripts/tests/test_desktop_release_prepare.py b/scripts/tests/test_desktop_release_prepare.py
new file mode 100644
index 000000000..7d110cc94
--- /dev/null
+++ b/scripts/tests/test_desktop_release_prepare.py
@@ -0,0 +1,96 @@
+"""Run the real prepare command against a private Git fixture and fake transport."""
+import json
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+class DesktopPrepareTests(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.temp.cleanup)
+ self.root = Path(self.temp.name)
+ self.repo = self.root / 'repo'
+ self.repo.mkdir()
+ self.remote = self.root / 'origin'
+ self.bin = self.root / 'bin'
+ self.bin.mkdir()
+ self.log = self.root / 'gh.json'
+ self.env = dict(os.environ, PATH=str(self.bin) + os.pathsep + os.environ['PATH'], PREPARE_FIXTURE_LOG=str(self.log))
+ self.env.pop('BRANCH', None)
+ self.env.pop('GIT_DIR', None)
+ self.env.pop('GIT_WORK_TREE', None)
+ self.git('init', '-q', '-b', 'main')
+ source = self.repo / 'desktop/scripts'
+ source.mkdir(parents=True)
+ shutil.copyfile(ROOT / 'desktop/scripts/release-desktop.sh', source / 'release-desktop.sh')
+ self.git('add', '.')
+ self.git('commit', '-qm', 'previous version')
+ self.git('tag', '-a', 'v1.2.54_desktop', '-m', 'previous release')
+ self.git('init', '-q', '--bare', str(self.remote))
+ self.git('remote', 'add', 'origin', str(self.remote))
+ self.git('push', '-q', 'origin', 'main', '--tags')
+ self.git('switch', '-qc', 'candidate-branch')
+ self.git('commit', '--allow-empty', '-qm', 'tested change')
+ self.git('push', '-qu', 'origin', 'candidate-branch')
+ for name, body in {
+ 'curl': '#!/usr/bin/env python3\nprint(\'{"desktop-macos":{"version":"1.2.54"}}\')\n',
+ 'gh': '#!/usr/bin/env python3\nimport json, os, sys\nfrom pathlib import Path\nPath(os.environ["PREPARE_FIXTURE_LOG"]).write_text(json.dumps(sys.argv[1:]))\n',
+ }.items():
+ path = self.bin / name
+ path.write_text(body)
+ path.chmod(0o755)
+
+ def git(self, *args):
+ return subprocess.check_output(['git', '-c', 'user.name=Fixture', '-c', '[email protected]', *args],
+ cwd=self.repo, env=self.env, stderr=subprocess.STDOUT, text=True, timeout=10).strip()
+
+ def run_script(self, *args):
+ return subprocess.run(['bash', 'desktop/scripts/release-desktop.sh', *args], cwd=self.repo,
+ env=self.env, capture_output=True, text=True, timeout=10)
+
+ def test_prepare_dispatches_pushed_pr_version_without_tagging_or_releasing(self):
+ before = self.git('ls-remote', '--tags', 'origin')
+ result = self.run_script('--prepare')
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(json.loads(self.log.read_text()), ['workflow', 'run', 'release-desktop.yml', '--ref', 'candidate-branch',
+ '-f', 'version=1.2.55', '-f', 'prepare_only=true'])
+ self.assertEqual(self.git('ls-remote', '--tags', 'origin'), before)
+ self.assertNotIn('v1.2.55_desktop', self.git('tag', '-l'))
+
+ def test_prepare_dry_run_has_no_dispatch_or_tag(self):
+ result = self.run_script('--prepare', '--dry-run', '1.3.1')
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertFalse(self.log.exists())
+ self.assertNotIn('v1.3.1_desktop', self.git('tag', '-l'))
+
+ def test_prepare_rejects_dirty_or_unpushed_source_and_older_branch_tip(self):
+ (self.repo / 'dirty').write_text('uncommitted')
+ result = self.run_script('--prepare')
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn('dirty', result.stderr)
+ (self.repo / 'dirty').unlink()
+ self.git('commit', '--allow-empty', '-qm', 'not pushed')
+ result = self.run_script('--prepare')
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn('not on origin/', result.stderr)
+ self.git('reset', '--hard', 'HEAD~2')
+ result = self.run_script('--prepare')
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn('pushed branch tip', result.stderr)
+ self.assertFalse(self.log.exists())
+
+ def test_prepare_and_wait_are_not_ambiguous(self):
+ result = self.run_script('--prepare', '--wait')
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn('use --wait when releasing', result.stderr)
+ self.assertFalse(self.log.exists())
+
+
+if __name__ == '__main__':
+ unittest.main()