chore(ci): update build workflow for targeted path triggers and concurrency management

- Refine branch and path filters for efficient CI triggers.
- Add concurrency control to avoid overlapping builds.
- Improve runtime base build logic with conditional evaluation and skipping.
- Enhance image info generation with fallback handling and deployment readiness checks.
This commit is contained in:
2025-11-03 22:41:06 +01:00
parent a93a086ee4
commit 84a5a3fa21

View File

@@ -4,10 +4,30 @@ run-name: Build Image - ${{ github.ref_name }} - ${{ github.sha }}
on:
push:
branches: [ main, staging ]
paths-ignore:
- '**.md'
- 'docs/**'
branches:
- main
- staging
paths:
- '.gitea/workflows/**'
- 'src/**'
- 'resources/**'
- 'config/**'
- 'public/**'
- 'composer.json'
- 'composer.lock'
- 'package.json'
- 'package-lock.json'
- 'Dockerfile.production'
- 'Dockerfile.runtime'
- 'docker-compose.yml'
- 'docker-compose.*.yml'
- 'docker/**'
- 'deployment/**'
- 'scripts/ci/**'
- 'vite.config.*'
- 'tsconfig.json'
- 'babel.config.js'
- 'Makefile'
workflow_dispatch:
inputs:
branch:
@@ -30,6 +50,9 @@ env:
IMAGE_NAME: framework
RUNTIME_IMAGE_NAME: framework-runtime
concurrency:
group: build-image-${{ github.ref_name || github.head_ref || inputs.branch || github.run_id }}
cancel-in-progress: true
jobs:
# Job 0: Detect if a new image build is required
changes:
@@ -204,13 +227,25 @@ jobs:
runtime-base:
name: Build Runtime Base Image
needs: changes
if: needs.changes.outputs.needs_runtime_build == 'true'
runs-on: docker-build
outputs:
image_ref: ${{ steps.set-result.outputs.image_ref }}
built: ${{ steps.set-result.outputs.built }}
steps:
- name: Evaluate runtime build requirement
id: decision
shell: bash
run: |
if [ "${{ needs.changes.outputs.needs_runtime_build }}" = "true" ]; then
echo "Runtime base rebuild required"
echo "should_build=true" >> "$GITHUB_OUTPUT"
else
echo "Runtime base rebuild not required"
echo "should_build=false" >> "$GITHUB_OUTPUT"
fi
- name: Download CI helpers
if: ${{ steps.decision.outputs.should_build == 'true' }}
shell: bash
env:
CI_TOKEN: ${{ secrets.CI_TOKEN }}
@@ -232,17 +267,10 @@ jobs:
fi
chmod +x /tmp/ci-tools/clone_repo.sh
- name: Evaluate runtime build requirement
id: decision
shell: bash
- name: Skip runtime base build
if: ${{ steps.decision.outputs.should_build != 'true' }}
run: |
if [ "${{ needs.changes.outputs.needs_runtime_build }}" = "true" ]; then
echo "Runtime base rebuild required"
echo "should_build=true" >> "$GITHUB_OUTPUT"
else
echo "Runtime base rebuild not required"
echo "should_build=false" >> "$GITHUB_OUTPUT"
fi
echo " Runtime base build not required skipping."
- name: Install git and setup environment
if: steps.decision.outputs.should_build == 'true'
@@ -499,7 +527,7 @@ jobs:
SHOULD_BUILD: ${{ needs.changes.outputs.needs_build }}
outputs:
image_tag: ${{ steps.image_info.outputs.IMAGE_TAG }}
commit_sha: ${{ steps.meta.outputs.commit_sha }}
commit_sha: ${{ steps.image_info.outputs.COMMIT_SHA }}
image_url: ${{ steps.image_info.outputs.IMAGE_URL }}
steps:
- name: Skip build when not required
@@ -786,25 +814,65 @@ jobs:
echo "✅ Image built and pushed successfully!"
- name: Set image info
if: ${{ env.SHOULD_BUILD == 'true' }}
id: image_info
shell: bash
env:
SHOULD_BUILD: ${{ env.SHOULD_BUILD }}
REF_NAME: ${{ github.ref_name }}
HEAD_REF: ${{ github.head_ref }}
FULL_REF: ${{ github.ref }}
run: |
REGISTRY_DEFAULT="$REGISTRY"
if [ -z "$REGISTRY_DEFAULT" ]; then
REGISTRY_DEFAULT="${{ env.REGISTRY }}"
fi
IMAGE_NAME="${{ env.IMAGE_NAME }}"
COMMIT_SHA="${{ github.sha }}"
if [ -z "$COMMIT_SHA" ]; then
COMMIT_SHA=$(cd /workspace/repo && git rev-parse HEAD)
COMMIT_SHA="unknown"
fi
if [ "${SHOULD_BUILD}" != "true" ]; then
IMAGE_TAG="latest"
IMAGE_URL="${REGISTRY_DEFAULT}/${IMAGE_NAME}:${IMAGE_TAG}"
echo "IMAGE_TAG=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
echo "IMAGE_URL=$IMAGE_URL" >> "$GITHUB_OUTPUT"
echo "COMMIT_SHA=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
echo " Build skipped using latest image tag ($IMAGE_TAG)."
EFFECTIVE_REF="$REF_NAME"
if [ -z "$EFFECTIVE_REF" ]; then
EFFECTIVE_REF="$HEAD_REF"
fi
if [ -z "$EFFECTIVE_REF" ] && [ -n "$FULL_REF" ]; then
EFFECTIVE_REF="${FULL_REF##*/}"
fi
if [ "$EFFECTIVE_REF" = "staging" ]; then
echo "🚀 Staging branch detected - will auto-deploy using the latest published image."
else
echo "💡 Image is ready for deployment!"
echo " Run the 'Deploy to Production' or 'Deploy to Staging' workflow to deploy this image."
fi
exit 0
fi
cd /workspace/repo
if [ -z "$COMMIT_SHA" ] || [ "$COMMIT_SHA" = "unknown" ]; then
COMMIT_SHA=$(git rev-parse HEAD)
fi
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
TAG="${SHORT_SHA}-$(date +%s)"
REGISTRY_TO_USE="${{ env.REGISTRY_URL }}"
IMAGE_NAME="${{ env.IMAGE_NAME }}"
REGISTRY_TO_USE="${REGISTRY_URL:-$REGISTRY_DEFAULT}"
IMAGE_TAG="$TAG"
IMAGE_URL="${REGISTRY_TO_USE}/${IMAGE_NAME}:${IMAGE_TAG}"
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "IMAGE_URL=$IMAGE_URL" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
echo "IMAGE_URL=$IMAGE_URL" >> "$GITHUB_OUTPUT"
echo "COMMIT_SHA=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
echo "📦 Image info:"
echo " Tag: $IMAGE_TAG"
@@ -813,7 +881,7 @@ jobs:
REF_NAME="${{ github.ref_name }}"
if [ -z "$REF_NAME" ]; then
REF_NAME=$(cd /workspace/repo && git rev-parse --abbrev-ref HEAD)
REF_NAME=$(git rev-parse --abbrev-ref HEAD)
fi
if [ "$REF_NAME" = "staging" ]; then
@@ -827,8 +895,7 @@ jobs:
deploy-staging:
name: Auto-deploy to Staging
needs: [changes, build]
if: |
github.ref_name == 'staging' || github.head_ref == 'staging' || (github.ref_name == '' && contains(github.ref, 'staging'))
if: ${{ always() && (github.ref_name == 'staging' || github.head_ref == 'staging' || (github.ref_name == '' && contains(github.ref, 'staging'))) && needs.build.result != 'failure' && needs.build.result != 'cancelled' && needs.changes.result != 'failure' && needs.changes.result != 'cancelled' }}
runs-on: ubuntu-latest
environment:
name: staging