CI #634
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
--- | |
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() |