-
Notifications
You must be signed in to change notification settings - Fork 8
85 lines (72 loc) · 2.55 KB
/
ci.yml
File metadata and controls
85 lines (72 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: CI
on: [push, pull_request]
jobs:
build:
name: Build & test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x, '*']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: 'package.json'
- uses: shivammathur/setup-php@v2
with:
php-version: '7.0'
- run: npm ci
- run: npm test
publish:
name: Publish to npm
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment:
name: npm
url: https://www.npmjs.com/package/@httptoolkit/httpsnippet
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: 'package.json'
- run: npm ci
- name: Verify tag matches package.json version
id: version-check
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
echo "Error: Tag version (v$TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
exit 1
fi
echo "✓ Tag version matches package.json version: $PACKAGE_VERSION"
# Check if version matches strict X.Y.Z format (stable release)
if echo "$PACKAGE_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Stable release version detected: $PACKAGE_VERSION"
echo "is_prerelease=false" >> $GITHUB_OUTPUT
else
echo "Prerelease version detected: $PACKAGE_VERSION"
echo "is_prerelease=true" >> $GITHUB_OUTPUT
fi
# Make sure we have the latest npm for publishing:
- run: npm install -g npm@latest
- name: Publish to npm
run: |
if [ "${{ steps.version-check.outputs.is_prerelease }}" == "true" ]; then
echo "Publishing untagged prerelease"
npm publish --provenance --tag test
# We have to publish with a tag (so we use 'test') but we can clean it up:
npm dist-tag rm @httptoolkit/httpsnippet test --silent
else
echo "Publishing stable release with 'latest' tag"
npm publish --provenance
fi