From df281aa62b79d5d6f44923ef8609510a56c85ff5 Mon Sep 17 00:00:00 2001 From: penguin Date: Mon, 8 Dec 2025 20:05:45 -0600 Subject: [PATCH] infra: image: build image for branches if they dont exist --- .gitea/workflows/gentoo-utils.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml index d75e875..70d77a0 100644 --- a/.gitea/workflows/gentoo-utils.yml +++ b/.gitea/workflows/gentoo-utils.yml @@ -14,28 +14,37 @@ 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 + echo "image_tag=$image_tag" >> $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 +52,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