From bd27a84414aa917dbf4940defa062d9886164972 Mon Sep 17 00:00:00 2001 From: RJ Trujillo Date: Tue, 19 Sep 2023 23:33:33 -0600 Subject: [PATCH] feat(ci): Split build for Fedora 38 and 39 (#67) --- .github/workflows/build.yml | 62 +++++++++++++++++++++++++++++-------- Containerfile | 4 ++- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7467df..7f1fd11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,11 +1,11 @@ name: build development package on: pull_request: - merge_group: + merge_group: push: branches: - main - workflow_dispatch: + workflow_dispatch: env: IMAGE_NAME: ublue-update IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} @@ -18,7 +18,18 @@ jobs: contents: read packages: write id-token: write - steps: + strategy: + fail-fast: false + matrix: + major_version: [38, 39] + include: + - major_version: 38 + is_latest_version: true + is_stable_version: true + - major_version: 39 + is_latest_version: true + is_stable_version: false + steps: # Checkout push-to-registry action GitHub repository - name: Checkout Push to Registry action uses: actions/checkout@v4 @@ -27,16 +38,41 @@ jobs: id: generate-tags shell: bash run: | - echo "sha_short=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT - alias_tags=() - # Only perform the follow code when the action is spawned from a Pull Request + # Generate a timestamp for creating an image version history + TIMESTAMP="$(date +%Y%m%d)" + MAJOR_VERSION="${{ matrix.major_version }}" + COMMIT_TAGS=() + BUILD_TAGS=() + # Have tags for tracking builds during pull request + SHA_SHORT="${GITHUB_SHA::7}" + COMMIT_TAGS+=("pr-${{ github.event.pull_request.number }}-${MAJOR_VERSION}") + COMMIT_TAGS+=("${SHA_SHORT}-${MAJOR_VERSION}") + if [[ "${{ matrix.is_latest_version }}" == "true" ]] && \ + [[ "${{ matrix.is_stable_version }}" == "true" ]]; then + COMMIT_TAGS+=("pr-${{ github.event.pull_request.number }}") + COMMIT_TAGS+=("${SHA_SHORT}") + fi + + BUILD_TAGS=("${MAJOR_VERSION}" "${MAJOR_VERSION}-${TIMESTAMP}") + + if [[ "${{ matrix.is_latest_version }}" == "true" ]] && \ + [[ "${{ matrix.is_stable_version }}" == "true" ]]; then + BUILD_TAGS+=("latest") + fi + if [[ "${{ github.event_name }}" == "pull_request" ]]; then - alias_tags+=("pr-${{ github.event.number }}") + echo "Generated the following commit tags: " + for TAG in "${COMMIT_TAGS[@]}"; do + echo "${TAG}" + done + alias_tags=("${COMMIT_TAGS[@]}") else - # The following is run when the timer is triggered or a merge/push to main - echo "date=$(date +%Y%m%d)" >> $GITHUB_OUTPUT - alias_tags+=("latest") + 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 # Build image using Buildah action @@ -49,8 +85,8 @@ jobs: image: ${{ env.IMAGE_NAME }} tags: | ${{ steps.generate-tags.outputs.alias_tags }} - ${{ steps.generate-tags.outputs.date }} - ${{ steps.generate-tags.outputs.sha_short }} + build-args: | + FEDORA_MAJOR_VERSION=${{ matrix.major_version }} oci: true # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. @@ -103,7 +139,7 @@ jobs: if: github.event_name != 'pull_request' run: | echo "${{ toJSON(steps.push.outputs) }}" - + copr-build: permissions: contents: read diff --git a/Containerfile b/Containerfile index 1c46466..d5af966 100644 --- a/Containerfile +++ b/Containerfile @@ -1,4 +1,6 @@ -FROM registry.fedoraproject.org/fedora:latest AS builder +ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}" + +FROM registry.fedoraproject.org/fedora:${FEDORA_MAJOR_VERSION} AS builder ENV UBLUE_ROOT=/app/output