Skip to content

Commit 7194f13

Browse files
feat(ci): Skip CI for commits without code changes (#3545)
1 parent eb1b3c9 commit 7194f13

8 files changed

+98
-7
lines changed

.github/workflows/buildandtest.yml

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ on:
88
pull_request:
99

1010
jobs:
11+
diff_check:
12+
uses: ./.github/workflows/skip-ci.yml
13+
1114
job_test:
1215
name: Test
1316
runs-on: ubuntu-latest
17+
needs: [diff_check]
18+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
1419
steps:
1520
- uses: actions/checkout@v4
1621
- uses: actions/setup-node@v4
@@ -30,6 +35,8 @@ jobs:
3035
job_lint:
3136
name: Lint
3237
runs-on: ubuntu-latest
38+
needs: [diff_check]
39+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
3340
steps:
3441
- uses: actions/checkout@v4
3542
- uses: actions/cache@v3
@@ -46,6 +53,8 @@ jobs:
4653
job_lint_sample_new_arch:
4754
name: Lint Sample
4855
runs-on: ubuntu-latest
56+
needs: [diff_check]
57+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
4958
steps:
5059
- uses: actions/checkout@v4
5160
- uses: actions/cache@v3
@@ -64,6 +73,8 @@ jobs:
6473
job_check_integrity:
6574
name: Check package integrity
6675
runs-on: ubuntu-latest
76+
needs: [diff_check]
77+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
6778
steps:
6879
- uses: actions/checkout@v4
6980
- uses: actions/cache@v3
@@ -82,6 +93,8 @@ jobs:
8293
job_build:
8394
name: Build
8495
runs-on: ubuntu-latest
96+
needs: [diff_check]
97+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
8598
steps:
8699
- uses: actions/checkout@v4
87100
- uses: actions/setup-node@v4
@@ -124,7 +137,8 @@ jobs:
124137
job_type_check:
125138
name: Type Check Typescript 3.8
126139
runs-on: ubuntu-latest
127-
needs: [job_build]
140+
needs: [job_build, diff_check]
141+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
128142
steps:
129143
- uses: actions/checkout@v4
130144
- uses: actions/setup-node@v4
@@ -163,7 +177,8 @@ jobs:
163177
job_circular_dep_check:
164178
name: Circular Dependency Check
165179
runs-on: ubuntu-latest
166-
needs: [job_build]
180+
needs: [job_build, diff_check]
181+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
167182
steps:
168183
- uses: actions/checkout@v4
169184
- uses: actions/setup-node@v4
@@ -194,7 +209,8 @@ jobs:
194209
job_bundle:
195210
name: Bundle
196211
runs-on: ubuntu-latest
197-
needs: [job_test, job_build]
212+
needs: [job_test, job_build, diff_check]
213+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
198214
strategy:
199215
# we want that the matrix keeps running, default is to cancel them if it fails.
200216
fail-fast: false

.github/workflows/codegen.yml

+5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ on:
88
pull_request:
99

1010
jobs:
11+
diff_check:
12+
uses: ./.github/workflows/skip-ci.yml
13+
1114
codegen:
1215
runs-on: ubuntu-latest
16+
needs: [diff_check]
17+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
1318
strategy:
1419
matrix:
1520
platform: ["android", "ios"]

.github/workflows/codeql-analysis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ on:
2121
- cron: '27 16 * * 5'
2222

2323
jobs:
24+
diff_check:
25+
uses: ./.github/workflows/skip-ci.yml
26+
2427
analyze:
2528
name: Analyze
2629
runs-on: ubuntu-latest
30+
needs: [diff_check]
31+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
2732

2833
strategy:
2934
fail-fast: false

.github/workflows/e2e.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ env:
1313
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
1414

1515
jobs:
16+
diff_check:
17+
uses: ./.github/workflows/skip-ci.yml
18+
1619
cancel-previous-workflow:
1720
runs-on: ubuntu-latest
21+
needs: [diff_check]
22+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
1823
steps:
1924
- name: Cancel Previous Runs
2025
uses: styfle/cancel-workflow-action@01ce38bf961b4e243a6342cbade0dbc8ba3f0432 # [email protected]
@@ -23,6 +28,8 @@ jobs:
2328

2429
metrics:
2530
runs-on: ${{ matrix.runs-on }}
31+
needs: [diff_check]
32+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
2633
strategy:
2734
# we want that the matrix keeps running, default is to cancel them if it fails.
2835
fail-fast: false
@@ -146,6 +153,8 @@ jobs:
146153
react-native-build:
147154
name: Build RN ${{ matrix.rn-version }} ${{ matrix.rn-architecture }} ${{ matrix.engine }} ${{ matrix.platform }} ${{ matrix.build-type }} ${{ matrix.ios-use-frameworks }}
148155
runs-on: ${{ matrix.runs-on }}
156+
needs: [diff_check]
157+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
149158
env:
150159
RN_SENTRY_POD_NAME: RNSentry
151160
RN_DIFF_REPOSITORY: https://github.com/react-native-community/rn-diff-purge.git
@@ -410,8 +419,12 @@ jobs:
410419
path: test/react-native/versions/${{ matrix.rn-version }}/RnDiffApp/ios/*.log
411420

412421
react-native-test:
413-
name: Test RN ${{ matrix.rn-version }} ${{ matrix.rn-architecture }} ${{ matrix.engine }} ${{ matrix.platform }} ${{ matrix.build-type }} ${{ matrix.ios-use-frameworks }}
414-
needs: react-native-build
422+
name:
423+
Test RN ${{ matrix.rn-version }} ${{ matrix.rn-architecture }} ${{ matrix.engine }} ${{ matrix.platform }} ${{
424+
matrix.build-type }} ${{ matrix.ios-use-frameworks }}
425+
needs: [react-native-build, diff_check]
426+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
427+
415428
runs-on: ${{ matrix.runs-on }}
416429
strategy:
417430
fail-fast: false # keeps matrix running if one fails

.github/workflows/native-tests.yml

+9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ on:
66
pull_request:
77

88
jobs:
9+
diff_check:
10+
uses: ./.github/workflows/skip-ci.yml
11+
912
cancel-previous-workflow:
1013
runs-on: ubuntu-latest
14+
needs: [diff_check]
15+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
1116
steps:
1217
- name: Cancel Previous Runs
1318
uses: styfle/cancel-workflow-action@01ce38bf961b4e243a6342cbade0dbc8ba3f0432 # [email protected]
@@ -17,6 +22,8 @@ jobs:
1722
test-ios:
1823
name: ios
1924
runs-on: macos-latest
25+
needs: [diff_check]
26+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
2027
steps:
2128
- uses: actions/checkout@v4
2229

@@ -51,6 +58,8 @@ jobs:
5158
test-android:
5259
name: android
5360
runs-on: ubuntu-latest
61+
needs: [diff_check]
62+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
5463
steps:
5564
- uses: actions/checkout@v4
5665

.github/workflows/sample-application.yml

+7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ env:
1414
RN_SENTRY_POD_NAME: RNSentry
1515

1616
jobs:
17+
diff_check:
18+
uses: ./.github/workflows/skip-ci.yml
19+
1720
cancel-previous-workflow:
1821
runs-on: ubuntu-latest
22+
needs: [diff_check]
23+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
1924
steps:
2025
- name: Cancel Previous Runs
2126
uses: styfle/cancel-workflow-action@01ce38bf961b4e243a6342cbade0dbc8ba3f0432 # [email protected]
@@ -25,6 +30,8 @@ jobs:
2530
build:
2631
name: Build ${{ matrix.rn-architecture }} ${{ matrix.platform }} ${{ matrix.build-type }}
2732
runs-on: ${{ matrix.runs-on }}
33+
needs: [diff_check]
34+
if: ${{ needs.diff_check.outputs.skip_ci != 'true' }}
2835
strategy:
2936
# we want that the matrix keeps running, default is to cancel them if it fails.
3037
fail-fast: false

.github/workflows/skip-ci.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Skip CI
2+
on:
3+
workflow_call:
4+
outputs:
5+
skip_ci:
6+
description: "Value yes if the current PR only contains changes to files not related to code, otherwise, not defined."
7+
value: ${{ jobs.diff_check.outputs.skip_ci }}
8+
9+
jobs:
10+
diff_check:
11+
runs-on: ubuntu-latest
12+
continue-on-error: true
13+
outputs:
14+
skip_ci:
15+
${{ steps.check_diff.outputs.skip_ci }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Check diff from Pull Request
22+
id: check_diff
23+
run: |
24+
skipList=(".github/CODEOWNERS" ".prettierignore")
25+
# Ignores changelog.md, readme.md,...
26+
fileChangesArray=($(git diff --name-only origin/${{ github.base_ref }}..origin/${{ github.head_ref }} | grep -v '\.md$'))
27+
printf '%s\n' "${fileChangesArray[@]}"
28+
for item in "${fileChangesArray[@]}"
29+
do
30+
if [[ ! " ${skipList[@]} " =~ " ${item} " ]]; then
31+
#found an item that doesn't belong to the skip list.
32+
exit 0
33+
fi
34+
done
35+
echo "skip_ci=true" >> $GITHUB_OUTPUT
36+
echo "no source code files commited, skipping CI."

.prettierignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/test/react-native/versions
2-
CHANGELOG.md
3-
2+
.github/workflows/*.yml
3+
*.md

0 commit comments

Comments
 (0)