Skip to content

Commit 074e59d

Browse files
committed
chore: short-circuit required checks for docs-only PRs
1 parent 549a666 commit 074e59d

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

.github/workflows/build.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,66 @@ on:
77

88
permissions:
99
contents: read
10-
10+
pull-requests: read
1111
concurrency:
1212
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1313
cancel-in-progress: true
1414

1515
jobs:
16+
detect-markdown-only:
17+
name: Detect markdown-only changes
18+
runs-on: ubuntu-latest
19+
outputs:
20+
markdown_only: ${{ steps.detect.outputs.markdown_only }}
21+
steps:
22+
- name: Detect markdown-only PR
23+
id: detect
24+
env:
25+
GH_TOKEN: ${{ github.token }}
26+
PR_NUMBER: ${{ github.event.pull_request.number }}
27+
REPOSITORY: ${{ github.repository }}
28+
EVENT_NAME: ${{ github.event_name }}
29+
run: |
30+
if [ "$EVENT_NAME" != "pull_request" ]; then
31+
echo "markdown_only=false" >> "$GITHUB_OUTPUT"
32+
exit 0
33+
fi
34+
35+
gh api --paginate "repos/$REPOSITORY/pulls/$PR_NUMBER/files" --jq '.[].filename' > "$RUNNER_TEMP/changed-files.txt"
36+
37+
if [ ! -s "$RUNNER_TEMP/changed-files.txt" ]; then
38+
markdown_only=false
39+
elif grep -qvE '\.md$' "$RUNNER_TEMP/changed-files.txt"; then
40+
markdown_only=false
41+
else
42+
markdown_only=true
43+
fi
44+
45+
echo "markdown_only=$markdown_only" >> "$GITHUB_OUTPUT"
46+
echo "markdown_only=$markdown_only"
47+
1648
build:
49+
needs: detect-markdown-only
1750
name: Build Job
1851
runs-on: ubuntu-latest
1952

2053
steps:
54+
- name: Skip expensive CI for markdown-only PR
55+
if: needs.detect-markdown-only.outputs.markdown_only == 'true'
56+
run: echo "Only Markdown files changed; marking this check successful without running expensive CI."
2157
- name: Git checkout
58+
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
2259
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
2360

2461
- name: 'Set up Java 17'
62+
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
2563
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
2664
with:
2765
java-version: '17'
2866
distribution: 'temurin'
2967

3068
- name: Cache Gradle packages
69+
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
3170
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
3271
with:
3372
path: |
@@ -38,7 +77,9 @@ jobs:
3877
${{ runner.os }}-gradle-
3978
4079
- name: Make compile
80+
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
4181
run: make compile
4282

4383
- name: Make stop
84+
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
4485
run: make stop

.github/workflows/gradle-wrapper-validation.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,48 @@ on:
77

88
permissions:
99
contents: read
10-
10+
pull-requests: read
1111
jobs:
12+
detect-markdown-only:
13+
name: Detect markdown-only changes
14+
runs-on: ubuntu-latest
15+
outputs:
16+
markdown_only: ${{ steps.detect.outputs.markdown_only }}
17+
steps:
18+
- name: Detect markdown-only PR
19+
id: detect
20+
env:
21+
GH_TOKEN: ${{ github.token }}
22+
PR_NUMBER: ${{ github.event.pull_request.number }}
23+
REPOSITORY: ${{ github.repository }}
24+
EVENT_NAME: ${{ github.event_name }}
25+
run: |
26+
if [ "$EVENT_NAME" != "pull_request" ]; then
27+
echo "markdown_only=false" >> "$GITHUB_OUTPUT"
28+
exit 0
29+
fi
30+
31+
gh api --paginate "repos/$REPOSITORY/pulls/$PR_NUMBER/files" --jq '.[].filename' > "$RUNNER_TEMP/changed-files.txt"
32+
33+
if [ ! -s "$RUNNER_TEMP/changed-files.txt" ]; then
34+
markdown_only=false
35+
elif grep -qvE '\.md$' "$RUNNER_TEMP/changed-files.txt"; then
36+
markdown_only=false
37+
else
38+
markdown_only=true
39+
fi
40+
41+
echo "markdown_only=$markdown_only" >> "$GITHUB_OUTPUT"
42+
echo "markdown_only=$markdown_only"
43+
1244
validation:
45+
needs: detect-markdown-only
1346
runs-on: ubuntu-latest
1447
steps:
48+
- name: Skip expensive CI for markdown-only PR
49+
if: needs.detect-markdown-only.outputs.markdown_only == 'true'
50+
run: echo "Only Markdown files changed; marking this check successful without running expensive CI."
1551
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
52+
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
1653
- uses: gradle/actions/wrapper-validation@5e2ebd065dc2488b7a6ad670704656cbbe1e8f60 # v6.1.1
54+
if: needs.detect-markdown-only.outputs.markdown_only != 'true'

0 commit comments

Comments
 (0)