From 020db020bd4aef87e5440d9967762943fb260b4e Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Thu, 26 Nov 2026 19:58:17 +0530 Subject: [PATCH 1/2] Publish to npm via trusted publishing Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yml | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..38a80a1c --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,70 @@ +name: Cypress CLI Publish + +on: + workflow_dispatch: + inputs: + version: + description: Version to publish, e.g. 1.38.1 (1.38.1-tp.0 for a non-latest dist-tag) + required: true + type: string + npm_tag: + description: npm dist-tag + required: true + default: latest + type: string + +permissions: + contents: read + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + env: + VERSION: ${{ inputs.version }} + NPM_TAG: ${{ inputs.npm_tag }} + steps: + - name: Validate inputs + run: | + if [ "$NPM_TAG" = latest ]; then + pattern='^[0-9]+\.[0-9]+\.[0-9]+$' + else + pattern='^[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.-]+$' + fi + if ! [[ "$VERSION" =~ $pattern ]]; then + echo "::error::version '$VERSION' does not match $pattern for dist-tag '$NPM_TAG'" + exit 1 + fi + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + + # No registry-url: setup-node would write an .npmrc token line that shadows OIDC. + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version: 24 + + - run: npm install -g npm@11.21.0 + + - name: Upgrade version + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + npm version "$VERSION" + + - name: Publish + run: npm publish --access public --tag "$NPM_TAG" + + - name: Push tag + if: inputs.npm_tag != 'latest' + run: git push origin "v$VERSION" + + - name: Push tag and version bump branch + if: inputs.npm_tag == 'latest' + run: | + branch="release-$(date +%s)" + git push --follow-tags origin "HEAD:refs/heads/$branch" + echo "Open the version bump PR: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/$GITHUB_REF_NAME...$branch?expand=1" | tee -a "$GITHUB_STEP_SUMMARY" From 64f793d70fa89dc989085ada753b04d9ebdf6feb Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Thu, 26 Nov 2026 20:32:12 +0530 Subject: [PATCH 2/2] Reject non-canonical versions; create the GitHub release in the workflow Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 38a80a1c..a4756347 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,6 +12,10 @@ on: required: true default: latest type: string + release_notes: + description: GitHub release notes (markdown). The release is created only for the latest dist-tag + required: false + type: string permissions: contents: read @@ -28,10 +32,12 @@ jobs: steps: - name: Validate inputs run: | + num='(0|[1-9][0-9]*)' + id='(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)' if [ "$NPM_TAG" = latest ]; then - pattern='^[0-9]+\.[0-9]+\.[0-9]+$' + pattern="^$num\\.$num\\.$num\$" else - pattern='^[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.-]+$' + pattern="^$num\\.$num\\.$num-$id(\\.$id)*\$" fi if ! [[ "$VERSION" =~ $pattern ]]; then echo "::error::version '$VERSION' does not match $pattern for dist-tag '$NPM_TAG'" @@ -68,3 +74,10 @@ jobs: branch="release-$(date +%s)" git push --follow-tags origin "HEAD:refs/heads/$branch" echo "Open the version bump PR: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/$GITHUB_REF_NAME...$branch?expand=1" | tee -a "$GITHUB_STEP_SUMMARY" + + - name: Create GitHub release + if: inputs.npm_tag == 'latest' && inputs.release_notes != '' + env: + GH_TOKEN: ${{ github.token }} + RELEASE_NOTES: ${{ inputs.release_notes }} + run: gh release create "v$VERSION" --verify-tag --title "Public Beta v$VERSION" --notes "$RELEASE_NOTES"