|
| 1 | +name: "publish patch release - npm" |
| 2 | + |
| 3 | +# A patch release has two steps: |
| 4 | +# 1. Run this workflow with a release branch. It sets the next patch version on the branch, creates |
| 5 | +# a draft GitHub release and publishes the packages to npm under "latest-pending". |
| 6 | +# 2. Wait until `utils/check_npm_packages.sh <version>` passes. Then edit the notes of the draft |
| 7 | +# release and publish it. That starts this workflow again, to move "latest" to the new version. |
| 8 | +# |
| 9 | +# Step 2 runs the workflow file of the released commit, so the release branch must have this file. |
| 10 | +# The packages on npm must list publish_manual.yml as a trusted publisher that can run |
| 11 | +# "npm publish" and "npm dist-tag". |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + branch: |
| 17 | + description: "Release branch, for example release-1.65" |
| 18 | + required: true |
| 19 | + type: string |
| 20 | + release: |
| 21 | + types: [published] |
| 22 | + |
| 23 | +jobs: |
| 24 | + prepare-release: |
| 25 | + name: "set version, draft release" |
| 26 | + runs-on: ubuntu-24.04 |
| 27 | + if: github.event_name == 'workflow_dispatch' && github.repository == 'microsoft/playwright' |
| 28 | + permissions: |
| 29 | + contents: write # This is required to push the version commit and to create the draft release |
| 30 | + issues: read # This is required to list the fixed issues in the release notes |
| 31 | + pull-requests: read # This is required to list the fixed issues in the release notes |
| 32 | + outputs: |
| 33 | + sha: ${{ steps.commit.outputs.sha }} |
| 34 | + env: |
| 35 | + BRANCH: ${{ inputs.branch }} |
| 36 | + steps: |
| 37 | + - name: Check the branch name |
| 38 | + run: | |
| 39 | + if [[ ! "$BRANCH" =~ ^release-[0-9]+\.[0-9]+$ ]]; then |
| 40 | + echo "ERROR: '$BRANCH' is not a release branch, expected a name like release-1.65" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 44 | + with: |
| 45 | + ref: ${{ inputs.branch }} |
| 46 | + # The release notes need the commits since the previous release tag. |
| 47 | + fetch-depth: 0 |
| 48 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 49 | + with: |
| 50 | + node-version: lts/* |
| 51 | + - run: npm ci |
| 52 | + - run: npm run build |
| 53 | + - run: npx playwright install --with-deps |
| 54 | + - name: Set the next patch version |
| 55 | + id: version |
| 56 | + run: | |
| 57 | + PREVIOUS=$(node utils/workspace.js --get-version) |
| 58 | + if [[ ! "$PREVIOUS" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then |
| 59 | + echo "ERROR: the version of $BRANCH is $PREVIOUS, expected a released version like 1.65.1" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + if ! git rev-parse --quiet --verify "refs/tags/v$PREVIOUS" > /dev/null; then |
| 63 | + echo "ERROR: there is no v$PREVIOUS tag, so $PREVIOUS is not released yet" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((BASH_REMATCH[3] + 1))" |
| 67 | + ./utils/workspace.js --set-version "$VERSION" |
| 68 | + npm run doc |
| 69 | + echo "previous=$PREVIOUS" >> "$GITHUB_OUTPUT" |
| 70 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 71 | + - name: Write the release notes |
| 72 | + run: | |
| 73 | + node utils/draft_patch_release_notes.js "v$PREVIOUS" > "$RUNNER_TEMP/release-notes.md" |
| 74 | + cat "$RUNNER_TEMP/release-notes.md" |
| 75 | + env: |
| 76 | + PREVIOUS: ${{ steps.version.outputs.previous }} |
| 77 | + GH_TOKEN: ${{ github.token }} |
| 78 | + # The draft comes before the commit, so that it exists even when the commit fails. It targets the |
| 79 | + # branch: GitHub creates the tag from the head of the branch when the release is published. |
| 80 | + # The workflow token makes github-actions[bot] the author of the release. The promote-npm job |
| 81 | + # below and the publish-npm job of publish_release.yml use the author to recognize this release. |
| 82 | + - name: Create the draft release |
| 83 | + run: | |
| 84 | + if gh release view "v$VERSION" > /dev/null 2>&1; then |
| 85 | + # An earlier run created the draft and failed after that. |
| 86 | + gh release edit "v$VERSION" --draft --target "$BRANCH" --notes-file "$RUNNER_TEMP/release-notes.md" |
| 87 | + else |
| 88 | + gh release create "v$VERSION" --draft --title "v$VERSION" --target "$BRANCH" --notes-file "$RUNNER_TEMP/release-notes.md" |
| 89 | + fi |
| 90 | + env: |
| 91 | + VERSION: ${{ steps.version.outputs.version }} |
| 92 | + GH_TOKEN: ${{ github.token }} |
| 93 | + # A push with the workflow token does not start other workflows, so publish_release.yml does not |
| 94 | + # publish a beta version for this commit. |
| 95 | + - name: Commit the version |
| 96 | + id: commit |
| 97 | + run: | |
| 98 | + git config user.name "microsoft-playwright-automation[bot]" |
| 99 | + git config user.email "203992400+microsoft-playwright-automation[bot]@users.noreply.github.com" |
| 100 | + git commit --all --message "chore: mark v$VERSION" |
| 101 | + git push origin "HEAD:refs/heads/$BRANCH" |
| 102 | + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
| 103 | + env: |
| 104 | + VERSION: ${{ steps.version.outputs.version }} |
| 105 | + |
| 106 | + # Publishes every package under "latest-pending" and leaves "latest" where it is, see |
| 107 | + # utils/publish_all_packages.sh. The promote-npm job moves "latest" when the release is published. |
| 108 | + publish-npm: |
| 109 | + name: "publish NPM" |
| 110 | + needs: prepare-release |
| 111 | + runs-on: ubuntu-24.04 |
| 112 | + permissions: |
| 113 | + id-token: write # This is required for OIDC login (NPM publish) to succeed |
| 114 | + contents: read # This is required for actions/checkout to succeed |
| 115 | + steps: |
| 116 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 117 | + with: |
| 118 | + ref: ${{ needs.prepare-release.outputs.sha }} |
| 119 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 120 | + with: |
| 121 | + node-version: lts/* |
| 122 | + registry-url: 'https://registry.npmjs.org' |
| 123 | + - run: npm ci |
| 124 | + - run: npm run build |
| 125 | + - run: utils/publish_all_packages.sh --release |
| 126 | + |
| 127 | + # Runs when a person publishes the draft release that prepare-release created. To retry, re-run the job. |
| 128 | + promote-npm: |
| 129 | + name: "move the npm dist-tag" |
| 130 | + if: github.event_name == 'release' && github.event.release.author.login == 'github-actions[bot]' && github.repository == 'microsoft/playwright' |
| 131 | + runs-on: ubuntu-24.04 |
| 132 | + timeout-minutes: 330 |
| 133 | + permissions: |
| 134 | + id-token: write # This is required for OIDC login (npm dist-tag) to succeed |
| 135 | + contents: read # This is required for actions/checkout to succeed |
| 136 | + steps: |
| 137 | + # Checks out the commit of the release tag. |
| 138 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 139 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 140 | + with: |
| 141 | + node-version: lts/* |
| 142 | + registry-url: 'https://registry.npmjs.org' |
| 143 | + # npm dist-tag supports OIDC login from npm 11.21.0. |
| 144 | + - run: npm install -g npm@11.21.1 |
| 145 | + # Fails when npm has not made all packages live yet. Re-run the job later in that case. |
| 146 | + - name: Check that all packages are live |
| 147 | + run: utils/check_npm_packages.sh "${TAG#v}" |
| 148 | + env: |
| 149 | + TAG: ${{ github.event.release.tag_name }} |
| 150 | + # The same list that utils/publish_all_packages.sh writes after it publishes the packages. |
| 151 | + - name: List the published packages |
| 152 | + run: | |
| 153 | + node -e ' |
| 154 | + const { workspace } = require("./utils/workspace.js"); |
| 155 | + const { version } = require("./package.json"); |
| 156 | + if (`v${version}` !== process.env.TAG) |
| 157 | + throw new Error(`The release tag is ${process.env.TAG}, but the version of its commit is ${version}`); |
| 158 | + const packages = workspace.publicPackagesInDependencyOrder().map(pkg => pkg.packageJSON.name); |
| 159 | + console.log(JSON.stringify({ version, tag: "latest", packages }, null, 2)); |
| 160 | + ' > npm-publish.json |
| 161 | + cat npm-publish.json |
| 162 | + env: |
| 163 | + TAG: ${{ github.event.release.tag_name }} |
| 164 | + - name: Move the dist-tag once all packages are live |
| 165 | + run: node utils/promote_npm_packages.js npm-publish.json |
0 commit comments