forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
240 lines (232 loc) · 9.67 KB
/
assets.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
# This workflow is much more convoluted than it should be (see a simpler
# version of it in git's history). The reason it is convoluted is that it
# kept timing out on any of the hosted runners so we're now trying to see
# if GitHub own runners are any better. Of course, GH only provides x86
# runners and thus (instead of a nice matrix job of amd64, arm64) we have
# to "emulated" arm64 side on the amd64 runner.
#
# The trick we play is that we keep it as a matrix job still, but we make
# it use the same GitHub provided x86 ubuntu-20.04 runners. The runner that
# gets to unpack arm64 artifacts does so with the help of binfmt-support and
# qemu-user-static
---
name: Assets
on: # yamllint disable-line rule:truthy
workflow_run:
workflows:
- Publish
types:
- completed
branches:
- "master"
- "[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+-stable"
- "[0-9]+.[0-9]+-lts"
jobs:
build:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
arch: [amd64, arm64]
steps:
- name: checkout repo
uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Force fetch annotated tags (workaround)
# Workaround for https://github.com/actions/checkout/issues/290
run: |
git fetch --force --tags
- name: Determine architecture prefix and ref
env:
REF: ${{ github.event.workflow_run.head_branch }}
run: |
# FIXME: I'd rather be a real matrix job with a functional arm64 runner
# echo "ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" >> "$GITHUB_ENV"
APT_INSTALL="sudo apt install -y binfmt-support qemu-user-static"
# the following weird statement is here to speed up the happy path
# if the default server is responding -- we can skip apt update
$APT_INSTALL || { sudo apt update && $APT_INSTALL ; }
echo "ARCH=${{ matrix.arch }}" >> "$GITHUB_ENV"
echo "TAG=$(git describe --always --tags | grep -E '[0-9]*\.[0-9]*\.[0-9]*' || echo snapshot)" >> "$GITHUB_ENV"
- name: ensure clean assets dir
run: |
rm -rf assets && mkdir -p assets
- name: Pull the EVE release from DockerHUB or build it
run: |
HV=kvm
if [ "${{ github.event.repository.full_name }}" = "lf-edge/eve" ]; then
EVE=lfedge/eve:${{ env.TAG }}-${HV}-${{ env.ARCH }}
docker pull "$EVE"
else
make pkgs
make HV=${HV} ZARCH=${{ env.ARCH }} eve
EVE=lfedge/eve:$(make version)-${HV}-${{ env.ARCH }}
fi
docker run "$EVE" rootfs > assets/rootfs.img
docker run "$EVE" installer_net | tar -C assets -xvf -
- name: Create direct iPXE config
run: |
URL="${{ github.event.repository.html_url }}/releases/download/${{ env.TAG }}/${{ env.ARCH }}."
sed -i. -e '/# set url https:/s#^.*$#set url '"$URL"'#' assets/ipxe.efi.cfg
for comp in initrd rootfs installer; do
sed -i. -e "s#initrd=${comp}#initrd=${{ env.ARCH }}.${comp}#g" assets/ipxe.efi.cfg
done
sed -e 's#{mac:hexhyp}#{ip}#' < assets/ipxe.efi.cfg > assets/ipxe.efi.ip.cfg
- name: Unzip kernel on arm64
run: |
# FIXME: stock iPXE doesn't support compressed kernels on arm64.
# EVE's iPXE does, but we still haven't quite figured out the
# hand-off part between the two. Therefore for now unpack the kernel.
if [ "${{ env.ARCH }}" = arm64 ]; then
mv assets/kernel assets/kernel.gz
gzip -d assets/kernel.gz
fi
- name: Pull eve-sources and publish collected_sources.tar.gz to assets
run: |
HV=kvm
EVE_SOURCES=lfedge/eve-sources:${{ env.TAG }}-${HV}-${{ env.ARCH }}
docker pull "$EVE_SOURCES"
docker create --name eve_sources "$EVE_SOURCES" bash
docker export --output assets/collected_sources.tar.gz eve_sources
docker rm eve_sources
- name: Create a GitHub release and clean up artifacts
id: create-release
uses: actions/github-script@v3
with:
result-encoding: string
script: |
console.log(context)
tag = '${{ env.TAG }}'
// first create a release -- it is OK if that fails,
// since it means the release is already there
try {
const raw = (await github.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: 'Release ' + tag,
prerelease: true,
})).data
console.log(raw)
} catch (e) {}
// get the release ID
const release = (await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag,
})).data
// get assets for that ID
const assets = (await github.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
})).data
// remove all assets (since we will be uploading new ones)
// note that we only consider assets coming from the same
// architecture we're running on -- this is because GH
// release assets can only be flat (no folders allowed)
if (Array.isArray(assets) && assets.length > 0) {
for (const asset of assets) {
if (asset.name.startsWith('${{ env.ARCH }}')) {
await github.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: asset.id,
})
}
}
}
return release.upload_url
- name: Upload rootfs for the release
id: upload-rootfs-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/rootfs.img
asset_name: ${{ env.ARCH }}.rootfs.img
asset_content_type: application/octet-stream
- name: Upload kernel for the release
id: upload-kernel-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/kernel
asset_name: ${{ env.ARCH }}.kernel
asset_content_type: application/octet-stream
- name: Upload installer.img for the release
id: upload-installer-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/installer.img
asset_name: ${{ env.ARCH }}.installer.img
asset_content_type: application/octet-stream
- name: Upload initrd.img for the release
id: upload-initrd-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/initrd.img
asset_name: ${{ env.ARCH }}.initrd.img
asset_content_type: application/octet-stream
- name: Upload initrd.bits for the release
id: upload-initrd-bits-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/initrd.bits
asset_name: ${{ env.ARCH }}.initrd.bits
asset_content_type: application/octet-stream
- name: Upload ipxe.efi for the release
id: upload-ipxe-efi-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/ipxe.efi
asset_name: ${{ env.ARCH }}.ipxe.efi
asset_content_type: application/octet-stream
- name: Upload ipxe.efi.cfg for the release
id: upload-ipxe-efi-cfg-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/ipxe.efi.cfg
asset_name: ${{ env.ARCH }}.ipxe.efi.cfg
asset_content_type: application/octet-stream
- name: Upload ipxe.efi.ip.cfg for the release
id: upload-ipxe-efi-ip-cfg-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/ipxe.efi.ip.cfg
asset_name: ${{ env.ARCH }}.ipxe.efi.ip.cfg
asset_content_type: application/octet-stream
- name: Upload COLLECTED_SOURCES
id: upload-collected-sources-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.result }}
asset_path: assets/collected_sources.tar.gz
asset_name: ${{ env.ARCH }}.collected_sources.tar.gz
asset_content_type: application/octet-stream