Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ copy the workflow below, name its CI's gate job in `checks`, and release its fir
workflow adds no token, deploy key or App for tagging.
6. **Holds workflow changes while it runs.** GitHub refuses a workflow's own token when it tags a commit whose workflow
files differ from the default branch's, so a workflow change that merges during a release leaves it published and
untagged. The `release-freeze` action prevents that with a commit status of the same name. The release's first job
runs it with `mode: start`, which fails that status on every open pull request that changes a workflow file; a
last job with `if: always()` runs `mode: end`, which passes it again however the release ended. CI runs it on every
pull request with `mode: pull-request`, so one opened or pushed mid-release is caught, and every pull request
carries the status. List `release-freeze` as a required status check on the default branch.
untagged. The `release-freeze` action prevents that with a commit status of the same name. A job right after
preflight runs it with `mode: start`, which fails that status on every open pull request that changes a workflow
file, and every publishing job needs that job: a release that could not set the freeze publishes nothing. A last
job with `if: always()` runs `mode: end`, which passes the status again however the release ended. A small workflow
of its own, on `pull_request_target`, runs `mode: pull-request` for every pull request, so one opened or pushed
mid-release is caught and every pull request carries the status. It is `pull_request_target` because a fork's or
Dependabot's `pull_request` run gets a read-only token and could not post a status; it checks out nothing, so it
never runs the pull request's code. List `release-freeze` as a required status check on the default branch.
7. **Publishes steps that can run again.** Re-running failed jobs, or dispatching the same version again from the same
commit, must not fail on what an earlier attempt already published.
8. **Tags last.** One final job, needing every publishing job, runs `release-tag` and then creates the GitHub release.
Expand Down Expand Up @@ -98,7 +101,7 @@ jobs:
sha: ${{ needs.preflight.outputs.sha }}

publish:
needs: [preflight, verify]
needs: [preflight, freeze, verify]
# A skipped verify is a pass; a failed one stops the release.
if: ${{ !failure() && !cancelled() }}
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -127,7 +130,7 @@ jobs:
$([[ "$PRERELEASE" == true ]] && echo --prerelease)
```

The release's last job, and CI's job for pull requests:
The release's last job:

```yaml
# In release.yml: after everything else, whatever happened.
Expand All @@ -139,10 +142,23 @@ The release's last job, and CI's job for pull requests:
steps:
- uses: MaudeCode/.github/actions/release-freeze@<full commit SHA>
with: { mode: end }
```

And `.github/workflows/release-freeze.yml`, for pull requests:

```yaml
name: Release freeze

# In ci.yml: on every pull request.
release-freeze:
if: github.event_name == 'pull_request'
# pull_request_target, so pull requests from forks and Dependabot get the status too. Safe because nothing is checked
# out: the action reads the pull request's file list through the API and never runs its code. Keep it that way.
on:
pull_request_target:
types: [opened, reopened, synchronize]

permissions: {}

jobs:
status:
runs-on: ubuntu-24.04
permissions: { statuses: write, pull-requests: read, actions: read }
steps:
Expand Down
2 changes: 1 addition & 1 deletion actions/release-freeze/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Keep pull requests that change a workflow file from merging while a
inputs:
mode:
description: >-
"pull-request" on a pull request's push sets that pull request's status. "start" as a release's first job
"pull-request" on a pull request's push (a pull_request_target workflow that checks out nothing) sets that pull request's status. "start" as a release's first job
freezes the open pull requests that change a workflow file. "end" as its last job, with if always(), thaws them.
required: true
workflow:
Expand Down
2 changes: 1 addition & 1 deletion actions/release-freeze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ run(async () => {
if (repository.status !== 200) throw new Error(`Reading the repository failed: HTTP ${repository.status}`);
const event = JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf8"));
const pull = event.pull_request && { number: event.pull_request.number, sha: event.pull_request.head.sha };
if (mode === "pull-request" && !pull) throw new Error('mode "pull-request" runs on a pull_request event.');
if (mode === "pull-request" && !pull) throw new Error('mode "pull-request" runs on a pull_request_target or pull_request event.');
const result = await freeze(api, { mode, workflow: env.INPUT_WORKFLOW, branch: repository.data.default_branch, runId: env.GITHUB_RUN_ID, pull });
appendFileSync(env.GITHUB_OUTPUT, `frozen=${JSON.stringify(result.frozen)}\nthawed=${JSON.stringify(result.thawed)}\n`);
console.log(`Frozen: ${result.frozen.join(", ") || "none"}. Thawed: ${result.thawed.join(", ") || "none"}.`);
Expand Down