-
-
Notifications
You must be signed in to change notification settings - Fork 314
70 lines (67 loc) · 2.08 KB
/
Copy pathpublish.yml
File metadata and controls
70 lines (67 loc) · 2.08 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
name: Publish to npm
on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [master]
jobs:
check:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
should_publish: ${{ steps.version-check.outputs.should_publish }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 24.x
- name: Check if version is already published
id: version-check
run: |
NAME=$(node -p "require('./package.json').name")
LOCAL=$(node -p "require('./package.json').version")
if npm view "${NAME}@${LOCAL}" version 2>/dev/null; then
echo "should_publish=false" >> "$GITHUB_OUTPUT"
echo "Version $LOCAL already published, skipping."
else
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "New version detected: $LOCAL"
fi
publish:
needs: check
if: needs.check.outputs.should_publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 24.x
- run: npm ci
- name: Build
run: npm run dist
- name: Determine npm tag
id: npm-tag
run: |
VERSION=$(node -p "require('./package.json').version")
if [[ "$VERSION" == *-* ]]; then
echo "tag=beta" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi
- name: Publish
run: npm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }}
- name: Create GitHub Release
run: |
VERSION=$(node -p "require('./package.json').version")
PRERELEASE=""
if [[ "$VERSION" == *-* ]]; then
PRERELEASE="--prerelease"
fi
gh release create "v${VERSION}" --generate-notes $PRERELEASE
env:
GH_TOKEN: ${{ github.token }}