infra: image: build image for branches if they dont exist
Some checks failed
Gentoo Utils / build-oci-image (push) Successful in 6m19s
Gentoo Utils / build (push) Failing after 0s

This commit is contained in:
2025-12-08 20:05:45 -06:00
parent e9da4fbf62
commit bfb0c50ab0

View File

@@ -14,28 +14,38 @@ jobs:
- name: Check for changes before building
id: image-changes
# build image only if 1. changes are detected or 2. an image for the working branch doesnt exist
run: |
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
echo "branch_name=$branch_name" >> $GITEA_OUTPUT
if [[ "$branch_name" == "${{ gitea.event.repository.default_branch }}" ]]; then
echo "image_tag=latest" >> $GITEA_OUTPUT
image_tag=latest
else
echo "image_tag=$branch_name" >> $GITEA_OUTPUT
image_tag=$branch_name
fi
echo "branch_name=$branch_name" >> $GITEA_OUTPUT
# slugify
echo "image_tag=$(echo "$image_tag" | sed -E 's/[^a-zA-Z0-9]/-/g')" >> $GITEA_OUTPUT
if ! git diff ${{ gitea.event.before }} ${{ gitea.sha }} --no-patch --exit-code .docker; then
echo changes_detected=true >> $GITEA_OUTPUT
build_image=true
else
echo changes_detected=false >> $GITEA_OUTPUT
if ! docker manifest inspect git.epenguin.net/${{ gitea.repository }}:${image_tag} >/dev/null 2>&1; then
build_image=true
else
build_image=false
fi
fi
echo "build_image=$build_image" >> $GITEA_OUTPUT
cat $GITEA_OUTPUT
- name: Set up Docker buildx
if: steps.image-changes.outputs.changes_detected == 'true'
if: steps.image-changes.outputs.build_image == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to Github Container Registry
if: steps.image-changes.outputs.changes_detected == 'true'
if: steps.image-changes.outputs.build_image == 'true'
uses: docker/login-action@v3
with:
registry: git.epenguin.net
@@ -43,7 +53,7 @@ jobs:
password: ${{ secrets.CI_BOT_TOKEN }}
- name: Build and push
if: steps.image-changes.outputs.changes_detected == 'true'
if: steps.image-changes.outputs.build_image == 'true'
uses: docker/build-push-action@v6
with:
push: true