diff --git a/.github/workflows/_desktop-release.yml b/.github/workflows/_desktop-release.yml index e1ac19d44f1..568dacf066f 100644 --- a/.github/workflows/_desktop-release.yml +++ b/.github/workflows/_desktop-release.yml @@ -201,6 +201,11 @@ jobs: build-windows: name: Build and Release Windows + # The EV signing service account (coder-ci) only trusts jobs in this + # environment, which only main and v* tags may use. v* tags are not + # protected in this repository, so callers must only pass a commit on main + # (release.yml's preflight resolves the tag and checks this). + environment: code-signing runs-on: windows-latest permissions: contents: write # Upload release assets diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e59a31cfec2..8242abed5ea 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1338,6 +1338,10 @@ jobs: # Windows builds are slow - only run in merge queue and main pushes, not on every PR push if: ${{ (github.event_name == 'merge_group' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (needs.changes.outputs.src == 'true' || needs.changes.outputs.config == 'true') }} runs-on: windows-latest + # Pushes to main sign with the EV key, whose service account (coder-ci) + # only trusts jobs in code-signing. Merge queue builds run the queued PR's + # code, so they get no environment and stay unsigned. + environment: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'code-signing' || '' }} permissions: contents: read id-token: write # GCP workload identity for Windows code signing diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5213c62c29f..83d4da633f4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,11 +19,19 @@ jobs: preflight: name: Validate release target runs-on: ubuntu-latest + outputs: + # The commit every build job checks out: the release tag's commit, which + # must be on main. desktop-builds signs in the code-signing environment, + # which is granted from the dispatch ref (main), and v* tags are not + # protected, so it must not build a commit that never reached main. + ref: ${{ steps.target.outputs.ref }} steps: - name: Ensure release tag context + id: target env: EVENT_NAME: ${{ github.event_name }} INPUT_TAG: ${{ inputs.tag }} + GH_TOKEN: ${{ github.token }} run: | if [ -z "$RELEASE_TAG" ]; then echo "::error::RELEASE_TAG is empty. Ensure this workflow runs on a release event or refs/tags/* ref." @@ -39,7 +47,30 @@ jobs: fi fi - echo "Publishing tag $RELEASE_TAG" + if [ -n "$INPUT_TAG" ]; then + if [[ ! "$INPUT_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then + echo "::error::tag input must be a release tag like v1.2.3, got '$INPUT_TAG'" + exit 1 + fi + tag_ref="refs/tags/$INPUT_TAG" + else + tag_ref="$GITHUB_REF" + fi + + # Pin the build to the tag's commit, so moving the tag mid-run has + # no effect, and require that commit to be on main. + if ! sha=$(gh api "repos/$GITHUB_REPOSITORY/commits/$tag_ref" --jq .sha); then + echo "::error::tag ${tag_ref#refs/tags/} does not exist" + exit 1 + fi + status=$(gh api "repos/$GITHUB_REPOSITORY/compare/$sha...main" --jq .status) + if [ "$status" != "ahead" ] && [ "$status" != "identical" ]; then + echo "::error::${tag_ref#refs/tags/} points at $sha, which is not on main" + exit 1 + fi + echo "ref=$sha" >> "$GITHUB_OUTPUT" + + echo "Publishing tag $RELEASE_TAG from $sha (${tag_ref#refs/tags/})" desktop-builds: name: Build and Release Desktop Apps @@ -49,7 +80,7 @@ jobs: id-token: write # GCP workload identity for Windows code signing uses: ./.github/workflows/_desktop-release.yml with: - ref: ${{ inputs.tag || github.ref }} + ref: ${{ needs.preflight.outputs.ref }} release_tag: ${{ inputs.tag || github.event.release.tag_name || github.ref_name }} secrets: inherit # zizmor: ignore[secrets-inherit] -- reusable workflow needs platform signing secrets @@ -62,7 +93,7 @@ jobs: packages: write # Push to GHCR uses: ./.github/workflows/_docker-release.yml with: - ref: ${{ inputs.tag || github.ref }} + ref: ${{ needs.preflight.outputs.ref }} version: ${{ inputs.tag || github.event.release.tag_name || github.ref_name }} is_latest: true @@ -76,7 +107,7 @@ jobs: - name: Checkout code uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 with: - ref: ${{ inputs.tag || github.ref }} + ref: ${{ needs.preflight.outputs.ref }} fetch-depth: 0 # Required for git describe to find tags persist-credentials: false