-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(release): fail release pipelines before npm publish if git push is unavailable #36564
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
Draft
Martin Hochel (Hotell)
wants to merge
3
commits into
microsoft:master
Choose a base branch
from
Hotell:feat/release-git-push-preflight
base: master
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.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,33 @@ | ||
| # Flags a release that published to npm but deliberately skipped the git push. | ||
| # | ||
| # Only fires when the git push preflight failed and the release was forced. In that case packages | ||
| # are live on npm while the repo still has the old versions, so someone must run the recovery. | ||
| # | ||
| # Include immediately AFTER the beachball publish step. | ||
|
|
||
| parameters: | ||
| - name: dryRun | ||
| type: boolean | ||
| default: false | ||
|
|
||
| steps: | ||
| - ${{ if eq(parameters.dryRun, false) }}: | ||
| - script: | | ||
| echo "##vso[task.logissue type=warning]Packages were published to npm but NOT pushed to git." | ||
| echo "##vso[task.logissue type=warning]Run the 'release-recovery' skill against this pipeline run to resync the repo." | ||
| echo "" | ||
| echo "The repository is now out of sync with npm." | ||
| echo "" | ||
| echo "To recover, from a clean fluentui checkout run:" | ||
| echo " /release-recovery $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)" | ||
| echo "" | ||
| echo "Then fix the underlying cause - usually rotating the GitHub PAT in the" | ||
| echo "'Github and NPM secrets' variable group - or the next release will fail the same way." | ||
| echo "" | ||
|
|
||
| # Green-with-warning: the npm release genuinely succeeded, so a red run would be | ||
| # misleading and would train people to ignore failed release runs. But plain green would | ||
| # let the outstanding manual recovery slip by unnoticed. | ||
| echo "##vso[task.complete result=SucceededWithIssues;]Published to npm; git push skipped - recovery required" | ||
| displayName: 'Flag forced release for recovery' | ||
| condition: and(succeeded(), ne(variables['gitPushAvailable'], 'true')) | ||
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,90 @@ | ||
| # Guards a release against publishing to npm with a git token that cannot push. | ||
| # | ||
| # Background: `beachball publish` publishes to npm BEFORE it commits/tags/pushes. npm publishes are | ||
| # irreversible, so an invalid git token leaves npm and the repo permanently out of sync (this | ||
| # happened on 2026-06-30 when an enterprise policy started rejecting classic PATs with a lifetime | ||
| # > 8 days: all 18 v8 packages published, then every push retry failed with 403). | ||
| # | ||
| # Usage: include this template BEFORE the beachball publish step, and add $(beachballPushArgs) to | ||
| # the publish command. | ||
| # | ||
| # - template: .devops/templates/release-git-preflight.yml@self | ||
| # parameters: | ||
| # branch: master | ||
| # dryRun: ${{ parameters.dryRun }} | ||
| # forceReleaseWithoutGitPush: ${{ parameters.forceReleaseWithoutGitPush }} | ||
| # | ||
| # - script: | | ||
| # yarn beachball publish $(beachballPushArgs) --config ... --message '...' | ||
| # env: | ||
| # GITHUB_PAT: $(githubPAT) | ||
| # NPM_TOKEN: $(npmToken) | ||
|
|
||
| parameters: | ||
| # Branch the release pushes bumps/changelogs/tags to. | ||
| - name: branch | ||
| type: string | ||
| default: master | ||
|
|
||
| # Git remote the release pushes to. | ||
| - name: remote | ||
| type: string | ||
| default: origin | ||
|
|
||
| # Emergency escape hatch. When true, a failed preflight no longer blocks the release: packages are | ||
| # still published to npm, but with `--no-push`, and a recovery bundle is produced instead. | ||
| # This is a permission to proceed, NOT a mandate to skip - a healthy token still does a full release. | ||
| - name: forceReleaseWithoutGitPush | ||
| type: boolean | ||
| default: false | ||
|
|
||
| # Dry runs never publish or push, so the preflight is skipped. | ||
| - name: dryRun | ||
| type: boolean | ||
| default: false | ||
|
|
||
| steps: | ||
| # Always define the variable so `$(beachballPushArgs)` is never left as an unexpanded macro, | ||
| # even on code paths where the preflight itself is skipped. | ||
| - script: | | ||
| echo "##vso[task.setvariable variable=beachballPushArgs;]" | ||
| displayName: 'Preflight: initialize push mode' | ||
|
|
||
| - ${{ if eq(parameters.dryRun, false) }}: | ||
| - script: | | ||
| set -euo pipefail | ||
|
|
||
| # ADO renders boolean parameters as "True"/"False"; normalize before comparing. | ||
| force=$(echo "$FORCE_RELEASE_WITHOUT_GIT_PUSH" | tr '[:upper:]' '[:lower:]') | ||
|
|
||
| allowFailure="" | ||
| if [ "$force" = "true" ]; then | ||
| allowFailure="--allow-failure" | ||
| echo "Force mode enabled: a failed preflight will not block the release." | ||
| fi | ||
|
|
||
| node -r ./scripts/ts-node/src/register ./scripts/executors/src/check-git-push-access.ts \ | ||
| --remote "${{ parameters.remote }}" \ | ||
| --branch "${{ parameters.branch }}" \ | ||
| $allowFailure | ||
| env: | ||
| GITHUB_PAT: $(githubPAT) | ||
| FORCE_RELEASE_WITHOUT_GIT_PUSH: ${{ parameters.forceReleaseWithoutGitPush }} | ||
| displayName: 'Preflight: verify git push access' | ||
|
|
||
| # Translate the preflight result into the beachball flags used by the publish step. | ||
| # | ||
| # `--no-push` makes beachball publish to npm but skip commit/tag/push. Note it also skips the | ||
| # `precommit` hook and tagging, which is why force mode reproduces those separately when | ||
| # building the recovery bundle. | ||
| - script: | | ||
| set -euo pipefail | ||
|
|
||
| if [ "$(gitPushAvailable)" = "true" ]; then | ||
| echo "Git push available - performing a normal release." | ||
| echo "##vso[task.setvariable variable=beachballPushArgs;]" | ||
| else | ||
| echo "Git push NOT available - publishing to npm only (--no-push)." | ||
| echo "##vso[task.setvariable variable=beachballPushArgs;]--no-push" | ||
| fi | ||
| displayName: 'Preflight: select beachball push mode' |
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
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
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
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.
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.