11name : ci
22
3- on :
4- - pull_request
3+ on : [pull_request]
54
65concurrency :
76 group : ${{ github.workflow }}-${{ github.event.pull-request.number || github.ref }}
@@ -16,9 +15,40 @@ permissions:
1615 checks : write # Used to annotate code in the PR
1716
1817jobs :
18+ changes :
19+ name : categorize changes
20+ runs-on : ubuntu-latest
21+ outputs :
22+ non-docs : ${{ steps.detect.outputs.non-docs }}
23+ yaml : ${{ steps.detect.outputs.yaml }}
24+ steps :
25+ - name : Get base depth
26+ id : base-depth
27+ run : echo "base-depth=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_OUTPUT
28+ - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
29+ with :
30+ ref : ${{ github.event.pull_request.head.sha }}
31+ fetch-depth : ${{ steps.base-depth.outputs.base-depth }}
32+ - name : detect
33+ id : detect
34+ run : |
35+ git fetch origin ${{ github.base_ref }}
36+ CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} | tr ' ' '\n')
37+
38+ echo -e "Changed files:\n${CHANGED_FILES}"
39+
40+ # If no files are changed at all, then `grep -v` will match even though no change outputs
41+ # should be true. Skipping output on an empty set of changes eliminates the false positive
42+ if [[ -n "${CHANGED_FILES}" ]]; then
43+ echo "non-docs=$(echo \"${CHANGED_FILES}\" | grep -qv '**\.md' && echo 'true' )" | tee -a $GITHUB_OUTPUT
44+ echo "yaml=$(echo \"${CHANGED_FILES}\" | grep -q '**\.ya\?ml' && echo 'true' )" | tee -a $GITHUB_OUTPUT
45+ fi
46+
1947 build :
2048 name : build
2149 runs-on : ubuntu-latest
50+ needs : [changes]
51+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
2252 steps :
2353 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2454 - uses : actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
3060 buildFips :
3161 name : buildFips
3262 runs-on : ubuntu-latest
63+ needs : [changes]
64+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
3365 steps :
3466 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3567 - uses : actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
@@ -40,15 +72,16 @@ jobs:
4072 go build -v -tags "disable_spire,disable_tls" ./cmd/entrypoint
4173 echo "Build finished with exit code: $?"
4274 linting :
43- needs : [build]
4475 name : lint
4576 runs-on : ubuntu-latest
77+ needs : [changes]
4678 steps :
4779 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4880 - uses : actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
4981 with :
5082 go-version-file : " go.mod"
5183 - name : gofmt
84+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
5285 run : |
5386 gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*'))
5487 if [[ -n "$gofmt_out" ]]; then
@@ -57,15 +90,18 @@ jobs:
5790 echo "$gofmt_out"
5891 - name : golangci-lint
5992 uses : golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
93+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
6094 with :
6195 version : v2.1.6
6296 only-new-issues : true
6397 args : --timeout=10m
6498 - name : yamllint
99+ if : ${{ needs.changes.outputs.yaml == 'true' }}
65100 run : |
66101 apt-get update && apt-get install -y yamllint
67102 make yamllint
68103 - name : check-license
104+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
69105 run : |
70106 go install github.com/google/[email protected] 71107 go-licenses check ./...
0 commit comments