-
-
Notifications
You must be signed in to change notification settings - Fork 281
323 lines (294 loc) · 10.9 KB
/
BuildImages.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
name: Build OS image
on:
push:
branches:
- "master"
- "develop"
paths:
- "src/modules/**"
- "src/build_dist"
- "config/**"
- ".github/workflows/BuildImages.yml"
- ".github/workflow_config.yml"
- ".github/scripts/**"
tags-ignore:
- "**"
pull_request:
types: [opened, edited, reopened, synchronize]
paths:
- "src/**"
- "config/**"
- ".github/workflows/BuildImages.yml"
- ".github/scripts/**"
- ".github/workflow_config.yml"
workflow_dispatch:
# Allow to stop obsolete workflows
concurrency:
group: ci-buildtrain-${{ github.ref }}-1
cancel-in-progress: true
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
date: ${{ steps.base-name.outputs.date }}
start_timestamp: ${{ steps.base-name.outputs.start_timestamp }}
start_realtime: ${{ steps.base-name.outputs.start_realtime }}
version: ${{ steps.current-version.outputs.version }}
name: ${{ steps.base-name.outputs.name }}
prefix: ${{ steps.gen-prefix.outputs.prefix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create Date and timestamp
id: base-name
shell: bash
run: |
# Create Date and timestamp
{
echo "date=$(date +"%Y-%m-%d")"
echo "start_timestamp=${EPOCHSECONDS}"
realtime="$(date -d@"${EPOCHSECONDS}" -u +"%Y-%m-%d %H:%M:%S UTC")"
echo "start_realtime=${realtime}"
echo "name=${{ github.event.repository.name }}"
} >> $GITHUB_OUTPUT
- name: Get current version
id: current-version
shell: bash
run: |
# Get current version
echo "version=$(cat ./src/version)" >> $GITHUB_OUTPUT
- name: Generate Name Prefix
id: gen-prefix
shell: bash
run: |
# Generate Name prefix
prefix="${{ steps.base-name.outputs.date }}"
prefix="${prefix}-${{ steps.base-name.outputs.name }}"
prefix="${prefix}-${{ steps.current-version.outputs.version }}"
echo "prefix=${prefix}" >> $GITHUB_OUTPUT
- name: Debug information
id: debug-info
shell: bash
run: |
# Print Debug informations
echo "Debug information:"
echo "Date: ${{ steps.base-name.outputs.date }}"
echo "Start Time: ${{ steps.base-name.outputs.start_realtime }}"
echo "Timestamp (sec): ${{ steps.base-name.outputs.start_timestamp }}"
echo "Name: ${{ steps.base-name.outputs.name }}"
echo "Version: ${{ steps.current-version.outputs.version }}"
echo "Prefix: ${{ steps.gen-prefix.outputs.prefix }}"
- name: Setup Summary
shell: bash
run: |
# Setup summary
{
echo -e "### Setup:\n"
echo -e "Date: ${{ steps.base-name.outputs.date }}"
echo -e "Name: ${{ steps.base-name.outputs.name }}"
echo -e "Version: ${{ steps.current-version.outputs.version }}"
echo -e "Prefix: ${{ steps.gen-prefix.outputs.prefix }}"
echo -e "Start Time: ${{ steps.base-name.outputs.start_realtime }}"
} >> $GITHUB_STEP_SUMMARY
matrix:
name: Create Matrix
needs: setup
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create Matrix
id: set-matrix
run: |
# Create matrix using setup_matrix.py
PY_INT=$(command -v python3)
APP="${{ github.workspace }}/.github/scripts/setup_matrix.py"
CONFIG="${{ github.workspace }}/.github/workflow_config.yml"
GROUP="buildtest"
${PY_INT} ${APP} -c ${CONFIG} -g ${GROUP} --git
build:
needs: [setup, matrix]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.matrix.outputs.matrix) }}
outputs:
file-name: ${{ steps.move-image.outputs.file_name }}
steps:
- name: Build image
id: build
uses: mainsail-crew/MainsailOS-actions/build-image@master
with:
config: ${{ matrix.config }}
- name: Generate file name
if: always()
shell: bash
id: file-name
run: |
# Generate file name
type="$(cut -d'/' -f1 <<< ${{ matrix.config }})"
sbc="$(cut -d'/' -f2 <<< ${{ matrix.config }})"
file_name="${{ needs.setup.outputs.prefix }}-${type}-${sbc}"
echo "file_name=${file_name}" >> $GITHUB_OUTPUT
echo "File name: ${file_name}"
## Keep as Debug output.
# # Generate summary header
# {
# echo "## Build creates following files:"
# echo "- ${file_name}.img"
# echo "- ${file_name}.img.xz"
# echo "- ${file_name}.img.sha256"
# echo "- ${file_name}.xz.img.sha256"
# echo "- ${file_name}-build.log"
# echo "**NOTE:** If image build fails it will only generate a log file"
# } >> $GITHUB_STEP_SUMMARY
- name: Upload logfile
if: always()
uses: actions/upload-artifact@v3
with:
name: ${{ steps.file-name.outputs.file_name }}-build.log
path: ${{ github.workspace }}/repository/src/build.log
- name: Cleanup workspace
shell: bash
run: |
# Clean up workspace
path="${{ github.workspace }}/repository/src/workspace"
sudo rm -rfv ${path}/aptcache
sudo rm -rfv ${path}/mount
sudo rm -rfv ${path}/chroot_script
- name: Set workspace permissions
if: success()
shell: bash
run: |
# Change owner and permissions
path="${{ github.workspace }}/repository/src/workspace"
sudo chown -v -R ${USER}:${USER} ${path}
sudo chmod 0775 -v -R ${path}
- name: Rename image file
id: move-image
if: success()
shell: bash
run: |
# Rename image
image="${{ steps.file-name.outputs.file_name }}"
mv -v repository/src/workspace/*.img ${image}.img
echo "image=${image}" >> $GITHUB_OUTPUT
- name: Compressing Image
id: compress
shell: bash
run: |
# Compress image
# Outputs:
# "img_size=${size}"
# "img_size_hr=${size_hr}"
# "comp_img_size=${comp_size}"
# "comp_img_size_hr=${comp_size_hr}"
path="${{ github.workspace }}/repository"
APP="${path}/.github/scripts/compress.sh"
${APP} ${{ steps.move-image.outputs.image }}
- name: Calculating checksums
id: checksums
shell: bash
run: |
# Calculate checksums (sha256)
path="${{ github.workspace }}/repository"
APP="${path}/.github/scripts/checksums.sh"
${APP} ${{ steps.move-image.outputs.image }}
- name: Export config
id: config
shell: bash
run: |
# Export configuration
cfg="${{ github.workspace }}/repository/src/config"
cfg_out="${{ steps.file-name.outputs.file_name }}-config"
cat ${cfg} | sed -n '/^[A-Z]/p' | sort > ${cfg_out}
echo "config_file=${cfg_out}" >> $GITHUB_OUTPUT
{
echo -e "## Configuration:"
echo -e "<details>\n<summary>Show configuration</summary>\n"
cat ${cfg_out}
echo -e "</details>\n"
} >> $GITHUB_STEP_SUMMARY
- name: Generate Build statistics
shell: bash
id: statistic
run: |
# Generate build statistics
start_realtime="${{ needs.setup.outputs.start_realtime }}"
start_timestamp="${{ needs.setup.outputs.start_timestamp }}"
finish_timestamp="${EPOCHSECONDS}"
finish_realtime="$(date -d@"${EPOCHSECONDS}" -u +"%Y-%m-%d %H:%M:%S UTC")"
duration="$((finish_timestamp-start_timestamp))"
# Human readable
duration_hr="$(date -d@"${duration}" -u +"[ %H:%M:%S ]")"
echo "duration=${duration}" >> $GITHUB_OUTPUT
echo "duration_hr=${duration_hr}" >> $GITHUB_OUTPUT
{
echo "## Build statistics:"
echo "Build start time: ${start_realtime}"
echo "Build finish time: ${finish_realtime}"
echo "Build duration: ${duration} seconds ${duration_hr}"
} >> $GITHUB_STEP_SUMMARY
- name: Generate summary column md file
env:
md_file: ${{ steps.move-image.outputs.image }}-col.md
image: ${{ steps.move-image.outputs.image }}.img.xz
raw_img_size: ${{ steps.compress.outputs.img_size }}
raw_img_size_hr: ${{ steps.compress.outputs.img_size_hr }}
comp_img_size: ${{ steps.compress.outputs.comp_img_size }}
comp_img_size_hr: ${{ steps.compress.outputs.comp_img_size_hr }}
duration: ${{ steps.statistic.outputs.duration }}
duration_hr: ${{ steps.statistic.outputs.duration_hr }}
run: |
# Generate table-column.md
path="${{ github.workspace }}/repository"
APP="${path}/.github/scripts/summary_column.sh"
${APP} ${{ github.workspace }}
- name: Upload Compressed Image
uses: actions/upload-artifact@v3
with:
name: ${{ steps.move-image.outputs.image }}.img.xz
path: ${{ steps.move-image.outputs.image }}.img.xz
- name: Upload Compressed Image Checksum
uses: actions/upload-artifact@v3
with:
name: ${{ steps.move-image.outputs.image }}.img.xz.sha256
path: ${{ steps.move-image.outputs.image }}.img.xz.sha256
- name: Upload Image Checksum
uses: actions/upload-artifact@v3
with:
name: ${{ steps.move-image.outputs.image }}.img.sha256
path: ${{ steps.move-image.outputs.image }}.img.sha256
- name: Upload Configuration
uses: actions/upload-artifact@v3
with:
name: ${{ steps.config.outputs.config_file }}
path: ${{ steps.config.outputs.config_file }}
- name: Upload Summary table column file
uses: actions/upload-artifact@v3
with:
name: ${{ steps.move-image.outputs.image }}-col.md
path: ${{ steps.move-image.outputs.image }}-col.md
summary:
name: Build Summary
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
path: repository
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ${{ github.workspace }}
- name: Generate summary
run: |
# Generate summary
path="${{ github.workspace }}/repository"
APP="${path}/.github/scripts/generate_summary.sh"
${APP} ${{ github.workspace }}