-
-
Notifications
You must be signed in to change notification settings - Fork 272
403 lines (352 loc) · 13.1 KB
/
Release.yml
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
name: Release
on:
workflow_dispatch:
inputs:
version:
type: string
description: New version number in X.Y.Z
required: true
jobs:
push-version-number:
name: Push version number
runs-on: ubuntu-latest
steps:
- name: Clone develop repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
ref: "develop"
- name: Get current version
id: current-version
shell: bash
run: |
source ./config/default
echo "version=${DIST_VERSION}" >> $GITHUB_OUTPUT
- name: Push version number
if: steps.current-version.outputs.version != github.event.inputs.version
shell: bash
run: |
sed -i "s|^DIST_VERSION.*|DIST_VERSION=\"${{ github.event.inputs.version }}\"|" ./config/default
- name: git add & commit & push
if: steps.current-version.outputs.version != github.event.inputs.version
uses: EndBug/add-and-commit@v9
with:
add: "./config/default"
default_author: github_actions
message: "chore: push version number to v${{ github.event.inputs.version }}"
push: true
update-master-branch:
name: Update master branch
needs: push-version-number
runs-on: ubuntu-latest
steps:
- uses: everlytic/[email protected]
with:
github_token: ${{ secrets.PAT }}
source_ref: "develop"
target_branch: "master"
commit_message_template: "[Automated] Merged {source_ref} into target {target_branch}"
release:
name: Create Release
needs: update-master-branch
runs-on: ubuntu-latest
outputs:
id: ${{ steps.create-release.outputs.id }}
date: ${{ steps.base-name.outputs.date }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Get latest tag
id: latest_tag
shell: bash
run: |
echo "TAG_NAME=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_OUTPUT
- name: Generate a changelog
uses: orhun/git-cliff-action@v2
id: changelog
with:
config: ./cliff-release.toml
args: ${{ steps.latest_tag.outputs.TAG_NAME }}..HEAD
- name: Create empty release
id: create-release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: "MainsailOS ${{ github.event.inputs.version }}"
tag_name: ${{ github.event.inputs.version }}
body: ${{ steps.changelog.outputs.content }}
draft: true
- name: Create Date
id: base-name
if: always()
shell: bash
run: |
NOW="$(date +"%Y-%m-%d")"
echo "date=${NOW}" >> $GITHUB_OUTPUT
matrix:
name: Create Matrix
needs: release
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: master
- name: Create Matrix
id: set-matrix
run: |
PY_INT=$(command -v python3)
CONFIG="${{ github.workspace }}/.github/workflow_config.yml"
GROUP="release"
$PY_INT ${{ github.workspace }}/.github/scripts/setup_matrix.py -c $CONFIG -g $GROUP --git
build:
needs: [release, matrix]
runs-on: ubuntu-latest
outputs:
base_name: ${{ steps.move-image.outputs.base_name }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.matrix.outputs.matrix) }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: master
path: repository
submodules: true
- name: Build image
id: build
uses: ./repository/.github/actions/build
with:
config: ${{ matrix.config }}
- name: Upload failed Logfile
if: failure()
uses: actions/upload-artifact@v4
with:
name: failed-${{ steps.move-image.outputs.image }}.log
path: repository/src/build.log
- name: Rename image file
id: move-image
shell: bash
run: |
source repository/src/config
base_name="${{ needs.release.outputs.date }}-${DIST_NAME}-${DIST_VERSION}"
image="${base_name}-${{ steps.build.outputs.type }}-${{ steps.build.outputs.sbc }}"
mv repository/src/workspace/*.img $image.img
echo "base_name=${base_name}" >> $GITHUB_OUTPUT
echo "image=${image}" >> $GITHUB_OUTPUT
- name: Compressing Image
shell: bash
run: |
CPU_COUNT="$(nproc)"
echo -e "\e[32mUsing ${CPU_COUNT} Cores for compression...\e[0m"
xz -efkvz9T"${CPU_COUNT}" ${{ steps.move-image.outputs.image }}.img || true
- name: Upload Compressing Image
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: ${{ steps.move-image.outputs.image }}.img.xz
- name: Calculating checksums
id: checksums
shell: bash
run: |
sha256sum ${{ steps.move-image.outputs.image }}.img > ${{ steps.move-image.outputs.image }}.img.sha256
image_checksum=`cat ${{ steps.move-image.outputs.image }}.img.sha256 | awk '{ print $1 }'`
echo "image=${image_checksum}" >> $GITHUB_OUTPUT
sha256sum ${{ steps.move-image.outputs.image }}.img.xz > ${{ steps.move-image.outputs.image }}.img.xz.sha256
zip_checksum=`cat ${{ steps.move-image.outputs.image }}.img.xz.sha256 | awk '{ print $1 }'`
echo "zip=${zip_checksum}" >> $GITHUB_OUTPUT
- name: Upload Checksums
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: ${{ steps.move-image.outputs.image }}.img.sha256;${{ steps.move-image.outputs.image }}.img.xz.sha256
- name: Calculating filesizes
id: filesizes
shell: bash
run: |
image_filesize=`wc -c ${{ steps.move-image.outputs.image }}.img | awk '{print $1}'`
echo "image=${image_filesize}" >> $GITHUB_OUTPUT
zip_filesize=`wc -c ${{ steps.move-image.outputs.image }}.img.xz | awk '{print $1}'`
echo "zip=${zip_filesize}" >> $GITHUB_OUTPUT
- name: Debug output
run: |
echo "release-id: ${{ needs.release.outputs.id }}"
echo "release-version: ${{ needs.release.outputs.version }}"
echo "image-name: ${{ steps.move-image.outputs.image }}"
echo "checksum image: ${{ steps.checksums.outputs.image }}"
echo "checksum zip: ${{ steps.checksums.outputs.zip }}"
echo "filesize-image: ${{ steps.filesizes.outputs.image }}"
echo "filesize-zip: ${{ steps.filesizes.outputs.zip }}"
- name: Get JSON data
id: json-data
shell: bash
run: |
source repository/src/config
if [[ -n "${BASE_ARCH}" ]]; then
type="64-bit"
else
type="32-bit"
fi
name="${JSON_PRETTY_NAME} ${{ github.event.inputs.version }}"
name="${name} - ${JSON_PRETTY_SBC_NAME}"
name="${name} (${type})"
echo "pretty_name=${name}" >> $GITHUB_OUTPUT
echo "description=${JSON_DESCRIPTION}" >> $GITHUB_OUTPUT
echo "icon_url=${JSON_ICON_URL}" >> $GITHUB_OUTPUT
echo "init_format=${JSON_INIT_FORMAT}" >> $GITHUB_OUTPUT
echo "supported_sbc=${JSON_SUPPORTED_SBC}" >> $GITHUB_OUTPUT
- name: Generate JSON
id: json
uses: actions/github-script@v6
env:
name: "${{ steps.json-data.outputs.pretty_name }}"
description: "${{ steps.json-data.outputs.description }}"
icon: "${{ steps.json-data.outputs.icon_url }}"
url: "https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.version }}/${{ steps.move-image.outputs.image }}.img.xz"
extract_size: ${{ steps.filesizes.outputs.image }}
extract_sha256: "${{ steps.checksums.outputs.image }}"
image_download_size: ${{ steps.filesizes.outputs.zip }}
release_date: "${{ needs.release.outputs.date }}"
init_format: "${{ steps.json-data.outputs.init_format }}"
supported_sbc: ${{ steps.json-data.outputs.supported_sbc }}
with:
result-encoding: string
script: |
const fs = require('fs')
const { name, description, icon, url, extract_size, extract_sha256, image_download_size, release_date, init_format, supported_sbc } = process.env
const json = JSON.stringify({
name,
description,
icon,
url,
extract_size: parseInt(extract_size),
extract_sha256,
image_download_size: parseInt(image_download_size),
release_date,
init_format,
devices: supported_sbc.split(" ").filter((item) => item != '')
})
fs.writeFileSync("./${{ steps.move-image.outputs.image }}.json", json)
- name: Debug output
shell: bash
run: |
cat "./${{ steps.move-image.outputs.image }}.json"
- name: Upload JSON
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: ${{ steps.move-image.outputs.image }}.json
finish:
name: Finish Release
needs: [release, build]
runs-on: ubuntu-latest
steps:
- name: Publish Release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
update-rpi-imager:
name: Update rpi-imager json
needs: [release, build, finish]
runs-on: ubuntu-latest
steps:
- name: Download snipes
uses: robinraju/[email protected]
with:
tag: ${{ github.event.inputs.version }}
fileName: "${{ needs.build.outputs.base_name }}-*.json"
out-file-path: "downloads"
- name: Combine JSON
id: json
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const downloadFolder = './downloads/'
const fs = require('fs')
const os_list = []
fs.readdirSync(downloadFolder).forEach(file => {
const raw = fs.readFileSync('./downloads/' + file, {encoding:'utf8', flag:'r'})
try {
os_list.push(JSON.parse(raw))
} catch (err) {
console.log("Error parsing JSON string:", err)
}
})
const json = JSON.stringify({os_list})
fs.writeFileSync('rpi-imager.json', json)
- name: Upload JSON
if: success()
uses: xresloader/upload-to-github-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release.outputs.id }}
file: rpi-imager.json
- name: Move in seperate dir
if: ${{ github.repository_owner == 'Mainsail-Crew' }}
run: |
mkdir upload
mv rpi-imager.json ./upload
- name: Upload to remote server
if: ${{ github.repository_owner == 'Mainsail-Crew' }}
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.OSHOST }}
username: ${{ secrets.OSUSER }}
password: ${{ secrets.OSPASSWORD }}
local-dir: ./upload/
update-changelog:
needs: finish
name: Generate changelog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: "develop"
token: ${{ secrets.PAT }}
fetch-depth: 0
- name: Get latest tag
id: get_tags
shell: bash
run: |
echo "END_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_OUTPUT
if [[ "${{ github.repository_owner }}" == "Mainsail-Crew" ]]; then
echo "START_TAG=0.5.0" >> $GITHUB_OUTPUT
else
echo "START_TAG=$(git for-each-ref --sort=creatordate --count=1 --format='%(refname:lstrip=2)')" >> $GITHUB_OUTPUT
fi
- name: Generate a changelog
uses: orhun/git-cliff-action@v2
id: git-cliff
with:
config: cliff.toml
args: ${{ steps.get_tags.outputs.START_TAG }}..${{ steps.get_tags.outputs.END_TAG }}
env:
OUTPUT: ${{ github.workspace }}/CHANGELOG.md
- name: Show CHANGELOG
run: |
cat CHANGELOG.md
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "docs(changelog): update changelog"
file_pattern: CHANGELOG.md