forked from osism/openstack-ironic-images
-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (191 loc) · 8.94 KB
/
ci.yaml
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
---
name: CI
'on':
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
push:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- distribution: ubuntu
release: jammy
- distribution: rocky
release: 9
runs-on: ubuntu-latest
env:
DISTRIBUTION: ${{ matrix.distribution }}
RELEASE: ${{ matrix.release }}
permissions:
contents: write
steps:
- name: Get code
uses: actions/checkout@v4
- name: Update Package Cache
run: apt update
shell: sudo -E bash -e {0}
- name: Install Packages with apt
run: >2
apt install -y
bubblewrap
cryptsetup-bin
dnf
dosfstools
e2fsprogs
gdisk
lvm2
qemu-utils
rsync
zstd
shell: sudo -E bash -e {0}
- name: Setup Python environment
uses: actions/setup-python@v5
with:
python-version: '3'
cache: 'pip'
id: py3
- name: Clean /usr/local/ to create more space
run: |2
from pathlib import Path
for child in Path('/usr/local').rglob('*'):
try:
child.unlink()
except IsADirectoryError:
pass
shell: sudo -E python {0}
- name: Install Packages with Pip
run: pip install -r requirements.txt
- name: Set image variables
run: |2
printf -v IMAGE_ID '%s-%s' "${{ matrix.distribution }}" "${{ matrix.release }}"
printf -v IMAGE_PROFILE '%s.conf' "$IMAGE_ID"
printf -v IMAGE_VERSION '%(%Y-%m-%d)T' "-1"
printf -v IMAGE_NAME '%s_%s' "$IMAGE_ID" "$IMAGE_VERSION"
printf -v IMAGE_SOURCE_DATE_EPOCH '%d' "$(git log -n 1 --pretty=format:%cd --date=format:"%s")"
mapfile -t _VARIABLES < <(compgen -A variable)
for _var in "${_VARIABLES[@]}"; do
if [[ "$_var" =~ ^IMAGE_ ]]; then
printf '%s=%s\n' "$_var" "${!_var}"
fi
done >> "$GITHUB_OUTPUT"
printf 'PYTHONPATH=%s\n' "$(${{ steps.py3.outputs.python-path }} -m site --user-site)" >> "$GITHUB_OUTPUT"
id: variables
- name: Show build summary
run: |2
declare -a _args
_args+=("-m" "mkosi")
_args+=("--profile" "${{ steps.variables.outputs.IMAGE_PROFILE }}")
_args+=("--image-version" "${{ steps.variables.outputs.IMAGE_VERSION }}")
_args+=("--source-date-epoch" "${{ steps.variables.outputs.IMAGE_SOURCE_DATE_EPOCH }}")
${{ steps.py3.outputs.python-path }} "${_args[@]}" summary
${{ steps.py3.outputs.python-path }} "${_args[@]}" --json summary | jq '.Images[0]' > build_summary.json
shell: sudo -E bash -e {0}
env:
PYTHONPATH: "${{ steps.variables.outputs.PYTHONPATH }}"
- name: Parse build summary
uses: zoexx/github-action-json-file-properties@release
with:
file_path: build_summary.json
id: build_summary
# - name: Cache/Restore ${{ steps.build_summary.outputs.CacheDirectory }}
# uses: actions/cache@v4
# with:
# path: ${{ steps.build_summary.outputs.CacheDirectory }}
# key: ${{ steps.build_summary.outputs.Output }}-${{ steps.build_summary.outputs.CacheDirectory }}
# - name: Create ${{ steps.build_summary.outputs.CacheDirectory }}
# run: mkdir -p ${{ steps.build_summary.outputs.CacheDirectory }}
# - name: Cache/Restore ${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.ToolsTreeDistribution }}-tools
# uses: actions/cache@v4
# with:
# path: ${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.ToolsTreeDistribution }}-tools
# key: ${{ steps.build_summary.outputs.Output }}-${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.ToolsTreeDistribution }}-tools
# - name: Create ${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.ToolsTreeDistribution }}-tools
# run: mkdir -p ${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.ToolsTreeDistribution }}-tools
- name: Build image
run: >2
${{ steps.py3.outputs.python-path }} -m mkosi
--profile "${{ steps.variables.outputs.IMAGE_PROFILE }}"
--image-version "${{ steps.variables.outputs.IMAGE_VERSION }}"
--source-date-epoch "${{ steps.variables.outputs.IMAGE_SOURCE_DATE_EPOCH }}"
--force
build
shell: sudo -E bash -e {0}
env:
PYTHONPATH: "${{ steps.variables.outputs.PYTHONPATH }}"
- name: Convert Image
run: ./create_disk_image.sh
shell: sudo -E bash -e {0}
env:
IMAGE_ID: "${{ steps.build_summary.outputs.Output }}"
IMAGE_VERSION: "${{ steps.variables.outputs.IMAGE_VERSION }}"
OUTPUTDIR: "${{ steps.build_summary.outputs.OutputDirectory }}"
BUILDROOT: "${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.Output }}"
- name: "Remove ${{ steps.build_summary.outputs.Output }} to reclaim Disk Space"
run: rm -rf "${{ steps.build_summary.outputs.Output }}"
shell: sudo -E bash -e {0}
working-directory: "${{ steps.build_summary.outputs.OutputDirectory }}"
- name: Augment manifest
run: >2
${{ steps.py3.outputs.python-path }}
"${GITHUB_WORKSPACE}/augment_manifest.py"
"${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.Output }}.manifest"
- name: Get latest release manifest
uses: robinraju/[email protected]
with:
tag: latest-${{ steps.build_summary.outputs.Output }}
latest: false
preRelease: false
fileName: "*.manifest"
tarBall: false
zipBall: false
out-file-path: /tmp
continue-on-error: true
id: last_release
- name: Compare releases
id: do_releases_match
run: >2
${{steps.py3.outputs.python-path}}
"${GITHUB_WORKSPACE}/compare_manifests.py"
/tmp/*.manifest
"${{ steps.build_summary.outputs.Output }}.manifest"
working-directory: "${{ steps.build_summary.outputs.OutputDirectory }}"
if: steps.last_release.outcome == 'success'
- name: Split large files in ≤ 2 GiB chunks or they can't be uploaded to GitHub as a release
if: steps.do_releases_match.outputs.value == 'false' || steps.last_release.outcome != 'success'
run: |2
for ending in raw.zst qcow2; do
split --numeric-suffixes=1 --bytes="$((1024 * 1024 * 1024 * 1 ))" "${{ steps.build_summary.outputs.Output }}.${ending}" "${{ steps.build_summary.outputs.Output }}.${ending}.";
done
working-directory: "${{ steps.build_summary.outputs.OutputDirectory }}"
- name: Compute checksums
if: steps.do_releases_match.outputs.value == 'false' || steps.last_release.outcome != 'success'
run: sha512sum "${{ steps.build_summary.outputs.Output }}.manifest" "${{ steps.build_summary.outputs.Output }}.qcow2"* "${{ steps.build_summary.outputs.Output }}.raw.zst"* > "${{ steps.build_summary.outputs.Output }}.sha512"
working-directory: "${{ steps.build_summary.outputs.OutputDirectory }}"
- name: Clean previous release
if: steps.do_releases_match.outputs.value == 'false' && steps.last_release.outcome == 'success'
run: gh release delete latest-${{ steps.build_summary.outputs.Output }} --cleanup-tag --yes
env:
GH_TOKEN: ${{ github.token }}
- name: Release ${{ steps.build_summary.outputs.Output }}
if: steps.do_releases_match.outputs.value == 'false' || steps.last_release.outcome != 'success'
uses: softprops/action-gh-release@v2
with:
files: |2
${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.Output }}.sha512
${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.Output }}.manifest
${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.Output }}.qcow2.*
${{ steps.build_summary.outputs.OutputDirectory }}/${{ steps.build_summary.outputs.Output }}.raw.zst.*
name: ${{ steps.variables.outputs.IMAGE_NAME }}
tag_name: latest-${{ steps.build_summary.outputs.Output }}
make_latest: true
draft: false
# - name: Make ${{ steps.build_summary.outputs.CacheDirectory }} and ${{ steps.build_summary.outputs.OutputDirectory }} cachable for GitHub
# run: setfacl -R -m "u:runner:rwx" ${{ steps.build_summary.outputs.CacheDirectory }} ${{ steps.build_summary.outputs.OutputDirectory }}
# shell: sudo -E bash -e {0}
# if: always()