Skip to content

Commit 6beeb8a

Browse files
committed
ci: skip running builds and tests when only changes are markdown
1 parent 720a62b commit 6beeb8a

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: ci
22

33
on:
4-
- pull_request
4+
pull_request:
5+
paths-ignore:
6+
- 'docs/**' # If the PR only modifies the documentation, there is no need to run builds and code tests
57

68
concurrency:
79
group: ${{ github.workflow }}-${{ github.event.pull-request.number || github.ref }}
@@ -16,9 +18,34 @@ permissions:
1618
checks: write # Used to annotate code in the PR
1719

1820
jobs:
21+
changes:
22+
name: categorize changes
23+
runs-on: ubuntu-latest
24+
outputs:
25+
non-docs: ${{ steps.detect.outputs.non-docs }}
26+
yaml: ${{ steps.detect.outputs.yaml }}
27+
steps:
28+
- name: Get base depth
29+
id: base-depth
30+
run: echo "base-depth=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_OUTPUT
31+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32+
with:
33+
ref: ${{ github.event.pull_request.head.sha }}
34+
fetch-depth: ${{ steps.base-depth.outputs.base-depth }}
35+
- name: detect
36+
run: |
37+
git fetch origin ${{ github.base_ref }}
38+
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} | tr ' ' '\n')
39+
40+
echo -e "Changed files:\n${CHANGED_FILES}"
41+
42+
echo "non-docs=$(echo \"${CHANGED_FILES}\" | grep -qv '**\.md' && echo 'true' )" | tee -a $GITHUB_OUTPUT
43+
echo "yaml=$(echo \"${CHANGED_FILES}\" | grep -q '**\.ya\?ml' && echo 'true' )" | tee -a $GITHUB_OUTPUT
1944
build:
2045
name: build
2146
runs-on: ubuntu-latest
47+
needs: [changes]
48+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
2249
steps:
2350
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2451
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
@@ -30,6 +57,8 @@ jobs:
3057
buildFips:
3158
name: buildFips
3259
runs-on: ubuntu-latest
60+
needs: [changes]
61+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
3362
steps:
3463
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3564
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
@@ -40,15 +69,16 @@ jobs:
4069
go build -v -tags "disable_spire,disable_tls" ./cmd/entrypoint
4170
echo "Build finished with exit code: $?"
4271
linting:
43-
needs: [build]
4472
name: lint
4573
runs-on: ubuntu-latest
74+
needs: [changes]
4675
steps:
4776
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4877
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
4978
with:
5079
go-version-file: "go.mod"
5180
- name: gofmt
81+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
5282
run: |
5383
gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*'))
5484
if [[ -n "$gofmt_out" ]]; then
@@ -57,15 +87,18 @@ jobs:
5787
echo "$gofmt_out"
5888
- name: golangci-lint
5989
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
90+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
6091
with:
6192
version: v2.1.6
6293
only-new-issues: true
6394
args: --timeout=10m
6495
- name: yamllint
96+
if: ${{ needs.changes.outputs.yaml == 'true' }}
6597
run: |
6698
apt-get update && apt-get install -y yamllint
6799
make yamllint
68100
- name: check-license
101+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
69102
run: |
70103
go install github.com/google/[email protected]
71104
go-licenses check ./...

0 commit comments

Comments
 (0)