-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving assets upload into a separate workflow
Signed-off-by: Roman Shaposhnik <rvs@zededa.com>
- Loading branch information
Showing
1 changed file
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
--- | ||
name: Assets | ||
on: | ||
workflow_run: | ||
workflows: | ||
- Publish | ||
types: | ||
- completed | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ARM64, ubuntu-20.04] | ||
steps: | ||
- name: Determine architecture prefix and ref | ||
env: | ||
REF: ${{ github.ref }} | ||
run: | | ||
echo "ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" >> "$GITHUB_ENV" | ||
echo "TAG=$(echo "$REF" | sed -e 's#^.*/##' -e 's#master#snapshot#' -e 's#main#snapshot#')" >> "$GITHUB_ENV" | ||
- name: Pull the release from DockerHUB | ||
run: | | ||
EVE=lfedge/eve:${{ env.TAG }}-xen-${{ env.ARCH }} | ||
docker pull "$EVE" | ||
rm -rf assets && mkdir assets && cd assets | ||
docker run "$EVE" rootfs > rootfs.img | ||
docker run "$EVE" installer_net | tar -xvf - | ||
- name: Create direct iPXE config | ||
run: | | ||
URL="https://github.com/lf-edge/eve/releases/download/${{ env.TAG }}/${{ env.ARCH }}." | ||
sed -i. -e "s#^kernel #kernel $URL#" -e "s#^initrd #initrd $URL#" assets/ipxe.efi.cfg | ||
sed -e 's#{mac:hexhyp}#{ip}#' < assets/ipxe.efi.cfg > assets/ipxe.efi.ip.cfg | ||
- 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-release-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-release-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 initrd.img for the release | ||
id: upload-release-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-release-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.cfg for the release | ||
id: upload-release-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-release-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 |