Skip to content

Commit

Permalink
extract metadata to its own reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
p5 committed Dec 21, 2024
1 parent d835f41 commit 0d5e879
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 65 deletions.
75 changes: 10 additions & 65 deletions .github/workflows/build-kinoite-40.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,20 @@ env:

jobs:
generate_metadata:
runs-on: ubuntu-latest
outputs:
BUILD_ARGS: ${{ steps.set-metadata.outputs.BUILD_ARGS }}
TAGS: ${{ steps.set-metadata.outputs.TAGS }}
IMAGE_REGISTRY: ${{ steps.set-metadata.outputs.IMAGE_REGISTRY }}
IMAGE_NAME: ${{ steps.set-metadata.outputs.IMAGE_NAME }}
steps:
- name: Fetch Kernel Version
id: fetch-kernel-version
run: |
KERNEL_VERSION=$(skopeo inspect docker://${IMAGE_REGISTRY}/main-kernel:${FEDORA_VERSION} | jq -r '.Labels["ostree.linux"]')
echo "KERNEL_VERSION=${KERNEL_VERSION}" >> $GITHUB_OUTPUT
- name: Generate Tags
id: generate-tags
env:
IS_LATEST_VERSION: false
IS_GTS_VERSION: true
IS_BETA_VERSION: false
run: |
TIMESTAMP="$(date +%Y%m%d)"
SHA_SHORT="${GITHUB_SHA::7}"
TAGS=()
TAGS+=("${FEDORA_VERSION}")
if [[ "${IS_LATEST_VERSION}" == "true" ]]; then
TAGS+=("latest")
elif [[ "${IS_GTS_VERSION}" == "true" ]]; then
TAGS+=("gts")
elif [[ "${IS_BETA_VERSION}" == "true" ]]; then
TAGS+=("beta")
fi
for TAG in "${TAGS[@]}"; do
TAGS+=("${TAG}-${TIMESTAMP}")
done
for TAG in "${TAGS[@]}"; do
TAGS+=("${TAG}-${SHA_SHORT}")
done
echo "TAGS=$(IFS=,; echo "${TAGS[*]}")" >> $GITHUB_OUTPUT
- name: Set Metadata
id: set-metadata
env:
KERNEL_VERSION: ${{ steps.fetch-kernel-version.outputs.KERNEL_VERSION }}
TAGS: ${{ steps.generate-tags.outputs.TAGS }}
run: |
BUILD_ARGS=()
BUILD_ARGS+=("KERNEL_VERSION=${KERNEL_VERSION}")
BUILD_ARGS+=("SOURCE_IMAGE=${SOURCE_IMAGE}")
BUILD_ARGS+=("FEDORA_MAJOR_VERSION=${FEDORA_VERSION}")
BUILD_ARGS+=("IMAGE_NAME=${IMAGE_NAME}")
echo "BUILD_ARGS=$(IFS=,; echo "${BUILD_ARGS[*]}")" >> $GITHUB_OUTPUT
echo "TAGS=$TAGS" >> $GITHUB_OUTPUT
echo "IMAGE_REGISTRY=${IMAGE_REGISTRY}" >> $GITHUB_OUTPUT
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_OUTPUT
uses: ./.github/workflows/reusable-generate-metadata.yml
with:
fedora-version: ${{ env.FEDORA_VERSION }}
image-registry: ${{ env.IMAGE_REGISTRY }}
image-name: ${{ env.IMAGE_NAME }}
is-gts: true

build:
uses: ./.github/workflows/reusable-build.yml
needs: generate_metadata
secrets: inherit
with:
image-registry: ${{ needs.generate_metadata.outputs.IMAGE_REGISTRY }}
image-name: ${{ needs.generate_metadata.outputs.IMAGE_NAME }}
image-registry: ${{ needs.generate_metadata.outputs.image-registry }}
image-name: ${{ needs.generate_metadata.outputs.image-name }}
platforms: amd64, arm64
build-args: ${{ needs.generate_metadata.outputs.BUILD_ARGS }}
tags: ${{ needs.generate_metadata.outputs.TAGS }}
build-args: ${{ needs.generate_metadata.outputs.build-args }}
tags: ${{ needs.generate_metadata.outputs.tags }}
86 changes: 86 additions & 0 deletions .github/workflows/reusable-generate-metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Generate Metadata

on:
workflow_call:
inputs:
fedora-version:
description: "The version of Fedora to build"
required: true
type: string
image-registry:
description: "The registry to push the image to"
required: true
type: string
image-name:
description: "The name of the image to build"
required: true
type: string
is-latest:
description: "Is this the latest version"
required: false
type: boolean
default: false
is-gts:
description: "Is this a GTS version"
required: false
type: boolean
default: false
is-beta:
description: "Is this a beta version"
required: false
type: boolean
default: false
outputs:
image-registry:
description: "The registry to push the image to"
value: ${{ inputs.image-registry }}
image-name:
description: "The name of the image to build"
value: ${{ inputs.image-name }}
build-args:
description: "The build arguments to pass to the build"
value: ${{ steps.set-metadata.outputs.BUILD_ARGS }}
tags:
description: "The tags to apply to the image"
value: ${{ steps.generate-tags.outputs.TAGS }}

jobs:
generate_metadata:
runs-on: ubuntu-latest
steps:
- name: Fetch Kernel Version
id: fetch-kernel-version
run: |
KERNEL_VERSION=$(skopeo inspect docker://${IMAGE_REGISTRY}/main-kernel:${FEDORA_VERSION} | jq -r '.Labels["ostree.linux"]')
echo "KERNEL_VERSION=${KERNEL_VERSION}" >> $GITHUB_OUTPUT
- name: Generate Tags
id: generate-tags
env:
IS_LATEST_VERSION: ${{ inputs.is-latest }}
IS_GTS_VERSION: ${{ inputs.is-gts }}
IS_BETA_VERSION: ${{ inputs.is-beta }}
run: |
TIMESTAMP="$(date +%Y%m%d)"
SHA_SHORT="${GITHUB_SHA::7}"
TAGS=()
TAGS+=("${FEDORA_VERSION}")
if [[ "${IS_LATEST_VERSION}" == "true" ]]; then
TAGS+=("latest")
elif [[ "${IS_GTS_VERSION}" == "true" ]]; then
TAGS+=("gts")
elif [[ "${IS_BETA_VERSION}" == "true" ]]; then
TAGS+=("beta")
fi
for TAG in "${TAGS[@]}"; do
TAGS+=("${TAG}-${TIMESTAMP}")
done
for TAG in "${TAGS[@]}"; do
TAGS+=("${TAG}-${SHA_SHORT}")
done
echo "TAGS=$(IFS=,; echo "${TAGS[*]}")" >> $GITHUB_OUTPUT

0 comments on commit 0d5e879

Please sign in to comment.