Skip to content

Commit 020db02

Browse files
kamal-kaur04claude
andcommitted
Publish to npm via trusted publishing
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6f2d26a commit 020db02

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
publish:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
id-token: write
25+
env:
26+
VERSION: ${{ inputs.version }}
27+
NPM_TAG: ${{ inputs.npm_tag }}
28+
steps:
29+
- name: Validate inputs
30+
run: |
31+
if [ "$NPM_TAG" = latest ]; then
32+
pattern='^[0-9]+\.[0-9]+\.[0-9]+$'
33+
else
34+
pattern='^[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.-]+$'
35+
fi
36+
if ! [[ "$VERSION" =~ $pattern ]]; then
37+
echo "::error::version '$VERSION' does not match $pattern for dist-tag '$NPM_TAG'"
38+
exit 1
39+
fi
40+
41+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
42+
with:
43+
fetch-depth: 0
44+
45+
# No registry-url: setup-node would write an .npmrc token line that shadows OIDC.
46+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
47+
with:
48+
node-version: 24
49+
50+
- run: npm install -g npm@11.21.0
51+
52+
- name: Upgrade version
53+
run: |
54+
git config user.name "github-actions[bot]"
55+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
56+
npm version "$VERSION"
57+
58+
- name: Publish
59+
run: npm publish --access public --tag "$NPM_TAG"
60+
61+
- name: Push tag
62+
if: inputs.npm_tag != 'latest'
63+
run: git push origin "v$VERSION"
64+
65+
- name: Push tag and version bump branch
66+
if: inputs.npm_tag == 'latest'
67+
run: |
68+
branch="release-$(date +%s)"
69+
git push --follow-tags origin "HEAD:refs/heads/$branch"
70+
echo "Open the version bump PR: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/$GITHUB_REF_NAME...$branch?expand=1" | tee -a "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)