-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (84 loc) · 2.41 KB
/
publish.yml
File metadata and controls
98 lines (84 loc) · 2.41 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
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Publish to npm
on:
workflow_dispatch:
inputs:
version:
description: Package version in x.y.z format
required: true
type: string
npm_token:
description: npm token used for publish
required: true
type: string
permissions:
contents: write
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: lts/*
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Validate version format
env:
VERSION: ${{ inputs.version }}
run: |
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version: $VERSION"
echo "Expected format: x.y.z"
exit 1
fi
- name: Configure git user
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Ensure tag does not exist
env:
VERSION: ${{ inputs.version }}
run: |
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "Tag v$VERSION already exists"
exit 1
fi
- name: Update package version and commit
env:
VERSION: ${{ inputs.version }}
run: |
npm version "$VERSION" --no-git-tag-version
git add package.json
git commit -m "chore(release): v$VERSION"
- name: Build package
run: |
npm install
npm run build
- name: Publish to npm
env:
NPM_TOKEN: ${{ inputs.npm_token }}
run: npm publish --access public --provenance
- name: Create and push tag
env:
VERSION: ${{ inputs.version }}
run: |
git tag "v$VERSION"
git push origin HEAD
git push origin "v$VERSION"
- name: Pack npm tarball
run: |
npm pack --pack-destination dist
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ inputs.version }}
run: |
gh release create "v$VERSION" \
--title "v$VERSION" \
--generate-notes \
dist/*