@@ -30,10 +30,70 @@ jobs:
3030 POSTHOG_PERF_API_KEY : ${{ secrets.POSTHOG_PERF_API_KEY }}
3131
3232 - name : Deploy docs
33- if : github.ref == 'refs/heads/main' && matrix.node-version == 'v22.14 .0'
33+ if : github.ref == 'refs/heads/main' && matrix.node-version == 'v22.20 .0'
3434 uses : JamesIves/github-pages-deploy-action@v4
3535 with :
3636 single-commit : true
3737 branch : gh-pages
3838 folder : typedoc
3939
40+ publish :
41+ name : Publish to npm
42+ needs : build
43+ if : startsWith(github.ref, 'refs/tags/v')
44+ runs-on : ubuntu-latest
45+ environment :
46+ name : npm
47+ url : https://www.npmjs.com/package/mockttp
48+ permissions :
49+ contents : read
50+ id-token : write
51+
52+ steps :
53+ - uses : actions/checkout@v4
54+
55+ - uses : actions/setup-node@v4
56+ with :
57+ node-version : ' v22.20.0'
58+ registry-url : ' https://registry.npmjs.org'
59+ cache : ' npm'
60+ cache-dependency-path : ' package.json'
61+
62+ - run : npm install
63+ - run : npm run build
64+
65+ - name : Verify tag matches package.json version
66+ id : version-check
67+ run : |
68+ TAG_VERSION=${GITHUB_REF#refs/tags/v}
69+ PACKAGE_VERSION=$(node -p "require('./package.json').version")
70+ if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
71+ echo "Error: Tag version (v$TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
72+ exit 1
73+ fi
74+ echo "✓ Tag version matches package.json version: $PACKAGE_VERSION"
75+
76+ # Check if version matches strict X.Y.Z format (stable release)
77+ if echo "$PACKAGE_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
78+ echo "Stable release version detected: $PACKAGE_VERSION"
79+ echo "is_prerelease=false" >> $GITHUB_OUTPUT
80+ else
81+ echo "Prerelease version detected: $PACKAGE_VERSION"
82+ echo "is_prerelease=true" >> $GITHUB_OUTPUT
83+ fi
84+
85+ # Make sure we have the latest npm for publishing:
86+ - run : npm install -g npm@latest
87+
88+ - name : Publish to npm
89+ run : |
90+ if [ "${{ steps.version-check.outputs.is_prerelease }}" == "true" ]; then
91+ echo "Publishing untagged prerelease"
92+ npm publish --provenance --tag test
93+ # We have to publish with a tag (so we use 'test') but we can clean it up:
94+ npm dist-tag rm mockttp test --silent
95+ else
96+ echo "Publishing stable release with 'latest' tag"
97+ npm publish --provenance
98+ fi
99+
0 commit comments