|
| 1 | +name: Cypress CLI Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: Version to publish, e.g. 1.38.1 (1.38.1-tp.0 for a non-latest dist-tag) |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + npm_tag: |
| 11 | + description: npm dist-tag |
| 12 | + required: true |
| 13 | + default: latest |
| 14 | + type: string |
| 15 | + release_notes: |
| 16 | + description: GitHub release notes (markdown). The release is created only for the latest dist-tag |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + publish: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: write |
| 28 | + id-token: write |
| 29 | + env: |
| 30 | + VERSION: ${{ inputs.version }} |
| 31 | + NPM_TAG: ${{ inputs.npm_tag }} |
| 32 | + steps: |
| 33 | + - name: Validate inputs |
| 34 | + run: | |
| 35 | + num='(0|[1-9][0-9]*)' |
| 36 | + id='(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)' |
| 37 | + if [ "$NPM_TAG" = latest ]; then |
| 38 | + pattern="^$num\\.$num\\.$num\$" |
| 39 | + else |
| 40 | + pattern="^$num\\.$num\\.$num-$id(\\.$id)*\$" |
| 41 | + fi |
| 42 | + if ! [[ "$VERSION" =~ $pattern ]]; then |
| 43 | + echo "::error::version '$VERSION' does not match $pattern for dist-tag '$NPM_TAG'" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + # No registry-url: setup-node would write an .npmrc token line that shadows OIDC. |
| 52 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 53 | + with: |
| 54 | + node-version: 24 |
| 55 | + |
| 56 | + - run: npm install -g npm@11.21.0 |
| 57 | + |
| 58 | + - name: Upgrade version |
| 59 | + run: | |
| 60 | + git config user.name "github-actions[bot]" |
| 61 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 62 | + npm version "$VERSION" |
| 63 | +
|
| 64 | + - name: Publish |
| 65 | + run: npm publish --access public --tag "$NPM_TAG" |
| 66 | + |
| 67 | + - name: Push tag |
| 68 | + if: inputs.npm_tag != 'latest' |
| 69 | + run: git push origin "v$VERSION" |
| 70 | + |
| 71 | + - name: Push tag and version bump branch |
| 72 | + if: inputs.npm_tag == 'latest' |
| 73 | + run: | |
| 74 | + branch="release-$(date +%s)" |
| 75 | + git push --follow-tags origin "HEAD:refs/heads/$branch" |
| 76 | + echo "Open the version bump PR: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/$GITHUB_REF_NAME...$branch?expand=1" | tee -a "$GITHUB_STEP_SUMMARY" |
| 77 | +
|
| 78 | + - name: Create GitHub release |
| 79 | + if: inputs.npm_tag == 'latest' && inputs.release_notes != '' |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ github.token }} |
| 82 | + RELEASE_NOTES: ${{ inputs.release_notes }} |
| 83 | + run: gh release create "v$VERSION" --verify-tag --title "Public Beta v$VERSION" --notes "$RELEASE_NOTES" |
0 commit comments