Skip to content

Commit 4754c28

Browse files
chore: Enable Conditional Step Skipping in Pipeline (#2076)
1 parent 55b6090 commit 4754c28

4 files changed

Lines changed: 131 additions & 36 deletions

File tree

.github/workflows/broken-links-checker.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Broken Link Checker
22

33
on:
44
pull_request:
5-
paths:
6-
- '**/*.md'
75
workflow_dispatch:
86

97
permissions:
@@ -28,14 +26,19 @@ jobs:
2826
with:
2927
files: |
3028
**/*.md
29+
30+
- name: Skip - No Markdown Files Changed
31+
if: github.event_name == 'pull_request' && steps.changed-markdown-files.outputs.any_changed != 'true'
32+
run: echo "No markdown files changed. Skipping broken link check."
33+
3134
# For PR: Check broken links only in changed files
3235
- name: Check Broken Links in Changed Markdown Files
3336
id: lychee-check-pr
3437
if: github.event_name == 'pull_request' && steps.changed-markdown-files.outputs.any_changed == 'true'
3538
uses: lycheeverse/lychee-action@v2.7.0
3639
with:
3740
args: >
38-
--verbose --no-progress --exclude ^https?://
41+
--verbose --exclude-mail --no-progress --exclude ^https?://
3942
${{ steps.changed-markdown-files.outputs.all_changed_files }}
4043
failIfEmpty: false
4144
env:
@@ -48,7 +51,7 @@ jobs:
4851
uses: lycheeverse/lychee-action@v2.7.0
4952
with:
5053
args: >
51-
--verbose --no-progress --exclude ^https?://
54+
--verbose --exclude-mail --no-progress --exclude ^https?://
5255
'**/*.md'
5356
failIfEmpty: false
5457
env:

.github/workflows/build-docker-images.yml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ on:
66
- main
77
- dev
88
- demo
9-
paths:
10-
- 'code/**'
11-
- '!code/tests/**'
12-
- 'docker/**'
13-
- 'package.json'
14-
- 'pyproject.toml'
15-
- '.github/workflows/build-docker-images.yml'
16-
- '.github/workflows/build-docker.yml'
179
pull_request:
1810
branches:
1911
- main
@@ -28,7 +20,37 @@ on:
2820
workflow_dispatch:
2921

3022
jobs:
23+
check-changes:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
should_build: ${{ steps.filter.outputs.docker_related }}
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v6
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Check for relevant changes
34+
id: filter
35+
uses: dorny/paths-filter@v3
36+
with:
37+
filters: |
38+
docker_related:
39+
- 'code/**'
40+
- '!code/tests/**'
41+
- 'docker/**'
42+
- 'package.json'
43+
- 'pyproject.toml'
44+
- '.github/workflows/build-docker-images.yml'
45+
- '.github/workflows/build-docker.yml'
46+
47+
- name: Skip - No Relevant Changes
48+
if: steps.filter.outputs.docker_related != 'true' && github.event_name != 'workflow_dispatch'
49+
run: echo "No relevant changes detected. Skipping docker build."
50+
3151
docker-build:
52+
needs: check-changes
53+
if: needs.check-changes.outputs.should_build == 'true' || github.event_name == 'workflow_dispatch'
3254
strategy:
3355
matrix:
3456
include:

.github/workflows/ci.yml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ on:
66
- main
77
- dev
88
- demo
9-
paths:
10-
- 'infra/**'
11-
- 'scripts/**'
12-
- 'azure.yaml'
13-
- 'pyproject.toml'
14-
- 'Makefile'
15-
- '.github/workflows/ci.yml'
169
schedule:
1710
- cron: '0 8,20 * * *' # Runs at 8:00 AM and 8:00 PM GMT
1811
workflow_dispatch:
@@ -25,7 +18,36 @@ concurrency:
2518
group: ${{ github.workflow }}-${{ github.ref }}
2619

2720
jobs:
21+
check-changes:
22+
runs-on: ubuntu-latest
23+
outputs:
24+
should_deploy: ${{ steps.filter.outputs.deploy_related }}
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v6
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Check for relevant changes
32+
id: filter
33+
uses: dorny/paths-filter@v3
34+
with:
35+
filters: |
36+
deploy_related:
37+
- 'infra/**'
38+
- 'scripts/**'
39+
- 'azure.yaml'
40+
- 'pyproject.toml'
41+
- 'Makefile'
42+
- '.github/workflows/ci.yml'
43+
44+
- name: Skip - No Relevant Changes
45+
if: steps.filter.outputs.deploy_related != 'true' && github.event_name != 'workflow_dispatch' && github.event_name != 'schedule'
46+
run: echo "No relevant changes detected. Skipping deployment validation."
47+
2848
deploy:
49+
needs: check-changes
50+
if: needs.check-changes.outputs.should_deploy == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
2951
runs-on: ubuntu-latest
3052
env:
3153
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
@@ -387,17 +409,17 @@ jobs:
387409

388410

389411
e2e-test:
390-
needs: deploy
391-
if: needs.deploy.outputs.DEPLOYMENT_SUCCESS == 'true'
412+
needs: [check-changes, deploy]
413+
if: always() && needs.deploy.result == 'success' && needs.deploy.outputs.DEPLOYMENT_SUCCESS == 'true'
392414
uses: ./.github/workflows/test-automation.yml
393415
with:
394416
web_url: ${{ needs.deploy.outputs.web_url }}
395417
admin_url: ${{ needs.deploy.outputs.admin_url }}
396418

397419

398420
cleanup:
399-
if: always()
400-
needs: [deploy, e2e-test]
421+
if: always() && needs.deploy.result != 'skipped'
422+
needs: [check-changes, deploy, e2e-test]
401423
runs-on: ubuntu-latest
402424

403425
env:

.github/workflows/tests.yml

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ on:
44
workflow_dispatch:
55
push:
66
branches: [main, dev, demo]
7-
paths:
8-
- 'code/**'
9-
- 'pyproject.toml'
10-
- 'package.json'
11-
- 'pytest.ini'
12-
- '.github/workflows/tests.yml'
137
pull_request:
148
branches: [main, dev, demo]
159
types:
@@ -21,22 +15,61 @@ on:
2115
merge_group:
2216

2317
jobs:
24-
test_package:
25-
name: Tests
18+
check-changes:
2619
runs-on: ubuntu-latest
20+
outputs:
21+
backend_changed: ${{ steps.filter.outputs.backend }}
22+
frontend_changed: ${{ steps.filter.outputs.frontend }}
2723
steps:
2824
- uses: actions/checkout@v6
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Check for relevant changes
29+
id: filter
30+
uses: dorny/paths-filter@v3
31+
with:
32+
filters: |
33+
backend:
34+
- 'code/backend/**'
35+
- 'code/app.py'
36+
- 'code/create_app.py'
37+
- 'code/tests/**'
38+
- 'pyproject.toml'
39+
- 'pytest.ini'
40+
- '.github/workflows/tests.yml'
41+
frontend:
42+
- 'code/frontend/**'
43+
- 'package.json'
44+
- '.github/workflows/tests.yml'
45+
46+
- name: Log detected changes
47+
run: |
48+
echo "Backend changed: ${{ steps.filter.outputs.backend }}"
49+
echo "Frontend changed: ${{ steps.filter.outputs.frontend }}"
50+
51+
python-tests:
52+
name: Python Tests
53+
needs: check-changes
54+
if: needs.check-changes.outputs.backend_changed == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call'
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v6
58+
2959
- name: Install Poetry
3060
run: pip install poetry
61+
3162
- name: Setup python
3263
uses: actions/setup-python@v6
3364
with:
3465
python-version: "3.11"
3566
architecture: x64
3667
cache: 'poetry'
68+
3769
- name: Install dependencies through poetry
3870
run: |
3971
poetry install
72+
4073
- name: Get coverage artifact ID
4174
id: coverage-artifact
4275
uses: actions/github-script@v8
@@ -64,28 +97,32 @@ jobs:
6497
return workflowRuns.data.workflow_runs[0]?.id ?? "";
6598
result-encoding: string
6699
retries: 3
100+
67101
- name: Download main coverage artifact
68102
uses: actions/download-artifact@v7
69103
if: github.event_name == 'pull_request' && steps.coverage-artifact.outputs.result != ''
70-
continue-on-error: true # There is a chance that the artifact doesn't exist, or has expired
104+
continue-on-error: true
71105
with:
72106
name: coverage
73107
path: "${{ github.workspace }}/coverage-main"
74108
github-token: ${{ secrets.GITHUB_TOKEN }}
75109
run-id: ${{ steps.coverage-artifact.outputs.result }}
110+
76111
- name: Get coverage from main
77112
id: coverage-value
78113
run: |
79114
MIN_COVERAGE=0
80115
81116
if [[ -f "./coverage-main/coverage.xml" ]]; then
82-
MIN_COVERAGE=$(grep -m 1 "<coverage" "./coverage-main/coverage.xml" | sed -E 's/.*line-rate="([^"]*)".*/\1/') # Extract the line rate from the XML
83-
MIN_COVERAGE=$(awk "BEGIN {print int($MIN_COVERAGE * 100)}") # Turn into percentage, rounding down to avoid rounding issues
117+
MIN_COVERAGE=$(grep -m 1 "<coverage" "./coverage-main/coverage.xml" | sed -E 's/.*line-rate="([^"]*)".*/\1/')
118+
MIN_COVERAGE=$(awk "BEGIN {print int($MIN_COVERAGE * 100)}")
84119
fi
85120
86121
echo "MIN_COVERAGE=$MIN_COVERAGE" >> "$GITHUB_OUTPUT"
122+
87123
- name: Run Python Tests
88124
run: make python-test optional_args="--junitxml=coverage-junit.xml --cov=code --cov-report=term-missing --cov-report=xml:coverage.xml --cov-fail-under=${{ steps.coverage-value.outputs.MIN_COVERAGE }} ./code/tests"
125+
89126
- uses: actions/upload-artifact@v6
90127
if: ${{ !cancelled() }}
91128
with:
@@ -94,13 +131,24 @@ jobs:
94131
coverage-junit.xml
95132
coverage.xml
96133
if-no-files-found: error
134+
135+
- name: Lint
136+
run: make lint
137+
138+
frontend-tests:
139+
name: Frontend Tests
140+
needs: check-changes
141+
if: needs.check-changes.outputs.frontend_changed == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call'
142+
runs-on: ubuntu-latest
143+
steps:
144+
- uses: actions/checkout@v6
145+
97146
- name: Setup node
98147
uses: actions/setup-node@v6
99148
with:
100149
node-version: 20
101150
cache: "npm"
102151
cache-dependency-path: "code/frontend/package-lock.json"
152+
103153
- name: Run frontend unit tests
104154
run: make unittest-frontend
105-
- name: Lint
106-
run: make lint

0 commit comments

Comments
 (0)