diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..a4756347 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,83 @@ +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 + release_notes: + description: GitHub release notes (markdown). The release is created only for the latest dist-tag + required: false + 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: | + 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="^$num\\.$num\\.$num\$" + else + pattern="^$num\\.$num\\.$num-$id(\\.$id)*\$" + 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" + + - 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"