From 888b9cce7f8ecd8595d1d795b0a638bed72762c0 Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Sat, 1 Nov 2025 22:23:18 +0100 Subject: [PATCH] ci: improve build job conditional execution in workflow - Replace job-level if condition with env variable for better control - Add conditional checks to all build steps - Add skip step when build not required - Simplify deploy-staging conditions --- .gitea/workflows/build-image.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/build-image.yml b/.gitea/workflows/build-image.yml index faf4603a..44cc55a4 100644 --- a/.gitea/workflows/build-image.yml +++ b/.gitea/workflows/build-image.yml @@ -472,14 +472,21 @@ jobs: build: name: Build Docker Image needs: [changes, runtime-base] - if: always() && needs.changes.outputs.needs_build == 'true' runs-on: docker-build + env: + SHOULD_BUILD: ${{ needs.changes.outputs.needs_build }} outputs: image_tag: ${{ steps.image_info.outputs.IMAGE_TAG }} commit_sha: ${{ steps.meta.outputs.commit_sha }} image_url: ${{ steps.image_info.outputs.IMAGE_URL }} steps: + - name: Skip build when not required + if: ${{ env.SHOULD_BUILD != 'true' }} + run: | + echo "ℹ️ Container build not required – using latest published image" + - name: Install git and setup environment + if: ${{ env.SHOULD_BUILD == 'true' }} shell: sh run: | if ! command -v bash >/dev/null 2>&1 || ! command -v git >/dev/null 2>&1; then @@ -489,6 +496,7 @@ jobs: git --version - name: Download CI helpers + if: ${{ env.SHOULD_BUILD == 'true' }} shell: bash env: CI_TOKEN: ${{ secrets.CI_TOKEN }} @@ -511,6 +519,7 @@ jobs: chmod +x /tmp/ci-tools/clone_repo.sh - name: Checkout code + if: ${{ env.SHOULD_BUILD == 'true' }} shell: bash run: | REF_NAME="${{ github.ref_name }}" @@ -530,6 +539,7 @@ jobs: cd /workspace/repo - name: Setup Docker Buildx + if: ${{ env.SHOULD_BUILD == 'true' }} shell: bash run: | docker buildx version || echo "Buildx nicht gefunden" @@ -553,6 +563,7 @@ jobs: docker buildx ls - name: Generate image metadata + if: ${{ env.SHOULD_BUILD == 'true' }} id: meta run: | cd /workspace/repo @@ -568,6 +579,7 @@ jobs: echo "Generated tag: ${TAG}" - name: Login to Registry + if: ${{ env.SHOULD_BUILD == 'true' }} id: login shell: bash run: | @@ -642,6 +654,7 @@ jobs: echo "CACHE_REGISTRY=$CANONICAL_REGISTRY" >> $GITHUB_ENV - name: Determine runtime base image + if: ${{ env.SHOULD_BUILD == 'true' }} id: runtime-image shell: bash run: | @@ -678,6 +691,7 @@ jobs: echo "🏗️ Runtime-Image gewählt: $SELECTED_IMAGE" - name: Build and push Docker image + if: ${{ env.SHOULD_BUILD == 'true' }} shell: bash env: REGISTRY_URL: ${{ env.REGISTRY_URL }} @@ -732,6 +746,7 @@ jobs: echo "✅ Image built and pushed successfully!" - name: Set image info + if: ${{ env.SHOULD_BUILD == 'true' }} id: image_info shell: bash run: | @@ -772,11 +787,7 @@ jobs: deploy-staging: name: Auto-deploy to Staging needs: [changes, build, runtime-base] - if: > - (github.ref_name == 'staging' || github.head_ref == 'staging' || (github.ref_name == '' && contains(github.ref, 'staging'))) - && needs.changes.result == 'success' - && (needs.build.result == 'success' || needs.build.result == 'skipped') - && (needs.runtime-base.result == 'success' || needs.runtime-base.result == 'skipped') + if: github.ref_name == 'staging' || github.head_ref == 'staging' || (github.ref_name == '' && contains(github.ref, 'staging')) runs-on: ubuntu-latest environment: name: staging