Skip to content

Commit dbc097b

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

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 26 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,27 @@ 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+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
29+
with:
30+
depth: 0
31+
- name: detect
32+
run: |
33+
git fetch origin ${{ github.base_ref }}
34+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | tr ' ' '\n')
35+
36+
echo "non-docs=$(echo \"${CHANGED_FILES}\" | grep -qv '**\.md' && echo 'true' )" >> $GITHUB_OUTPUT
37+
echo "yaml=$(echo \"${CHANGED_FILES}\" | grep -q '**\.ya\?ml' && echo 'true' )" >> $GITHUB_OUTPUT
1938
build:
2039
name: build
2140
runs-on: ubuntu-latest
41+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
2242
steps:
2343
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2444
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
@@ -30,6 +50,7 @@ jobs:
3050
buildFips:
3151
name: buildFips
3252
runs-on: ubuntu-latest
53+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
3354
steps:
3455
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3556
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
@@ -40,7 +61,6 @@ jobs:
4061
go build -v -tags "disable_spire,disable_tls" ./cmd/entrypoint
4162
echo "Build finished with exit code: $?"
4263
linting:
43-
needs: [build]
4464
name: lint
4565
runs-on: ubuntu-latest
4666
steps:
@@ -49,6 +69,7 @@ jobs:
4969
with:
5070
go-version-file: "go.mod"
5171
- name: gofmt
72+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
5273
run: |
5374
gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*'))
5475
if [[ -n "$gofmt_out" ]]; then
@@ -57,15 +78,18 @@ jobs:
5778
echo "$gofmt_out"
5879
- name: golangci-lint
5980
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
81+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
6082
with:
6183
version: v2.1.6
6284
only-new-issues: true
6385
args: --timeout=10m
6486
- name: yamllint
87+
if: ${{ needs.changes.outputs.yaml == 'true' }}
6588
run: |
6689
apt-get update && apt-get install -y yamllint
6790
make yamllint
6891
- name: check-license
92+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
6993
run: |
7094
go install github.com/google/[email protected]
7195
go-licenses check ./...

0 commit comments

Comments
 (0)