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
47 changes: 3 additions & 44 deletions common/config/azure-pipelines/npm-post-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,52 +117,11 @@ extends:
--verbose
DisplayName: 'Rush Build (repo-toolbox)'

# Use the versions recorded during publishing to avoid propagation latency in the package feeds.
- bash: |
set -e

triggering_alias="$(resources.triggeringAlias)"
rushstack_pipeline_id="$(resources.pipeline.esrpPublishRushstack.pipelineID)"
rushstack_run_id="$(resources.pipeline.esrpPublishRushstack.runID)"
rush_pipeline_id="$(resources.pipeline.esrpPublishRush.pipelineID)"
rush_run_id="$(resources.pipeline.esrpPublishRush.runID)"

if [[ "$triggering_alias" == "esrpPublishRushstack" ]]; then
pipeline_id="$rushstack_pipeline_id"
run_id="$rushstack_run_id"
elif [[ "$triggering_alias" == "esrpPublishRush" ]]; then
pipeline_id="$rush_pipeline_id"
run_id="$rush_run_id"
# If this pipeline was not resource-triggered, use whichever publishing pipeline ran latest.
elif (( rushstack_run_id > rush_run_id )); then
pipeline_id="$rushstack_pipeline_id"
run_id="$rushstack_run_id"
else
pipeline_id="$rush_pipeline_id"
run_id="$rush_run_id"
fi

echo "Using publishing pipeline $pipeline_id, run $run_id (trigger: ${triggering_alias:-manual})"
echo "##vso[task.setvariable variable=PublishingPipelineId]$pipeline_id"
echo "##vso[task.setvariable variable=PublishingRunId]$run_id"
displayName: 'Select publishing pipeline run'

- task: DownloadPipelineArtifact@2
displayName: 'Download published package versions'
inputs:
source: specific
project: GitHubProjectsPublish
pipeline: $(PublishingPipelineId)
runVersion: specific
runId: $(PublishingRunId)
artifact: published-versions
path: $(Pipeline.Workspace)/published-versions

# Resource-triggered runs check out the publishing pipeline's commit, so local package
# versions match the versions that were just published without waiting for feed propagation.
- template: /common/config/azure-pipelines/templates/run-repo-toolbox.yaml@self
parameters:
Arguments: >
bump-decoupled-local-dependencies
--published-versions-path "$(Pipeline.Workspace)/published-versions/published-versions.json"
Arguments: 'bump-decoupled-local-dependencies'
DisplayName: 'Bump decoupled local dependencies'

# If Rush itself was updated by bump-decoupled-local-dependencies, we need to bootstrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,40 @@ import type { ChildProcess } from 'node:child_process';

import { Async, Executable, FileSystem, type FolderItem, JsonFile } from '@rushstack/node-core-library';
import type { ITerminal } from '@rushstack/terminal';
import { DependencyType, PackageJsonEditor, RushConfiguration, type Subspace } from '@microsoft/rush-lib';
import {
DependencyType,
PackageJsonEditor,
RushConfiguration,
type RushConfigurationProject,
type Subspace
} from '@microsoft/rush-lib';
import type { IRushConfigurationJson } from '@microsoft/rush-lib/lib/api/RushConfiguration';
import { CommandLineAction, type CommandLineStringParameter } from '@rushstack/ts-command-line';

function _getLocalPublishedVersions(projects: Iterable<RushConfigurationProject>): Record<string, string> {
const localPublishedVersions: Record<string, string> = {};
for (const {
shouldPublish,
packageName,
packageJson: { version }
} of projects) {
if (shouldPublish) {
localPublishedVersions[packageName] = version;
}
}

return localPublishedVersions;
}

async function _getLatestPublishedVersionAsync(
terminal: ITerminal,
packageName: string,
publishedVersions: Record<string, string> | undefined,
publishedVersions: Record<string, string>,
feedUrl: string | undefined
): Promise<string> {
const recordedVersion: string | undefined = publishedVersions?.[packageName];
const recordedVersion: string | undefined = publishedVersions[packageName];
if (recordedVersion) {
terminal.writeLine(`Found version "${recordedVersion}" for "${packageName}" in published versions file`);
terminal.writeLine(`Found version "${recordedVersion}" for "${packageName}"`);
return recordedVersion;
}

Expand Down Expand Up @@ -86,13 +107,18 @@ export class BumpDecoupledLocalDependencies extends CommandLineAction {
const terminal: ITerminal = this.#terminal;
const feedUrl: string | undefined = this.#feedUrlParameter.value;
const publishedVersionsPath: string | undefined = this.#publishedVersionsPathParameter.value;
const publishedVersions: Record<string, string> | undefined = publishedVersionsPath
? await JsonFile.loadAsync(path.resolve(publishedVersionsPath))
: undefined;
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromDefaultLocation({
startingFolder: process.cwd()
});
const { projects, rushJsonFile, commonAutoinstallersFolder } = rushConfiguration;
const localPublishedVersions: Record<string, string> = _getLocalPublishedVersions(projects);
const publishedVersionsOverride: Record<string, string> | undefined = publishedVersionsPath
? await JsonFile.loadAsync(path.resolve(publishedVersionsPath))
: undefined;
const publishedVersions: Record<string, string> = {
...localPublishedVersions,
...publishedVersionsOverride
};

const projectsToUpdate: IProjectLike[] = [];

Expand Down