-
Notifications
You must be signed in to change notification settings - Fork 3
106 lines (86 loc) · 3.52 KB
/
Copy pathnode-release.yml
File metadata and controls
106 lines (86 loc) · 3.52 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
99
100
101
102
103
104
105
106
name: Node Release
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
push:
branches: [main]
paths:
- 'sdk-node/package.json'
workflow_dispatch:
concurrency: ${{ github.workflow }}-${{ github.ref }}
permissions:
contents: write
id-token: write
jobs:
release:
name: Publish Node SDK
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
fetch-depth: 0
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271
with:
version: 10
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Detect version change
id: version
run: |
current_version=$(node -p "require('./sdk-node/package.json').version")
printf 'current=%s\n' "$current_version" >> "$GITHUB_OUTPUT"
if [ "${{ github.event_name }}" = 'workflow_dispatch' ] || [ -z "${{ github.event.before }}" ]; then
printf 'changed=true\n' >> "$GITHUB_OUTPUT"
exit 0
fi
previous_version=
if git cat-file -e "${{ github.event.before }}:sdk-node/package.json" 2>/dev/null; then
previous_version=$(git show "${{ github.event.before }}:sdk-node/package.json" | node -e "let data=''; process.stdin.on('data', chunk => data += chunk); process.stdin.on('end', () => process.stdout.write(JSON.parse(data).version));")
fi
if [ "$current_version" = "$previous_version" ]; then
printf 'changed=false\n' >> "$GITHUB_OUTPUT"
exit 0
fi
printf 'changed=true\n' >> "$GITHUB_OUTPUT"
- name: Check npm publish state
if: ${{ steps.version.outputs.changed == 'true' }}
id: npm_state
env:
VERSION: ${{ steps.version.outputs.current }}
run: |
if npm view "@primitivedotdev/sdk@$VERSION" version >/dev/null 2>&1; then
printf 'published=true\n' >> "$GITHUB_OUTPUT"
exit 0
fi
printf 'published=false\n' >> "$GITHUB_OUTPUT"
- name: Install node dependencies
if: ${{ steps.version.outputs.changed == 'true' && steps.npm_state.outputs.published != 'true' }}
run: make node-install
- name: Publish package to npm
if: ${{ steps.version.outputs.changed == 'true' && steps.npm_state.outputs.published != 'true' }}
run: scripts/npm-publish-with-retry.sh --package @primitivedotdev/sdk --version "${{ steps.version.outputs.current }}" --directory sdk-node
- name: Check GitHub release state
if: ${{ steps.version.outputs.changed == 'true' }}
id: release_state
env:
GH_TOKEN: ${{ github.token }}
TAG: sdk-node/v${{ steps.version.outputs.current }}
run: |
if gh release view "$TAG" >/dev/null 2>&1; then
printf 'exists=true\n' >> "$GITHUB_OUTPUT"
exit 0
fi
printf 'exists=false\n' >> "$GITHUB_OUTPUT"
- name: Create GitHub release and tag
if: ${{ steps.version.outputs.changed == 'true' && steps.release_state.outputs.exists != 'true' }}
env:
GH_TOKEN: ${{ github.token }}
TAG: sdk-node/v${{ steps.version.outputs.current }}
VERSION: ${{ steps.version.outputs.current }}
run: |
gh release create "$TAG" \
--target "$GITHUB_SHA" \
--title "Node SDK v$VERSION" \
--generate-notes