Skip to content

Commit ea3d5d2

Browse files
committed
Moving assets upload into a separate workflow
Signed-off-by: Roman Shaposhnik <rvs@zededa.com>
1 parent 7a8d702 commit ea3d5d2

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

.github/workflows/assets.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
name: Assets
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Publish
7+
types:
8+
- completed
9+
10+
jobs:
11+
build:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ARM64, ubuntu-20.04]
17+
steps:
18+
- name: Determine architecture prefix and ref
19+
env:
20+
REF: ${{ github.ref }}
21+
run: |
22+
echo "ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" >> "$GITHUB_ENV"
23+
echo "TAG=$(echo "$REF" | sed -e 's#^.*/##' -e 's#master#snapshot#' -e 's#main#snapshot#')" >> "$GITHUB_ENV"
24+
- name: Pull the release from DockerHUB
25+
run: |
26+
EVE=lfedge/eve:${{ env.TAG }}-xen-${{ env.ARCH }}
27+
docker pull "$EVE"
28+
rm -rf assets && mkdir assets && cd assets
29+
docker run "$EVE" rootfs > rootfs.img
30+
docker run "$EVE" installer_net | tar -xvf -
31+
- name: Create direct iPXE config
32+
run: |
33+
URL="https://github.com/lf-edge/eve/releases/download/${{ env.TAG }}/${{ env.ARCH }}."
34+
sed -i. -e "s#^kernel #kernel $URL#" -e "s#^initrd #initrd $URL#" assets/ipxe.efi.cfg
35+
sed -e 's#{mac:hexhyp}#{ip}#' < assets/ipxe.efi.cfg > assets/ipxe.efi.ip.cfg
36+
- name: Create a GitHub release and clean up artifacts
37+
id: create-release
38+
uses: actions/github-script@v3
39+
with:
40+
result-encoding: string
41+
script: |
42+
console.log(context)
43+
tag = ${{ env.TAG }}
44+
45+
// first create a release -- it is OK if that fails,
46+
// since it means the release is already there
47+
try {
48+
const raw = (await github.repos.createRelease({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
tag_name: tag,
52+
name: 'Release ' + tag,
53+
prerelease: true,
54+
})).data
55+
console.log(raw)
56+
} catch (e) {}
57+
58+
// get the release ID
59+
const release = (await github.repos.getReleaseByTag({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
tag: tag,
63+
})).data
64+
65+
// get assets for that ID
66+
const assets = (await github.repos.listReleaseAssets({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
release_id: release.id,
70+
})).data
71+
72+
// remove all assets (since we will be uploading new ones)
73+
// note that we only consider assets coming from the same
74+
// architecture we're running on -- this is because GH
75+
// release assets can only be flat (no folders allowed)
76+
if (Array.isArray(assets) && assets.length > 0) {
77+
for (const asset of assets) {
78+
if (asset.name.startsWith('${{ env.ARCH }}')) {
79+
await github.repos.deleteReleaseAsset({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
asset_id: asset.id,
83+
})
84+
}
85+
}
86+
}
87+
88+
return release.upload_url
89+
90+
- name: Upload rootfs for the release
91+
id: upload-release-asset
92+
uses: actions/upload-release-asset@v1
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
with:
96+
upload_url: ${{ steps.create-release.outputs.result }}
97+
asset_path: assets/rootfs.img
98+
asset_name: ${{ env.ARCH }}.rootfs.img
99+
asset_content_type: application/octet-stream
100+
- name: Upload kernel for the release
101+
id: upload-release-asset
102+
uses: actions/upload-release-asset@v1
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
with:
106+
upload_url: ${{ steps.create-release.outputs.result }}
107+
asset_path: assets/kernel
108+
asset_name: ${{ env.ARCH }}.kernel
109+
asset_content_type: application/octet-stream
110+
- name: Upload initrd.img for the release
111+
id: upload-release-asset
112+
uses: actions/upload-release-asset@v1
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
with:
116+
upload_url: ${{ steps.create-release.outputs.result }}
117+
asset_path: assets/initrd.img
118+
asset_name: ${{ env.ARCH }}.initrd.img
119+
asset_content_type: application/octet-stream
120+
- name: Upload initrd.bits for the release
121+
id: upload-release-asset
122+
uses: actions/upload-release-asset@v1
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
with:
126+
upload_url: ${{ steps.create-release.outputs.result }}
127+
asset_path: assets/initrd.bits
128+
asset_name: ${{ env.ARCH }}.initrd.bits
129+
asset_content_type: application/octet-stream
130+
- name: Upload ipxe.efi.cfg for the release
131+
id: upload-release-asset
132+
uses: actions/upload-release-asset@v1
133+
env:
134+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
with:
136+
upload_url: ${{ steps.create-release.outputs.result }}
137+
asset_path: assets/ipxe.efi.cfg
138+
asset_name: ${{ env.ARCH }}.ipxe.efi.cfg
139+
asset_content_type: application/octet-stream
140+
- name: Upload ipxe.efi.ip.cfg for the release
141+
id: upload-release-asset
142+
uses: actions/upload-release-asset@v1
143+
env:
144+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145+
with:
146+
upload_url: ${{ steps.create-release.outputs.result }}
147+
asset_path: assets/ipxe.efi.ip.cfg
148+
asset_name: ${{ env.ARCH }}.ipxe.efi.ip.cfg
149+
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)