diff --git a/.github/actions/setup-android-helper-signing/action.yml b/.github/actions/setup-android-helper-signing/action.yml new file mode 100644 index 00000000000..0c8b9797a7a --- /dev/null +++ b/.github/actions/setup-android-helper-signing/action.yml @@ -0,0 +1,24 @@ +name: Setup Android helper signing +description: Writes the release keystore and exports its path. The caller passes the password to its build step. +inputs: + keystore-base64: + description: Base64 of the release keystore. + required: false + keystore-password: + description: Password of the release keystore and its key. + required: false +runs: + using: composite + steps: + - shell: bash + env: + KEYSTORE_BASE64: ${{ inputs.keystore-base64 }} + KEYSTORE_PASSWORD: ${{ inputs.keystore-password }} + run: | + set -euo pipefail + if [ -z "$KEYSTORE_BASE64" ] || [ -z "$KEYSTORE_PASSWORD" ]; then + echo "::error::Release builds need the ANDROID_HELPER_KEYSTORE_BASE64 and ANDROID_HELPER_KEYSTORE_PASSWORD secrets." + exit 1 + fi + printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/android-helper.keystore" + echo "AGENT_DEVICE_ANDROID_KEYSTORE=$RUNNER_TEMP/android-helper.keystore" >> "$GITHUB_ENV" diff --git a/.github/workflows/release-android-snapshot-helper.yml b/.github/workflows/release-android-snapshot-helper.yml index b87afd6f2f7..c6d1437579c 100644 --- a/.github/workflows/release-android-snapshot-helper.yml +++ b/.github/workflows/release-android-snapshot-helper.yml @@ -14,10 +14,6 @@ on: description: GitHub Release tag to upload assets to, for example v0.13.3. required: true type: string - checkout_ref: - description: Optional branch, tag, or commit SHA to build. Defaults to the selected workflow ref. - required: false - type: string permissions: contents: write @@ -27,11 +23,16 @@ jobs: name: Publish Android Snapshot Helper runs-on: blacksmith-4vcpu-ubuntu-2404 timeout-minutes: 30 + # The helper keystore secrets live only in the protected `release` environment. Its deployment + # rule gates github.ref, so the job builds exactly that ref. + environment: release + env: + AGENT_DEVICE_ANDROID_HELPER_RELEASE: '1' steps: - name: Checkout uses: useblacksmith/checkout@2b9fe87d796feea153b455ec2f3125b471a7b0e7 # v1.8.2 with: - ref: ${{ inputs.checkout_ref || github.ref }} + ref: ${{ github.ref }} - name: Checkout release validator uses: useblacksmith/checkout@2b9fe87d796feea153b455ec2f3125b471a7b0e7 # v1.8.2 @@ -64,6 +65,12 @@ jobs: - name: Setup Android SDK uses: ./.github/actions/setup-android-sdk + - name: Setup Android helper signing + uses: ./.github/actions/setup-android-helper-signing + with: + keystore-base64: ${{ secrets.ANDROID_HELPER_KEYSTORE_BASE64 }} + keystore-password: ${{ secrets.ANDROID_HELPER_KEYSTORE_PASSWORD }} + - name: Check Java toolchain run: | javac --version @@ -76,6 +83,7 @@ jobs: RELEASE_VERSION: ${{ steps.meta.outputs.version }} RELEASE_TAG: ${{ steps.meta.outputs.tag }} AGENT_DEVICE_ANDROID_HELPER: snapshot + AGENT_DEVICE_ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_HELPER_KEYSTORE_PASSWORD }} run: | set -euo pipefail mkdir -p "${RELEASE_ASSET_DIR}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d894944efd3..91d202235cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -85,8 +85,13 @@ jobs: permissions: contents: read cache-mode: none + # The helper keystore secrets live only in the protected `release` environment, so PR dry + # runs never receive them and sign with a throwaway key. + environment: ${{ needs.plan.outputs.mode != 'dry-run' && 'release' || '' }} env: VERSION: ${{ needs.plan.outputs.version }} + # scripts/build-android-helper.sh fails instead of using a throwaway key when this is set. + AGENT_DEVICE_ANDROID_HELPER_RELEASE: ${{ needs.plan.outputs.mode != 'dry-run' && '1' || '' }} steps: - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -100,7 +105,9 @@ jobs: persist-credentials: false ref: ${{ github.workflow_sha }} path: .release-tools - sparse-checkout: scripts/release-version.mjs + sparse-checkout: | + scripts/release-version.mjs + .github/actions/setup-android-helper-signing/action.yml sparse-checkout-cone-mode: false # No dependency cache: published bytes come from a clean install. @@ -113,10 +120,20 @@ jobs: - name: Setup Android SDK uses: ./.github/actions/setup-android-sdk + - name: Setup Android helper signing + if: needs.plan.outputs.mode != 'dry-run' + # From the workflow commit: the planned nightly source may predate this action. + uses: ./.release-tools/.github/actions/setup-android-helper-signing + with: + keystore-base64: ${{ secrets.ANDROID_HELPER_KEYSTORE_BASE64 }} + keystore-password: ${{ secrets.ANDROID_HELPER_KEYSTORE_PASSWORD }} + - name: Stamp release version run: node .release-tools/scripts/release-version.mjs stamp "$VERSION" - name: Build and verify every public package + env: + AGENT_DEVICE_ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_HELPER_KEYSTORE_PASSWORD }} run: pnpm release:prepare - name: Upload packages @@ -281,7 +298,7 @@ jobs: # agent-device.dev serves /.well-known/mcp.json with the npm `latest` version read when the # site builds. A tag push builds nothing on Vercel, so ask for a production build of main once # npm serves the new version. The VERCEL_SITE_DEPLOY_HOOK secret holds the Vercel deploy hook - # of the agent-device-website project for main; it is the only secret this workflow reads. + # of the agent-device-website project for main; it is the only secret the post-publish jobs read. redeploy-site: name: Redeploy agent-device.dev needs: [plan, publish] diff --git a/test/ci/release-workflow.test.ts b/test/ci/release-workflow.test.ts index f67b9f43f99..ca76df0eacd 100644 --- a/test/ci/release-workflow.test.ts +++ b/test/ci/release-workflow.test.ts @@ -10,6 +10,7 @@ type Job = { 'cache-mode'?: string; 'runs-on'?: string; environment?: string; + env?: Record; permissions?: Record; steps?: Array<{ id?: string; @@ -40,19 +41,31 @@ test('only the npm publisher and the MCP Registry call can mint an id-token', () }); /** The secret names a job references, wherever in the job they appear. */ -const secretsOf = (job: Job) => - [...JSON.stringify(job).matchAll(/secrets\.([A-Za-z0-9_]+)/g)].map(([, name]) => name); +const secretsOf = (job: Job) => [ + ...new Set( + [...JSON.stringify(job).matchAll(/secrets\.([A-Za-z0-9_]+)/g)].map(([, name]) => name), + ), +]; test('the publisher authenticates through OIDC alone', () => { expect(source).not.toMatch(/NPM_TOKEN|NODE_AUTH_TOKEN/); - // No secret reaches the jobs that build or publish the packages. The one secret in the file - // is the site's deploy hook, which only the redeploy job after a stable release reads. + // No secret reaches the publisher. The build reads only the Android helper keystore, and only + // in the protected `release` environment that PR dry runs never enter. The site's deploy hook + // is read only by the redeploy job after a stable release. expect(secretsOf(workflow.jobs.publish ?? {})).toEqual([]); - expect(secretsOf(workflow.jobs.build ?? {})).toEqual([]); + expect(workflow.jobs.build?.environment).toBe( + "${{ needs.plan.outputs.mode != 'dry-run' && 'release' || '' }}", + ); + expect(workflow.jobs.build?.env?.AGENT_DEVICE_ANDROID_HELPER_RELEASE).toBe( + "${{ needs.plan.outputs.mode != 'dry-run' && '1' || '' }}", + ); const withSecrets = Object.entries(workflow.jobs) .map(([name, job]) => [name, secretsOf(job)] as const) .filter(([, names]) => names.length > 0); - expect(withSecrets).toEqual([['redeploy-site', ['VERCEL_SITE_DEPLOY_HOOK']]]); + expect(withSecrets).toEqual([ + ['build', ['ANDROID_HELPER_KEYSTORE_BASE64', 'ANDROID_HELPER_KEYSTORE_PASSWORD']], + ['redeploy-site', ['VERCEL_SITE_DEPLOY_HOOK']], + ]); const setupNode = workflow.jobs.publish?.steps?.find((step) => step.uses?.startsWith('actions/setup-node@'), ); @@ -88,6 +101,9 @@ test('the version stamping entrypoint is pinned to the workflow commit', () => { (step) => step.with?.path === '.release-tools', ); expect(entrypoint?.with?.ref).toBe('${{ github.workflow_sha }}'); + expect( + workflow.jobs.build?.steps?.find((step) => step.name === 'Setup Android helper signing')?.uses, + ).toBe('./.release-tools/.github/actions/setup-android-helper-signing'); }); test('both nightly schedules keep separate concurrency groups for cron and manual selection', () => { diff --git a/test/repo-guards/release-assets.test.ts b/test/repo-guards/release-assets.test.ts index c75768bc275..1306537d0d8 100644 --- a/test/repo-guards/release-assets.test.ts +++ b/test/repo-guards/release-assets.test.ts @@ -197,6 +197,7 @@ for (const workflow of workflows) { const repositories: Record> = { caller: { '${{ inputs.checkout_ref || github.ref }}': historical, + '${{ github.ref }}': historical, '${{ github.workflow_sha }}': historical, '${{ job.workflow_sha }}': historical, },