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:
@@ -4,10 +4,30 @@ run-name: Build Image - ${{ github.ref_name }} - ${{ github.sha }}
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, staging ]
|
branches:
|
||||||
paths-ignore:
|
- main
|
||||||
- '**.md'
|
- staging
|
||||||
- 'docs/**'
|
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:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
branch:
|
branch:
|
||||||
@@ -30,6 +50,9 @@ env:
|
|||||||
IMAGE_NAME: framework
|
IMAGE_NAME: framework
|
||||||
RUNTIME_IMAGE_NAME: framework-runtime
|
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:
|
jobs:
|
||||||
# Job 0: Detect if a new image build is required
|
# Job 0: Detect if a new image build is required
|
||||||
changes:
|
changes:
|
||||||
@@ -204,13 +227,25 @@ jobs:
|
|||||||
runtime-base:
|
runtime-base:
|
||||||
name: Build Runtime Base Image
|
name: Build Runtime Base Image
|
||||||
needs: changes
|
needs: changes
|
||||||
if: needs.changes.outputs.needs_runtime_build == 'true'
|
|
||||||
runs-on: docker-build
|
runs-on: docker-build
|
||||||
outputs:
|
outputs:
|
||||||
image_ref: ${{ steps.set-result.outputs.image_ref }}
|
image_ref: ${{ steps.set-result.outputs.image_ref }}
|
||||||
built: ${{ steps.set-result.outputs.built }}
|
built: ${{ steps.set-result.outputs.built }}
|
||||||
steps:
|
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
|
- name: Download CI helpers
|
||||||
|
if: ${{ steps.decision.outputs.should_build == 'true' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
||||||
@@ -232,17 +267,10 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
chmod +x /tmp/ci-tools/clone_repo.sh
|
chmod +x /tmp/ci-tools/clone_repo.sh
|
||||||
|
|
||||||
- name: Evaluate runtime build requirement
|
- name: Skip runtime base build
|
||||||
id: decision
|
if: ${{ steps.decision.outputs.should_build != 'true' }}
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ needs.changes.outputs.needs_runtime_build }}" = "true" ]; then
|
echo "ℹ️ Runtime base build not required – skipping."
|
||||||
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: Install git and setup environment
|
- name: Install git and setup environment
|
||||||
if: steps.decision.outputs.should_build == 'true'
|
if: steps.decision.outputs.should_build == 'true'
|
||||||
@@ -499,7 +527,7 @@ jobs:
|
|||||||
SHOULD_BUILD: ${{ needs.changes.outputs.needs_build }}
|
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.image_info.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
|
- name: Skip build when not required
|
||||||
@@ -786,25 +814,65 @@ 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
|
||||||
|
env:
|
||||||
|
SHOULD_BUILD: ${{ env.SHOULD_BUILD }}
|
||||||
|
REF_NAME: ${{ github.ref_name }}
|
||||||
|
HEAD_REF: ${{ github.head_ref }}
|
||||||
|
FULL_REF: ${{ github.ref }}
|
||||||
run: |
|
run: |
|
||||||
|
REGISTRY_DEFAULT="$REGISTRY"
|
||||||
|
if [ -z "$REGISTRY_DEFAULT" ]; then
|
||||||
|
REGISTRY_DEFAULT="${{ env.REGISTRY }}"
|
||||||
|
fi
|
||||||
|
IMAGE_NAME="${{ env.IMAGE_NAME }}"
|
||||||
COMMIT_SHA="${{ github.sha }}"
|
COMMIT_SHA="${{ github.sha }}"
|
||||||
if [ -z "$COMMIT_SHA" ]; then
|
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
|
fi
|
||||||
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
|
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
|
||||||
TAG="${SHORT_SHA}-$(date +%s)"
|
TAG="${SHORT_SHA}-$(date +%s)"
|
||||||
|
|
||||||
REGISTRY_TO_USE="${{ env.REGISTRY_URL }}"
|
REGISTRY_TO_USE="${REGISTRY_URL:-$REGISTRY_DEFAULT}"
|
||||||
IMAGE_NAME="${{ env.IMAGE_NAME }}"
|
|
||||||
|
|
||||||
IMAGE_TAG="$TAG"
|
IMAGE_TAG="$TAG"
|
||||||
IMAGE_URL="${REGISTRY_TO_USE}/${IMAGE_NAME}:${IMAGE_TAG}"
|
IMAGE_URL="${REGISTRY_TO_USE}/${IMAGE_NAME}:${IMAGE_TAG}"
|
||||||
|
|
||||||
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
|
echo "IMAGE_TAG=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
|
||||||
echo "IMAGE_URL=$IMAGE_URL" >> $GITHUB_OUTPUT
|
echo "IMAGE_URL=$IMAGE_URL" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "COMMIT_SHA=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
echo "📦 Image info:"
|
echo "📦 Image info:"
|
||||||
echo " Tag: $IMAGE_TAG"
|
echo " Tag: $IMAGE_TAG"
|
||||||
@@ -813,7 +881,7 @@ jobs:
|
|||||||
|
|
||||||
REF_NAME="${{ github.ref_name }}"
|
REF_NAME="${{ github.ref_name }}"
|
||||||
if [ -z "$REF_NAME" ]; then
|
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
|
fi
|
||||||
|
|
||||||
if [ "$REF_NAME" = "staging" ]; then
|
if [ "$REF_NAME" = "staging" ]; then
|
||||||
@@ -827,8 +895,7 @@ jobs:
|
|||||||
deploy-staging:
|
deploy-staging:
|
||||||
name: Auto-deploy to Staging
|
name: Auto-deploy to Staging
|
||||||
needs: [changes, build]
|
needs: [changes, build]
|
||||||
if: |
|
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' }}
|
||||||
github.ref_name == 'staging' || github.head_ref == 'staging' || (github.ref_name == '' && contains(github.ref, 'staging'))
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment:
|
environment:
|
||||||
name: staging
|
name: staging
|
||||||
|
|||||||
Reference in New Issue
Block a user