Skip to content

Commit

Permalink
build: simplify rebuild checker
Browse files Browse the repository at this point in the history
  • Loading branch information
yacoob committed Nov 28, 2024
1 parent 44e2533 commit 0cc3685
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/maybe-build-yaucore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ jobs:
SIGNING_SECRET: ${{ secrets.SIGNING_SECRET }}
uses: ./.github/workflows/maybe-build.yaml
with:
base: ublue-os/ucore-hci:stable
derivative: yacoob/yaucore:latest
image: yacoob/yaucore:latest
recipe: yaucore.yaml
3 changes: 1 addition & 2 deletions .github/workflows/maybe-build-yaurora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ jobs:
SIGNING_SECRET: ${{ secrets.SIGNING_SECRET }}
uses: ./.github/workflows/maybe-build.yaml
with:
base: ublue-os/aurora-dx:stable
derivative: yacoob/yaurora:latest
image: yacoob/yaurora:latest
recipe: yaurora.yaml
45 changes: 16 additions & 29 deletions .github/workflows/maybe-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,36 @@ name: Check if we need to build a new image due to the base image update
on:
workflow_call:
inputs:
base:
description: Base image (user/name:tag) to check for updates
required: true
type: string
derivative:
description: My image (user/name:tag) to compare against
image:
description: Image (user/name:tag) to check
required: true
type: string
recipe:
description: Recipe file to use for the build
required: true
type: string
secrets:
SIGNING_SECRET:
required: true

jobs:
check:
name: Check if there's a new version of the base image
runs-on: ubuntu-latest
outputs:
needs_rebuild: ${{ steps.maybe-build.conclusion == 'success' }}
needs_rebuild: ${{ steps.compare.outputs.verdict == 'true' }}
steps:
- name: Get SHA of the latest ${{ inputs.base }} present in the repository
id: registry
run: |
REGISTRY_SHA=$(skopeo inspect docker://ghcr.io/${{ inputs.base }} | jq '.Digest' )
echo "SHA=$REGISTRY_SHA" >> $GITHUB_OUTPUT
- name: Get SHA of the latest ${{ inputs.derivative }} present in the repository
id: last-build
run: |
LAST_BUILD_SHA=$(skopeo inspect docker://ghcr.io/${{ inputs.derivative }} | jq '.Labels."org.opencontainers.image.base.digest"')
echo "SHA=$LAST_BUILD_SHA" >> $GITHUB_OUTPUT
- name: Output gathered information
id: debug-output
run: |
echo "${{ inputs.base }} is currently at [${{ steps.registry.outputs.SHA }}]"
echo "${{ inputs.derivative }} has last been built at ${{ inputs.base }}'s: [${{ steps.last-build.outputs.SHA }}]"
- name: Decide that we need a new build
id: maybe-build
if: steps.last-build.outputs.SHA != steps.registry.outputs.SHA
- name: Interrogate docker repository about ${{ inputs.image }}
id: compare
run: |
echo "Verdict: ${{ inputs.derivative }} needs to be rebuilt"
LATEST_BUILD_BASE_SHA=$(skopeo inspect docker://ghcr.io/${{ inputs.image }} | jq -r '.Labels."org.opencontainers.image.base.digest"')
BASE_IMAGE=$(skopeo inspect docker://ghcr.io/${{ inputs.image }} | jq -r '.Labels."org.opencontainers.image.base.name"')
LATEST_BASE_SHA=$(skopeo inspect docker://${BASE_IMAGE} | jq -r '.Digest' )
echo "Digest of ${BASE_IMAGE} from which latest ${{ inputs.image }} was built: [${LATEST_BUILD_BASE_SHA}]" >> ${GITHUB_OUTPUT}
echo "${BASE_IMAGE} is currently at [${LATEST_BASE_SHA}]" >> ${GITHUB_OUTPUT}
VERDICT=$([ "${LATEST_BUILD_BASE_SHA}" != "${LATEST_BASE_SHA}" ] && echo "true" || echo "false")
echo "## Rebuild needed: ${VERDICT}" >> ${GITHUB_STEP_SUMMARY}
echo "verdict=${VERDICT}" >> ${GITHUB_OUTPUT}
build:
permissions:
Expand Down

0 comments on commit 0cc3685

Please sign in to comment.