Enhance CI workflow to detect relevant changes

Added logic to skip build if no relevant changes detected.
This commit is contained in:
Michael authored and GitHub committed 2026-01-28 21:56:56 +01:00
1 parent eec81a7b67
commit 079a3626cb
1 file changed
+36 -11
+36 -11
View File
@@ -3,15 +3,6 @@ name: CI
on:
pull_request:
branches: [ master ]
paths:
- "src/**"
- "scripts/**"
- "angular.json"
- "tsconfig*.json"
- "package.json"
- "package-lock.json"
- ".github/workflows/**"
- "public/i18n/**"
jobs:
build:
@@ -19,18 +10,52 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect relevant changes
id: changes
shell: bash
run: |
BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.sha }}"
echo "Base: $BASE"
echo "Head: $HEAD"
files="$(git diff --name-only "$BASE" "$HEAD")"
echo "Changed files:"
echo "$files"
if echo "$files" | grep -Eq '^(src/|scripts/|angular\.json$|tsconfig.*\.json$|package\.json$|package-lock\.json$|\.github/workflows/|public/i18n/)'; then
echo "run_build=true" >> "$GITHUB_OUTPUT"
else
echo "run_build=false" >> "$GITHUB_OUTPUT"
fi
- name: Skip build (no relevant changes)
if: steps.changes.outputs.run_build != 'true'
run: |
echo "No files changed that affect the build/tests. Marking CI as successful."
exit 0
- name: Setup Node
if: steps.changes.outputs.run_build == 'true'
uses: actions/setup-node@v4
with:
node-version: 24.13.0
cache: npm
- run: npm i -g npm@11.8.0
- run: npm --version
- name: Pin npm version
if: steps.changes.outputs.run_build == 'true'
run: |
npm i -g npm@11.8.0
npm --version
- name: Install dependencies
if: steps.changes.outputs.run_build == 'true'
run: npm ci
- name: Build
if: steps.changes.outputs.run_build == 'true'
run: npm run build --if-present