-
Notifications
You must be signed in to change notification settings - Fork 18
66 lines (58 loc) · 1.92 KB
/
publish.yml
File metadata and controls
66 lines (58 loc) · 1.92 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
name: Publish
on:
workflow_run:
workflows:
- Testing
types:
- completed
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main' }}
runs-on: ubuntu-latest
steps:
- name: Checkout triggering commit
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Setup Node.js (OIDC)
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install
run: bun install --frozen-lockfile
- name: Check if already published
id: check
run: |
PKG_NAME=$(jq -r '.name' package.json)
PKG_VERSION=$(jq -r '.version' package.json)
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/${PKG_NAME}/${PKG_VERSION}")
if [ "$STATUS" = "200" ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "✓ ${PKG_NAME}@${PKG_VERSION} already published"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish
if: steps.check.outputs.skip != 'true'
run: |
set -euo pipefail
PKG_VERSION=$(jq -r '.version' package.json)
NPM_TAG="latest"
case "$PKG_VERSION" in
*-*) NPM_TAG="beta" ;;
esac
npm publish --provenance --access public --loglevel verbose --tag "$NPM_TAG" || {
echo "npm publish failed; dumping npm debug logs";
ls -la "$HOME/.npm/_logs" || true;
tail -n +1 "$HOME/.npm/_logs"/*-debug-0.log || true;
exit 1;
}