mirror of
https://github.com/ublue-os/akmods.git
synced 2026-11-03 14:59:42 -09:00
285 lines
10 KiB
YAML
285 lines
10 KiB
YAML
name: build-ublue
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
fedora_version:
|
|
description: 'The Fedora release version: 38, 39, 40, etc'
|
|
required: true
|
|
type: string
|
|
env:
|
|
IMAGE_BASE_NAME: akmods
|
|
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}-${{ inputs.fedora_version }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build_ublue:
|
|
name: akmods
|
|
runs-on: ubuntu-22.04
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
fedora_version:
|
|
- ${{ inputs.fedora_version }}
|
|
kernel_flavor:
|
|
- main
|
|
- asus
|
|
- fsync
|
|
- fsync-lts
|
|
- surface
|
|
cfile_suffix:
|
|
- common
|
|
- extra
|
|
- nvidia
|
|
exclude:
|
|
- kernel_flavor: asus
|
|
fedora_version: 38
|
|
- kernel_flavor: surface
|
|
fedora_version: 38
|
|
- fedora_version: 38
|
|
kernel_flavor: fsync # kernel-fsync not required for ublue-os F38
|
|
- fedora_version: 38
|
|
kernel_flavor: fsync-lts
|
|
- fedora_version: 40
|
|
kernel_flavor: fsync-lts # kernel-ba packages are not being built for F40 yet.
|
|
steps:
|
|
# Checkout push-to-registry action GitHub repository
|
|
- name: Checkout Push to Registry action
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Matrix Variables
|
|
shell: bash
|
|
run: |
|
|
if [ "common" == "${{ matrix.cfile_suffix }}" ]; then
|
|
echo "IMAGE_NAME=${{ env.IMAGE_BASE_NAME }}" >> $GITHUB_ENV
|
|
else
|
|
echo "IMAGE_NAME=${{ env.IMAGE_BASE_NAME }}-${{ matrix.cfile_suffix }}" >> $GITHUB_ENV
|
|
fi
|
|
export SOURCE_IMAGE=base
|
|
export SOURCE_ORG=fedora-ostree-desktops
|
|
echo "SOURCE_IMAGE=${SOURCE_IMAGE}" >> $GITHUB_ENV
|
|
echo "SOURCE_ORG=${SOURCE_ORG}" >> $GITHUB_ENV
|
|
echo "FQ_SOURCE_IMAGE=quay.io/${SOURCE_ORG}/${SOURCE_IMAGE}:${{ matrix.fedora_version }}" >> $GITHUB_ENV
|
|
|
|
|
|
- name: Generate tags
|
|
id: generate-tags
|
|
shell: bash
|
|
run: |
|
|
# Generate a timestamp for creating an image version history
|
|
TIMESTAMP="$(date +%Y%m%d)"
|
|
VARIANT="${{ matrix.kernel_flavor }}-${{ matrix.fedora_version }}"
|
|
|
|
COMMIT_TAGS=()
|
|
BUILD_TAGS=()
|
|
|
|
# Have tags for tracking builds during pull request
|
|
SHA_SHORT="${GITHUB_SHA::7}"
|
|
COMMIT_TAGS+=("pr-${{ github.event.number }}-${VARIANT}")
|
|
COMMIT_TAGS+=("${SHA_SHORT}-${VARIANT}")
|
|
|
|
BUILD_TAGS=("${VARIANT}" "${VARIANT}-${TIMESTAMP}")
|
|
|
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
|
echo "Generated the following commit tags: "
|
|
for TAG in "${COMMIT_TAGS[@]}"; do
|
|
echo "${TAG}"
|
|
done
|
|
|
|
alias_tags=("${COMMIT_TAGS[@]}")
|
|
else
|
|
alias_tags=("${BUILD_TAGS[@]}")
|
|
fi
|
|
|
|
echo "Generated the following build tags: "
|
|
for TAG in "${BUILD_TAGS[@]}"; do
|
|
echo "${TAG}"
|
|
done
|
|
|
|
echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Retrieve akmods signing key
|
|
run: |
|
|
mkdir -p certs
|
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
|
echo "Using test signing key"
|
|
else
|
|
echo "${{ secrets.AKMOD_PRIVKEY_20230518 }}" > certs/private_key.priv
|
|
fi
|
|
# DEBUG: get character count of key
|
|
wc -c certs/private_key.priv
|
|
|
|
- name: Pull build image
|
|
uses: Wandalen/wretry.action@v3.4.0
|
|
with:
|
|
attempt_limit: 3
|
|
attempt_delay: 15000
|
|
command: |
|
|
# pull the base image used for FROM in containerfile so
|
|
# we can retry on that unfortunately common failure case
|
|
podman pull ${{ env.FQ_SOURCE_IMAGE }}
|
|
|
|
- name: Get current version
|
|
run: |
|
|
set -eo pipefail
|
|
|
|
# skopeo must always run to inspect image labels for build version
|
|
skopeo inspect docker://${{ env.FQ_SOURCE_IMAGE }} > inspect.json
|
|
ver=$(jq -r '.Labels["org.opencontainers.image.version"]' inspect.json)
|
|
if [ -z "$ver" ] || [ "null" = "$ver" ]; then
|
|
echo "inspected image version must not be empty or null"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "main" == "${{ matrix.kernel_flavor }}" ]; then
|
|
# main kernel_flavor: use ostree.linux to determine kernel version
|
|
linux=$(jq -r '.Labels["ostree.linux"]' inspect.json)
|
|
else
|
|
# other kernel_flavor: start container use dnf to find kernel version
|
|
container_name="fq-$(uuidgen)"
|
|
podman run --entrypoint /bin/bash --name "$container_name" -dt "${{ env.FQ_SOURCE_IMAGE }}"
|
|
podman exec $container_name rpm-ostree install dnf dnf-plugins-core
|
|
|
|
# Fetch kernel version
|
|
dnf="podman exec $container_name dnf"
|
|
case "${{ matrix.kernel_flavor }}" in
|
|
"asus")
|
|
$dnf copr enable -y lukenukem/asus-kernel
|
|
linux=$($dnf repoquery --repoid copr:copr.fedorainfracloud.org:lukenukem:asus-kernel --whatprovides kernel | tail -n1 | sed 's/.*://')
|
|
;;
|
|
"fsync")
|
|
$dnf copr enable -y sentry/kernel-fsync
|
|
linux=$($dnf repoquery --repoid copr:copr.fedorainfracloud.org:sentry:kernel-fsync --whatprovides kernel | tail -n1 | sed 's/.*://')
|
|
;;
|
|
"fsync-lts")
|
|
$dnf copr enable -y sentry/kernel-ba
|
|
linux=$($dnf repoquery --repoid copr:copr.fedorainfracloud.org:sentry:kernel-ba --whatprovides kernel | tail -n1 | sed 's/.*://')
|
|
;;
|
|
"main")
|
|
linux=$($dnf repoquery --whatprovides kernel | tail -n1 | sed 's/.*://')
|
|
;;
|
|
"surface")
|
|
$dnf config-manager --add-repo=https://pkg.surfacelinux.com/fedora/linux-surface.repo
|
|
linux=$($dnf repoquery --repoid linux-surface --whatprovides kernel-surface | tail -n1 | sed 's/.*://')
|
|
;;
|
|
*)
|
|
echo "unexpected kernel_flavor '${{ matrix.kernel_flavor }}' for dnf repoquery"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
if [ -z "$linux" ] || [ "null" = "$linux" ]; then
|
|
echo "inspected image linux version must not be empty or null"
|
|
exit 1
|
|
fi
|
|
echo "SOURCE_IMAGE_VERSION=$ver" >> $GITHUB_ENV
|
|
echo "KERNEL_VERSION=$linux" >> $GITHUB_ENV
|
|
|
|
# Build metadata
|
|
- name: Image Metadata
|
|
uses: docker/metadata-action@v5
|
|
id: meta
|
|
with:
|
|
images: |
|
|
${{ env.IMAGE_NAME }}
|
|
labels: |
|
|
org.opencontainers.image.title=${{ env.IMAGE_BASE_NAME }}
|
|
org.opencontainers.image.description=A caching layer for pre-built akmod RPMs
|
|
org.opencontainers.image.version=${{ env.SOURCE_IMAGE_VERSION }}
|
|
ostree.linux=${{ env.KERNEL_VERSION }}
|
|
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/main/README.md
|
|
io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/1728152?s=200&v=4
|
|
|
|
# Build image using Buildah action
|
|
- name: Build Image
|
|
id: build_image
|
|
uses: redhat-actions/buildah-build@v2
|
|
with:
|
|
containerfiles: |
|
|
./Containerfile.${{ matrix.cfile_suffix }}
|
|
image: ${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
${{ steps.generate-tags.outputs.alias_tags }}
|
|
build-args: |
|
|
SOURCE_IMAGE=${{ env.SOURCE_IMAGE }}
|
|
SOURCE_ORG=${{ env.SOURCE_ORG }}
|
|
KERNEL_FLAVOR=${{ matrix.kernel_flavor }}
|
|
KERNEL_VERSION=${{ env.KERNEL_VERSION }}
|
|
FEDORA_MAJOR_VERSION=${{ matrix.fedora_version }}
|
|
RPMFUSION_MIRROR=${{ vars.RPMFUSION_MIRROR }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
oci: false
|
|
|
|
# Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR.
|
|
# https://github.com/macbre/push-to-ghcr/issues/12
|
|
- name: Lowercase Registry
|
|
id: registry_case
|
|
uses: ASzc/change-string-case-action@v6
|
|
with:
|
|
string: ${{ env.IMAGE_REGISTRY }}
|
|
|
|
|
|
- name: Push To GHCR
|
|
uses: Wandalen/wretry.action@v3.4.0
|
|
id: push
|
|
if: github.event_name != 'pull_request'
|
|
env:
|
|
REGISTRY_USER: ${{ github.actor }}
|
|
REGISTRY_PASSWORD: ${{ github.token }}
|
|
with:
|
|
action: redhat-actions/push-to-registry@v2
|
|
attempt_limit: 3
|
|
attempt_delay: 15000
|
|
with: |
|
|
image: ${{ steps.build_image.outputs.image }}
|
|
tags: ${{ steps.build_image.outputs.tags }}
|
|
registry: ${{ steps.registry_case.outputs.lowercase }}
|
|
username: ${{ env.REGISTRY_USER }}
|
|
password: ${{ env.REGISTRY_PASSWORD }}
|
|
extra-args: |
|
|
--disable-content-trust
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
if: github.event_name != 'pull_request'
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
# Sign container
|
|
- uses: sigstore/cosign-installer@v3.5.0
|
|
if: github.event_name != 'pull_request'
|
|
|
|
- name: Sign container image
|
|
if: github.event_name != 'pull_request'
|
|
run: |
|
|
cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ steps.registry_case.outputs.lowercase }}/${{ steps.build_image.outputs.image }}@${TAGS}
|
|
env:
|
|
TAGS: ${{ steps.push.outputs.outputs && fromJSON(steps.push.outputs.outputs).digest }}
|
|
COSIGN_EXPERIMENTAL: false
|
|
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
|
|
|
|
- name: Echo outputs
|
|
if: github.event_name != 'pull_request'
|
|
run: |
|
|
echo "${{ toJSON(steps.push.outputs) }}"
|
|
|
|
check:
|
|
name: Check all ${{ inputs.fedora_version }} builds successful
|
|
runs-on: ubuntu-latest
|
|
needs: [build_ublue]
|
|
steps:
|
|
- name: Exit on failure
|
|
if: ${{ needs.build_ublue.result == 'failure' }}
|
|
shell: bash
|
|
run: exit 1
|
|
- name: Exit
|
|
shell: bash
|
|
run: exit 0
|