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
This commit is contained in:
@@ -472,14 +472,21 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: Build Docker Image
|
name: Build Docker Image
|
||||||
needs: [changes, runtime-base]
|
needs: [changes, runtime-base]
|
||||||
if: always() && needs.changes.outputs.needs_build == 'true'
|
|
||||||
runs-on: docker-build
|
runs-on: docker-build
|
||||||
|
env:
|
||||||
|
SHOULD_BUILD: ${{ needs.changes.outputs.needs_build }}
|
||||||
outputs:
|
outputs:
|
||||||
image_tag: ${{ steps.image_info.outputs.IMAGE_TAG }}
|
image_tag: ${{ steps.image_info.outputs.IMAGE_TAG }}
|
||||||
commit_sha: ${{ steps.meta.outputs.commit_sha }}
|
commit_sha: ${{ steps.meta.outputs.commit_sha }}
|
||||||
image_url: ${{ steps.image_info.outputs.IMAGE_URL }}
|
image_url: ${{ steps.image_info.outputs.IMAGE_URL }}
|
||||||
steps:
|
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
|
- name: Install git and setup environment
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
shell: sh
|
shell: sh
|
||||||
run: |
|
run: |
|
||||||
if ! command -v bash >/dev/null 2>&1 || ! command -v git >/dev/null 2>&1; then
|
if ! command -v bash >/dev/null 2>&1 || ! command -v git >/dev/null 2>&1; then
|
||||||
@@ -489,6 +496,7 @@ jobs:
|
|||||||
git --version
|
git --version
|
||||||
|
|
||||||
- name: Download CI helpers
|
- name: Download CI helpers
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
@@ -511,6 +519,7 @@ jobs:
|
|||||||
chmod +x /tmp/ci-tools/clone_repo.sh
|
chmod +x /tmp/ci-tools/clone_repo.sh
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
REF_NAME="${{ github.ref_name }}"
|
REF_NAME="${{ github.ref_name }}"
|
||||||
@@ -530,6 +539,7 @@ jobs:
|
|||||||
cd /workspace/repo
|
cd /workspace/repo
|
||||||
|
|
||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
docker buildx version || echo "Buildx nicht gefunden"
|
docker buildx version || echo "Buildx nicht gefunden"
|
||||||
@@ -553,6 +563,7 @@ jobs:
|
|||||||
docker buildx ls
|
docker buildx ls
|
||||||
|
|
||||||
- name: Generate image metadata
|
- name: Generate image metadata
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
id: meta
|
id: meta
|
||||||
run: |
|
run: |
|
||||||
cd /workspace/repo
|
cd /workspace/repo
|
||||||
@@ -568,6 +579,7 @@ jobs:
|
|||||||
echo "Generated tag: ${TAG}"
|
echo "Generated tag: ${TAG}"
|
||||||
|
|
||||||
- name: Login to Registry
|
- name: Login to Registry
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
id: login
|
id: login
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -642,6 +654,7 @@ jobs:
|
|||||||
echo "CACHE_REGISTRY=$CANONICAL_REGISTRY" >> $GITHUB_ENV
|
echo "CACHE_REGISTRY=$CANONICAL_REGISTRY" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Determine runtime base image
|
- name: Determine runtime base image
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
id: runtime-image
|
id: runtime-image
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -678,6 +691,7 @@ jobs:
|
|||||||
echo "🏗️ Runtime-Image gewählt: $SELECTED_IMAGE"
|
echo "🏗️ Runtime-Image gewählt: $SELECTED_IMAGE"
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
REGISTRY_URL: ${{ env.REGISTRY_URL }}
|
REGISTRY_URL: ${{ env.REGISTRY_URL }}
|
||||||
@@ -732,6 +746,7 @@ jobs:
|
|||||||
echo "✅ Image built and pushed successfully!"
|
echo "✅ Image built and pushed successfully!"
|
||||||
|
|
||||||
- name: Set image info
|
- name: Set image info
|
||||||
|
if: ${{ env.SHOULD_BUILD == 'true' }}
|
||||||
id: image_info
|
id: image_info
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -772,11 +787,7 @@ jobs:
|
|||||||
deploy-staging:
|
deploy-staging:
|
||||||
name: Auto-deploy to Staging
|
name: Auto-deploy to Staging
|
||||||
needs: [changes, build, runtime-base]
|
needs: [changes, build, runtime-base]
|
||||||
if: >
|
if: github.ref_name == 'staging' || github.head_ref == 'staging' || (github.ref_name == '' && contains(github.ref, 'staging'))
|
||||||
(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')
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment:
|
environment:
|
||||||
name: staging
|
name: staging
|
||||||
|
|||||||
Reference in New Issue
Block a user