-
Notifications
You must be signed in to change notification settings - Fork 452
ci(repo): guard release workflow against stale-SHA runs #8591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jacekradko
wants to merge
4
commits into
main
Choose a base branch
from
jacek/guard-release-stale-sha
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−83
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f6bfe2b
ci(repo): guard release workflow against stale-SHA runs
jacekradko 60c6a23
ci(repo): extract release recovery to reusable workflow
jacekradko bb8ad8d
ci(repo): pin recovery checkout to main, fix stale comment
jacekradko c9ccf72
ci(repo): cancel stale release run instead of failing it
jacekradko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| name: Release Recovery (manual) | ||
|
|
||
| # Recovery handle for downstream notifications. Use when a release | ||
| # run published to npm but failed to dispatch one or more downstream | ||
| # workflows (sdk-infra-workers, dashboard, clerk-docs). Reads versions | ||
| # from main's package.json, verifies what is actually on npm, then | ||
| # re-dispatches the same workflows that the production release job | ||
| # would have dispatched. | ||
| # | ||
| # Invoked two ways: | ||
| # - Automatically as a dependent job from release.yml when the | ||
| # changesets step fails (workflow_call). | ||
| # - Manually via `gh workflow run release-recovery.yml -R clerk/javascript` | ||
| # or the Actions UI (workflow_dispatch). | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| workflow_call: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| recover: | ||
| name: Recover downstream notifications | ||
| if: ${{ github.repository == 'clerk/javascript' }} | ||
| runs-on: ${{ vars.RUNNER_NORMAL || 'ubuntu-latest' }} | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Always read versions from main, regardless of which ref a | ||
| # manual workflow_dispatch was triggered on. | ||
| ref: main | ||
| fetch-depth: 1 | ||
| show-progress: false | ||
|
|
||
| - name: Dispatch downstream workflows | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| result-encoding: string | ||
| retries: 3 | ||
| retry-exempt-status-codes: 400,401 | ||
| github-token: ${{ secrets.CLERK_COOKIE_PAT }} | ||
| script: | | ||
| const { execSync } = require('child_process'); | ||
|
|
||
| const clerkjsVersion = require('./packages/clerk-js/package.json').version; | ||
| const clerkUiVersion = require('./packages/ui/package.json').version; | ||
|
|
||
| // Only recover stable releases | ||
| const preReleases = [ | ||
| clerkjsVersion.includes('-') && `@clerk/clerk-js@${clerkjsVersion}`, | ||
| clerkUiVersion.includes('-') && `@clerk/ui@${clerkUiVersion}`, | ||
| ].filter(Boolean); | ||
| if (preReleases.length > 0) { | ||
| console.log(`Skipping recovery: ${preReleases.join(', ')} is a pre-release`); | ||
| return; | ||
| } | ||
|
|
||
| const preMode = require("fs").existsSync("./.changeset/pre.json"); | ||
| if (preMode) { | ||
| core.warning("Changeset in pre-mode, skipping recovery dispatch"); | ||
| return; | ||
| } | ||
|
|
||
| // Check if either version was actually published to npm | ||
| function isPublished(name, version) { | ||
| try { | ||
| return execSync(`npm view ${name}@${version} version`, { encoding: 'utf8' }).trim() === version; | ||
| } catch (e) { | ||
| console.log(`npm view ${name}@${version} failed: ${e.message}`); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| const clerkjsPublished = isPublished('@clerk/clerk-js', clerkjsVersion); | ||
| const clerkUiPublished = isPublished('@clerk/ui', clerkUiVersion); | ||
|
|
||
| if (!clerkjsPublished && !clerkUiPublished) { | ||
| console.log('Neither @clerk/clerk-js nor @clerk/ui were published to npm, no recovery needed'); | ||
| return; | ||
| } | ||
|
|
||
| const published = [ | ||
| clerkjsPublished && `@clerk/clerk-js@${clerkjsVersion}`, | ||
| clerkUiPublished && `@clerk/ui@${clerkUiVersion}`, | ||
| ].filter(Boolean).join(', '); | ||
| core.warning(`Recovery: ${published} published to npm but downstream repos were not notified. Dispatching now.`); | ||
|
|
||
| const nextjsVersion = require('./packages/nextjs/package.json').version; | ||
|
|
||
| // NOTE: Keep in sync with the `targets` array in release.yml's | ||
| // "Trigger workflows on related repos" and "Recover downstream | ||
| // notifications" steps. | ||
| const targets = [ | ||
| { repo: 'sdk-infra-workers', workflow_id: 'update-pkg-versions.yml', inputs: { clerkjsVersion, clerkUiVersion } }, | ||
| { repo: 'dashboard', workflow_id: 'prepare-nextjs-sdk-update.yml', inputs: { version: nextjsVersion } }, | ||
| { repo: 'clerk-docs', workflow_id: 'typedoc.yml' }, | ||
| ]; | ||
| const results = await Promise.allSettled( | ||
| targets.map(t => github.rest.actions.createWorkflowDispatch({ owner: 'clerk', ref: 'main', ...t })) | ||
| ); | ||
| const failures = results | ||
| .map((r, i) => r.status === 'rejected' ? { target: targets[i], reason: r.reason } : null) | ||
| .filter(Boolean); | ||
| if (failures.length) { | ||
| failures.forEach(f => core.error(`Recovery dispatch to ${f.target.repo}/${f.target.workflow_id} failed: ${f.reason?.message ?? f.reason}`)); | ||
| core.setFailed(`${failures.length} recovery dispatch(es) failed`); | ||
| } else { | ||
| core.notice('Recovery dispatch completed successfully'); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.