-
Notifications
You must be signed in to change notification settings - Fork 20
191 lines (170 loc) · 5.5 KB
/
Copy pathrelease.yaml
File metadata and controls
191 lines (170 loc) · 5.5 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
name: release
run-name: release ${{ github.ref_name }}
on:
workflow_dispatch:
release:
types: [published]
permissions: {}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Reject disallowed branch
if: >-
${{ github.event_name == 'workflow_dispatch'
&& !startsWith(github.ref, 'refs/heads/development/')
&& !startsWith(github.ref, 'refs/heads/hotfix/') }}
env:
REF_NAME: ${{ github.ref_name }}
run: |
echo "::error::Releases must run from a development/* or" \
"hotfix/* branch (got $REF_NAME)"
exit 1
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: Read version from package.json
id: version
run: |
version=$(jq -r .version package.json)
if [ -z "$version" ] || [ "$version" = "null" ]; then
echo "::error::No version found in package.json"
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Verify tag matches package.json version
if: ${{ github.event_name == 'release' }}
env:
VERSION: ${{ steps.version.outputs.version }}
TAG: ${{ github.event.release.tag_name }}
run: |
tag=${TAG#v}
if [ "$tag" != "$VERSION" ]; then
echo "::error::Release tag $TAG does not match package.json" \
"version $VERSION"
exit 1
fi
- name: Fail if release already exists
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
if gh release view "$VERSION" --repo "$GITHUB_REPOSITORY" \
>/dev/null 2>&1; then
echo "::error::Release $VERSION already exists"
exit 1
fi
- name: Fail if tag already exists
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then
echo "::error::Tag $VERSION already exists (possibly on a" \
"different commit); refusing to move it"
exit 1
fi
- name: Install NodeJS
uses: actions/setup-node@v6
with:
node-version: '24'
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline
- name: Build
run: yarn build
- name: Pack tarball
run: npm pack --ignore-scripts
- name: Attest build provenance
uses: actions/attest-build-provenance@v4
with:
subject-path: '*.tgz'
- name: Upload package artifact
uses: actions/upload-artifact@v7
with:
name: package
path: '*.tgz'
if-no-files-found: error
retention-days: 7
publish-github:
needs: build
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Download package artifact
uses: actions/download-artifact@v8
with:
name: package
- name: Install NodeJS
uses: actions/setup-node@v6
with:
node-version: '24'
registry-url: 'https://npm.pkg.github.com'
scope: '@scality'
- name: Publish to GitHub Packages
env:
NODE_AUTH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.build.outputs.version }}
run: |
if [ -n "$(npm view "@scality/arsenal@$VERSION" version 2>/dev/null)" ]; then
echo "::notice::@scality/arsenal@$VERSION already on GitHub Packages; skipping"
else
npm publish *.tgz --tag "latest-${VERSION%.*}"
fi
publish-npm:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Download package artifact
uses: actions/download-artifact@v8
with:
name: package
- name: Install NodeJS
uses: actions/setup-node@v6
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
scope: '@scality'
- name: Publish to npm
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
if [ -n "$(npm view "@scality/arsenal@$VERSION" version 2>/dev/null)" ]; then
echo "::notice::@scality/arsenal@$VERSION already on npm; skipping"
else
npm publish *.tgz --provenance --tag "latest-${VERSION%.*}"
fi
release:
needs: [build, publish-github, publish-npm]
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
permissions:
contents: write
steps:
- name: Create Release
uses: softprops/action-gh-release@v3
env:
GITHUB_TOKEN: ${{ github.token }}
with:
name: ${{ needs.build.outputs.version }}
tag_name: ${{ needs.build.outputs.version }}
generate_release_notes: true
append_body: true
body: |
GitHub Packages: https://github.com/${{ github.repository }}/pkgs/npm/arsenal
npm: https://www.npmjs.com/package/@scality/arsenal
target_commitish: ${{ github.sha }}