-
Notifications
You must be signed in to change notification settings - Fork 0
265 lines (241 loc) · 8.51 KB
/
Copy pathrelease.yml
File metadata and controls
265 lines (241 loc) · 8.51 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Release & Promotion
# FULLY AUTOMATED DEV -> MAIN PROMOTION PIPELINE
# 1. Triggers on push to 'dev' branch
# 2. Runs comprehensive test suite across Node LTS & current
# 3. Builds standalone binaries (Windows .exe, Linux, macOS) in parallel
# 4. Calculates unique CalVer (with Git tags + npm registry collision check)
# 5. Publishes to npmjs and GitHub Packages (GPR)
# 6. Generates GitHub Release with SHA-256 asset checksums
# 7. Automatically promotes clean verified code & release commit to 'main'
# 8. Syncs release tag commit back to 'dev' with [skip ci] to prevent duplicate runs
on:
push:
branches: [ dev ]
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
version:
name: Calculate Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.calver.outputs.version }}
tag: ${{ steps.calver.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: CalVer Calculation & Collision Protection
id: calver
run: |
Y=$(date +%Y); M=$(date +%-m)
git fetch --tags origin 2>/dev/null || true
H=0
for t in $(git tag -l "v${Y}.${M}.*"); do
B=$(echo "$t" | sed "s/v${Y}.${M}.//")
[ "$B" -gt "$H" ] 2>/dev/null && H=$B
done
# Check npm registry to prevent fatal publishing version collisions
NPM_VER=$(npm view cloudsync-cli version 2>/dev/null || echo "0.0.0")
if [[ "$NPM_VER" == "${Y}.${M}."* ]]; then
NPM_H=$(echo "$NPM_VER" | sed "s/${Y}.${M}.//")
[ "$NPM_H" -gt "$H" ] 2>/dev/null && H=$NPM_H
fi
V="${Y}.${M}.$((H+1))"
echo "version=${V}" >> $GITHUB_OUTPUT
echo "tag=v${V}" >> $GITHUB_OUTPUT
echo "Next Unique Release Version: ${V}"
test:
name: Test (Node ${{ matrix.node }})
runs-on: ubuntu-latest
needs: [ version ]
defaults:
run:
working-directory: ./cloudsync-cli
strategy:
matrix:
node: ['lts/*', '*']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
cache-dependency-path: cloudsync-cli/package-lock.json
- run: npm ci
- run: npm test
build-windows:
name: Windows EXE
runs-on: windows-latest
needs: [ test ]
defaults:
run:
working-directory: ./cloudsync-cli
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: npm
cache-dependency-path: cloudsync-cli/package-lock.json
- run: npm ci
- run: npm run build
- run: npx @yao-pkg/pkg dist/bundle.cjs -t node22-win-x64 -o cloudsync.exe
- run: .\cloudsync.exe --version
- run: |
mkdir release-assets
copy cloudsync.exe release-assets\
copy installer\CloudSync-Setup.bat release-assets\
copy installer\CloudSync.iss release-assets\
copy README.md release-assets\
copy LICENSE release-assets\
Compress-Archive -Path release-assets\* -DestinationPath cloudsync-windows-x64.zip
- uses: actions/upload-artifact@v4
with:
name: windows-build
path: |
cloudsync-cli/cloudsync.exe
cloudsync-cli/cloudsync-windows-x64.zip
cloudsync-cli/installer/CloudSync-Setup.bat
cloudsync-cli/installer/CloudSync.iss
retention-days: 7
build-linux:
name: Linux Binary
runs-on: ubuntu-latest
needs: [ test ]
defaults:
run:
working-directory: ./cloudsync-cli
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: npm
cache-dependency-path: cloudsync-cli/package-lock.json
- run: npm ci
- run: npm run build
- run: npx @yao-pkg/pkg dist/bundle.cjs -t node22-linux-x64 -o cloudsync-linux-x64
- run: chmod +x cloudsync-linux-x64 && ./cloudsync-linux-x64 --version
- uses: actions/upload-artifact@v4
with:
name: linux-build
path: cloudsync-cli/cloudsync-linux-x64
retention-days: 7
build-macos:
name: macOS Binary
runs-on: macos-latest
needs: [ test ]
defaults:
run:
working-directory: ./cloudsync-cli
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: npm
cache-dependency-path: cloudsync-cli/package-lock.json
- run: npm ci
- run: npm run build
- run: npx @yao-pkg/pkg dist/bundle.cjs -t node22-macos-x64 -o cloudsync-macos-x64
- run: chmod +x cloudsync-macos-x64 && ./cloudsync-macos-x64 --version
- uses: actions/upload-artifact@v4
with:
name: macos-build
path: cloudsync-cli/cloudsync-macos-x64
retention-days: 7
publish:
name: Publish, Release & Promote
runs-on: ubuntu-latest
needs: [ version, build-windows, build-linux, build-macos ]
defaults:
run:
working-directory: ./cloudsync-cli
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: windows-build
path: cloudsync-cli/assets/windows
- uses: actions/download-artifact@v4
with:
name: linux-build
path: cloudsync-cli/assets/linux
- uses: actions/download-artifact@v4
with:
name: macos-build
path: cloudsync-cli/assets/macos
- name: Setup Git & Author Identity
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin main dev || true
- name: Set Release Version & Create Commit
run: |
V=${{ needs.version.outputs.version }}
npm pkg set version=$V
echo "export const VERSION = '$V';" > src/version.mjs
# Capture latest developer feature commit message
LAST_MSG=$(git log -1 --pretty=%s)
git add package.json package-lock.json src/version.mjs
git commit -m "release: ${V} [skip ci]" -m "Promoted from dev: ${LAST_MSG}" || true
git tag ${{ needs.version.outputs.tag }}
# Promote directly to main and sync release commit back to dev
git push origin HEAD:main
git push origin HEAD:dev
git push origin ${{ needs.version.outputs.tag }}
- name: Setup npm Registry
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
cache: npm
cache-dependency-path: cloudsync-cli/package-lock.json
- name: Install Dependencies & Verify Package
run: |
npm ci
npm pack --dry-run
- name: Publish to npmjs
continue-on-error: true
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Setup GitHub Packages Registry
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://npm.pkg.github.com'
scope: '@tech4file'
- name: Publish to GitHub Packages (GPR)
continue-on-error: true
run: |
npm pkg set name="@tech4file/cloudsync-cli"
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Checksums
run: |
mkdir -p assets
cd assets
find . -type f ! -name '*.zip' ! -name '*.bat' ! -name '*.iss' ! -name '*.md' ! -name 'LICENSE' \
-exec sha256sum {} \; > checksums.txt || true
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.tag }}
name: ${{ needs.version.outputs.version }}
generate_release_notes: true
files: |
cloudsync-cli/assets/windows/cloudsync.exe
cloudsync-cli/assets/windows/cloudsync-windows-x64.zip
cloudsync-cli/assets/windows/CloudSync-Setup.bat
cloudsync-cli/assets/windows/CloudSync.iss
cloudsync-cli/assets/linux/cloudsync-linux-x64
cloudsync-cli/assets/macos/cloudsync-macos-x64
cloudsync-cli/assets/checksums.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}