Skip to content

Commit c973356

Browse files
authored
devops: move npm publishing to ESRP pipeline (#42171)
1 parent c873099 commit c973356

2 files changed

Lines changed: 58 additions & 45 deletions

File tree

.azure-pipelines/publish.yml

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
# Publishes @next (alpha) versions of all npm packages via ESRP. Manual trigger only.
2-
trigger: none
1+
# Publishes all npm packages via ESRP:
2+
# - @next (alpha with today's date) from main, daily on schedule
3+
# - @next (alpha with commit timestamp) from main, on manual trigger
4+
# - @beta (beta with commit timestamp) from release-* branches, on push
5+
# - @latest from v* release tags (pushed when a GitHub release is published)
6+
trigger:
7+
branches:
8+
include:
9+
- release-*
10+
tags:
11+
include:
12+
- v*
313

414
pr: none
515

16+
schedules:
17+
- cron: '10 5 * * *'
18+
displayName: "Daily @next publish"
19+
branches:
20+
include:
21+
- main
22+
always: true
23+
624
resources:
725
repositories:
826
- repository: 1esPipelines
@@ -36,12 +54,12 @@ extends:
3654
displayName: "Checkout code"
3755

3856
- task: Bash@3
39-
displayName: "Check the branch is main"
57+
displayName: "Check the branch is main, release-* or a v* tag"
4058
inputs:
4159
targetType: "inline"
4260
script: |
43-
if [[ "$BUILD_SOURCE_BRANCH" != "refs/heads/main" ]]; then
44-
echo "Alpha versions can only be published from main."
61+
if [[ "$BUILD_SOURCE_BRANCH" != "refs/heads/main" && "$BUILD_SOURCE_BRANCH" != refs/heads/release-* && "$BUILD_SOURCE_BRANCH" != refs/tags/v* ]]; then
62+
echo "Can only publish from main, release-* branches or v* tags."
4563
echo "Unexpected branch: $BUILD_SOURCE_BRANCH"
4664
exit 1
4765
fi
@@ -78,18 +96,44 @@ extends:
7896
displayName: "npm run build"
7997

8098
- task: Bash@3
81-
displayName: "Set alpha version with commit timestamp"
99+
name: setVersion
100+
displayName: "Set version and dist-tag"
82101
inputs:
83102
targetType: "inline"
84103
script: |
85104
set -e
86-
node utils/build/update_canary_version.js --alpha --commit-timestamp
105+
if [[ "$BUILD_SOURCE_BRANCH" == refs/tags/v* ]]; then
106+
# Release version is already checked in, only publish what the tag points at.
107+
NPM_DIST_TAG="latest"
108+
elif [[ "$BUILD_SOURCE_BRANCH" == refs/heads/release-* ]]; then
109+
NPM_DIST_TAG="beta"
110+
node utils/build/update_canary_version.js --beta --commit-timestamp
111+
elif [[ "$BUILD_REASON" == "Schedule" ]]; then
112+
NPM_DIST_TAG="next"
113+
node utils/build/update_canary_version.js --alpha --today-date
114+
else
115+
NPM_DIST_TAG="next"
116+
node utils/build/update_canary_version.js --alpha --commit-timestamp
117+
fi
87118
node utils/workspace.js --ensure-consistent
88119
VERSION=$(node utils/workspace.js --get-version)
89-
if [[ "$VERSION" != *-alpha-* ]]; then
120+
if [[ "$NPM_DIST_TAG" == "latest" && "$BUILD_SOURCE_BRANCH" != "refs/tags/v$VERSION" ]]; then
121+
echo "ERROR: version '$VERSION' does not match tag '$BUILD_SOURCE_BRANCH'"
122+
exit 1
123+
fi
124+
if [[ "$NPM_DIST_TAG" == "beta" && "$VERSION" != *-beta-* ]]; then
125+
echo "ERROR: unexpected version '$VERSION', must be a beta version"
126+
exit 1
127+
fi
128+
if [[ "$NPM_DIST_TAG" == "next" && "$VERSION" != *-alpha-* ]]; then
90129
echo "ERROR: unexpected version '$VERSION', must be an alpha version"
91130
exit 1
92131
fi
132+
echo "Publishing version $VERSION with dist-tag $NPM_DIST_TAG"
133+
echo "##vso[task.setvariable variable=npmDistTag;isOutput=true]$NPM_DIST_TAG"
134+
env:
135+
BUILD_SOURCE_BRANCH: $(Build.SourceBranch)
136+
BUILD_REASON: $(Build.Reason)
93137

94138
- task: Bash@3
95139
displayName: "Pack all packages"
@@ -106,6 +150,8 @@ extends:
106150
- job: Publish
107151
displayName: "ESRP Release to npm"
108152
dependsOn: Build
153+
variables:
154+
npmDistTag: $[ dependencies.Build.outputs['setVersion.npmDistTag'] ]
109155
templateContext:
110156
type: releaseJob
111157
isProduction: true
@@ -125,7 +171,7 @@ extends:
125171
intent: 'PackageDistribution'
126172
contenttype: 'npm'
127173
# npm dist-tag to publish with.
128-
productstate: 'next'
174+
productstate: '$(npmDistTag)'
129175
folderlocation: '$(Build.ArtifactStagingDirectory)/esrp-build'
130176
waitforreleasecompletion: true
131177
owners: 'yurys@microsoft.com'

.github/workflows/publish_release.yml

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
name: "publish release - npm, trace viewer"
1+
# npm publishing (@next, @beta and @latest) is done by the ESRP pipeline,
2+
# see .azure-pipelines/publish.yml
3+
name: "publish release - trace viewer"
24

35
on:
46
workflow_dispatch:
@@ -11,41 +13,6 @@ on:
1113
types: [published]
1214

1315
jobs:
14-
publish-npm:
15-
name: "publish NPM"
16-
runs-on: ubuntu-24.04
17-
if: github.repository == 'microsoft/playwright'
18-
permissions:
19-
id-token: write # This is required for OIDC login (NPM publish) to succeed
20-
contents: read # This is required for actions/checkout to succeed
21-
steps:
22-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23-
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
24-
with:
25-
node-version: lts/*
26-
registry-url: 'https://registry.npmjs.org'
27-
- run: npm ci
28-
- run: npm run build
29-
30-
- name: "@next: publish with commit timestamp (triggered manually)"
31-
if: contains(github.ref, 'main') && github.event_name == 'workflow_dispatch'
32-
run: |
33-
node utils/build/update_canary_version.js --alpha --commit-timestamp
34-
utils/publish_all_packages.sh --alpha
35-
- name: "@next: publish with today's date (triggered automatically)"
36-
if: contains(github.ref, 'main') && github.event.schedule
37-
run: |
38-
node utils/build/update_canary_version.js --alpha --today-date
39-
utils/publish_all_packages.sh --alpha
40-
- name: "@beta: publish with commit timestamp (triggered automatically)"
41-
if: contains(github.ref, 'release') && github.event_name == 'push'
42-
run: |
43-
node utils/build/update_canary_version.js --beta --commit-timestamp
44-
utils/publish_all_packages.sh --beta
45-
- name: "publish release to NPM"
46-
if: github.event_name == 'release' && github.event.action == 'published'
47-
run: utils/publish_all_packages.sh --release
48-
4916
publish-trace-viewer:
5017
name: "publish Trace Viewer to trace.playwright.dev"
5118
runs-on: ubuntu-24.04

0 commit comments

Comments
 (0)