Skip to content

Commit 0020d94

Browse files
iclantonclaude
andauthored
fix(post-publish): handle Rush version bump in npm-post-publish pipeline (#5725)
* Fix issues with updates to rushstack-websites. * fix(post-publish): handle Rush version bump in npm-post-publish pipeline If `bump-decoupled-local-dependencies` updates the Rush version in `rush.json`, the subsequent `rush update` step would fail because `install-run-rush.js` tried to install the new Rush version but the checked-in `rush-package-lock.json` still referenced the old version. Fix by emitting `RushWasUpdated` and `NewRushVersion` Azure Pipelines variables from `BumpDecoupledLocalDependencies`, then conditionally bootstrapping the new Rush version (skipping lockfile validation) and updating the checked-in lockfile before running `rush update` normally. Also only write `rush.json` when the Rush version actually changed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent beb0449 commit 0020d94

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

common/config/azure-pipelines/npm-post-publish.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ extends:
116116
Arguments: 'bump-decoupled-local-dependencies'
117117
DisplayName: 'Bump decoupled local dependencies'
118118

119+
# If Rush itself was updated by bump-decoupled-local-dependencies, we need to bootstrap
120+
# the new version and update the checked-in lockfile before running `rush update`.
121+
# Otherwise install-run-rush.js would fail lockfile validation when trying to install
122+
# the new version of Rush (the checked-in lockfile still references the old version).
123+
- template: /common/config/azure-pipelines/templates/install-run-rush.yaml@self
124+
parameters:
125+
Arguments: '--help'
126+
DisplayName: 'Install new Rush version (skip lockfile validation)'
127+
DisableInstallRunRushLockfile: true
128+
Condition: "eq(variables['RushWasUpdated'], 'true')"
129+
130+
- bash: >
131+
cp
132+
"common/temp/install-run/@microsoft+rush@$(NewRushVersion)/package-lock.json"
133+
common/config/validation/rush-package-lock.json
134+
displayName: 'Update rush-package-lock.json (new Rush version)'
135+
condition: eq(variables['RushWasUpdated'], 'true')
136+
119137
- template: /common/config/azure-pipelines/templates/install-run-rush.yaml@self
120138
parameters:
121139
Arguments: 'update'
@@ -126,9 +144,6 @@ extends:
126144
Arguments: 'update-autoinstaller --name plugins'
127145
DisplayName: 'Rush Update Autoinstaller (plugins)'
128146

129-
- bash: cp common/temp/install-run/@microsoft+rush@*/package-lock.json common/config/validation/rush-package-lock.json
130-
displayName: 'Update rush-package-lock.json'
131-
132147
- bash: |
133148
set -e
134149
@@ -188,6 +203,8 @@ extends:
188203
parameters:
189204
Arguments: 'install'
190205
DisplayName: 'Rush Install (rushstack-websites)'
206+
# rushstack-websites doesn't have an `install-run-rush` lockfile checked in
207+
DisableInstallRunRushLockfile: true
191208

192209
- template: /common/config/azure-pipelines/templates/install-run-rush.yaml@self
193210
parameters:
@@ -196,6 +213,8 @@ extends:
196213
--to-except api.rushstack.io
197214
--verbose
198215
DisplayName: 'Rush Build to-except api.rushstack.io (rushstack-websites)'
216+
# rushstack-websites doesn't have an `install-run-rush` lockfile checked in
217+
DisableInstallRunRushLockfile: true
199218

200219
# Download the api artifact from the triggering publish pipeline.
201220
# AzDO automatically resolves which pipeline resource triggered this run.

common/config/azure-pipelines/templates/install-run-rush.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ parameters:
1414
- name: RepoPath
1515
type: string
1616
default: '$(Build.SourcesDirectory)'
17+
- name: DisableInstallRunRushLockfile
18+
type: boolean
19+
default: false
1720

1821
steps:
1922
- script: 'node common/scripts/install-run-rush.js ${{ parameters.Arguments }}'
@@ -22,6 +25,7 @@ steps:
2225
${{ if ne(parameters.Condition, '') }}:
2326
condition: ${{ parameters.Condition }}
2427
env:
25-
INSTALL_RUN_RUSH_LOCKFILE_PATH: ${{ parameters.RepoPath }}/common/config/validation/rush-package-lock.json
28+
${{ if not(parameters.DisableInstallRunRushLockfile) }}:
29+
INSTALL_RUN_RUSH_LOCKFILE_PATH: ${{ parameters.RepoPath }}/common/config/validation/rush-package-lock.json
2630
${{ if ne(parameters.NpmAuthToken, '') }}:
2731
NPM_AUTH_TOKEN: ${{ parameters.NpmAuthToken }}

repo-scripts/repo-toolbox/src/cli/actions/BumpDecoupledLocalDependencies.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,19 @@ export class BumpDecoupledLocalDependencies extends CommandLineAction {
180180
// Update the Rush version in rush.json
181181
const latestRushVersion: string = await _getLatestPublishedVersionAsync(terminal, '@microsoft/rush');
182182
const rushJson: IRushConfigurationJson = await JsonFile.loadAsync(rushJsonFile);
183-
rushJson.rushVersion = latestRushVersion;
184-
await JsonFile.saveAsync(rushJson, rushJsonFile, { updateExistingFile: true });
185-
terminal.writeLine(`Updated ${rushJsonFile}`);
183+
const existingRushVersion: string = rushJson.rushVersion;
184+
const rushWasUpdated: boolean = existingRushVersion !== latestRushVersion;
185+
if (rushWasUpdated) {
186+
rushJson.rushVersion = latestRushVersion;
187+
await JsonFile.saveAsync(rushJson, rushJsonFile, { updateExistingFile: true });
188+
terminal.writeLine(
189+
`Updated ${rushJsonFile}: Rush version ${existingRushVersion} -> ${latestRushVersion}`
190+
);
191+
}
192+
193+
// Emit Azure Pipelines variables so subsequent pipeline steps can handle the Rush version change.
194+
// These are no-ops when run outside of Azure Pipelines.
195+
terminal.writeLine(`##vso[task.setvariable variable=NewRushVersion]${latestRushVersion}`);
196+
terminal.writeLine(`##vso[task.setvariable variable=RushWasUpdated]${rushWasUpdated}`);
186197
}
187198
}

0 commit comments

Comments
 (0)