1616 - uses : actions/setup-node@v4
1717 with :
1818 node-version : ${{ matrix.node-version }}
19+ cache : ' npm'
20+ cache-dependency-path : ' package.json'
1921
2022 - run : npm install
21-
23+ - run : npm run build
2224 - run : npm test
25+
26+ publish :
27+ name : Publish to npm
28+ needs : build
29+ if : startsWith(github.ref, 'refs/tags/v')
30+ runs-on : ubuntu-latest
31+ environment :
32+ name : npm
33+ url : https://www.npmjs.com/package/@httptoolkit/browser-launcher
34+ permissions :
35+ contents : read
36+ id-token : write
37+
38+ steps :
39+ - uses : actions/checkout@v4
40+
41+ - uses : actions/setup-node@v4
42+ with :
43+ node-version : ' 22.x'
44+ registry-url : ' https://registry.npmjs.org'
45+ cache : ' npm'
46+ cache-dependency-path : ' package.json'
47+
48+ - run : npm install
49+ - run : npm run build
50+
51+ - name : Verify tag matches package.json version
52+ id : version-check
53+ run : |
54+ TAG_VERSION=${GITHUB_REF#refs/tags/v}
55+ PACKAGE_VERSION=$(node -p "require('./package.json').version")
56+ if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
57+ echo "Error: Tag version (v$TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
58+ exit 1
59+ fi
60+ echo "✓ Tag version matches package.json version: $PACKAGE_VERSION"
61+
62+ # Check if version matches strict X.Y.Z format (stable release)
63+ if echo "$PACKAGE_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
64+ echo "Stable release version detected: $PACKAGE_VERSION"
65+ echo "is_prerelease=false" >> $GITHUB_OUTPUT
66+ else
67+ echo "Prerelease version detected: $PACKAGE_VERSION"
68+ echo "is_prerelease=true" >> $GITHUB_OUTPUT
69+ fi
70+
71+ # Make sure we have the latest npm for publishing:
72+ - run : npm install -g npm@latest
73+
74+ - name : Publish to npm
75+ run : |
76+ if [ "${{ steps.version-check.outputs.is_prerelease }}" == "true" ]; then
77+ echo "Publishing untagged prerelease"
78+ npm publish --provenance --tag test
79+ # We have to publish with a tag (so we use 'test') but we can clean it up:
80+ npm dist-tag rm @httptoolkit/browser-launcher test --silent
81+ else
82+ echo "Publishing stable release with 'latest' tag"
83+ npm publish --provenance
84+ fi
0 commit comments