-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (63 loc) · 2.02 KB
/
Copy pathrelease.yml
File metadata and controls
76 lines (63 loc) · 2.02 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
name: Publish release
on:
push:
tags:
- 'v*.*.*'
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
cache: npm
- name: Install dependencies
run: npm ci
- name: Validate tag version
shell: bash
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG_VERSION="${GITHUB_REF_NAME#v}"
if [[ "$TAG_VERSION" != "$PACKAGE_VERSION" ]]; then
echo "Tag $GITHUB_REF_NAME does not match package.json version $PACKAGE_VERSION"
exit 1
fi
- name: Build and validate package
run: |
npm run build
test "$(node dist/index.js --version)" = "$(node -p "require('./package.json').version")"
npm pack --dry-run
- name: Publish to npm
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version > /dev/null 2>&1; then
echo "$PACKAGE_NAME@$PACKAGE_VERSION is already published"
else
npm publish --access public --provenance
fi
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then
echo "GitHub release $GITHUB_REF_NAME already exists"
else
gh release create "$GITHUB_REF_NAME" \
--verify-tag \
--generate-notes \
--title "$GITHUB_REF_NAME"
fi