@@ -2,41 +2,132 @@ name: Tests
22
33on :
44 pull_request :
5- paths : ["**.go", "go.mod", "go.sum"]
65 push :
7- branches :
8- - main
6+ branches : ["main"]
7+ workflow_dispatch :
8+
9+ # Allow concurrent runs on main/release branches but isolates other branches
10+ concurrency :
11+ group : ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
12+ cancel-in-progress : ${{ ! (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) }}
913
1014jobs :
1115 unit-tests :
1216 runs-on : ubuntu-latest
1317 steps :
1418 - uses : actions/checkout@v3
1519
20+ - name : " Check for Go-related changes"
21+ id : check_go
22+ uses : dorny/paths-filter@v3
23+ with :
24+ filters : |
25+ check_go:
26+ - "**/*.go"
27+ - "go.mod"
28+ - "go.sum"
29+ - "justfile"
30+
1631 - name : Set up Go
32+ if : steps.check_go.outputs.check_go == 'true'
1733 uses : actions/setup-go@v5
1834 with :
1935 go-version-file : go.mod
36+ # cache: "The action has a built-in functionality for caching and
37+ # restoring go modules and build outputs. It uses [actions/cache@v4]."
38+ # - Handles go module cache (go env GOMODCACHE).
39+ # - Handles go build cache (go env GOCACHE).
2040 cache : true
2141
2242 - name : " Install just"
43+ if : steps.check_go.outputs.check_go == 'true'
2344 # casey/just: https://just.systems/man/en/chapter_6.html
2445 # taiki-e/install-action: https://github.com/taiki-e/install-action
2546 uses : taiki-e/install-action@just
2647
27- - name : Run all tests.
28- run : just test
48+ - run : just test
49+ if : steps.check_go.outputs.check_go == 'true'
2950
3051 build :
3152 runs-on : ubuntu-latest
3253 steps :
3354 - uses : actions/checkout@v3
3455
56+ - name : " Check for Go-related changes"
57+ id : check_go
58+ uses : dorny/paths-filter@v3
59+ with :
60+ filters : |
61+ check_go:
62+ - "**/*.go"
63+ - "go.mod"
64+ - "go.sum"
65+ - "justfile"
66+
3567 - name : Set up Go
68+ if : steps.check_go.outputs.check_go == 'true'
3669 uses : actions/setup-go@v5
3770 with :
3871 go-version-file : go.mod
72+ # cache: "The action has a built-in functionality for caching and
73+ # restoring go modules and build outputs. It uses [actions/cache@v4]."
74+ # - Handles go module cache (go env GOMODCACHE).
75+ # - Handles go build cache (go env GOCACHE).
3976 cache : true
4077
41- - name : Run all tests.
78+ - if : steps.check_go.outputs.check_go == 'true'
4279 run : make build
80+
81+ golangci :
82+ name : lint
83+ runs-on : ubuntu-latest
84+ steps :
85+ - uses : actions/checkout@v4
86+
87+ - name : " Check for Go-related changes"
88+ id : check_go
89+ uses : dorny/paths-filter@v3
90+ with :
91+ filters : |
92+ check_go:
93+ - "**/*.go"
94+ - "go.mod"
95+ - "go.sum"
96+ - "justfile"
97+
98+ - uses : actions/setup-go@v5
99+ if : steps.check_go.outputs.check_go == 'true'
100+ with :
101+ go-version-file : go.mod
102+ # cache: "The action has a built-in functionality for caching and
103+ # restoring go modules and build outputs. It uses [actions/cache@v4]."
104+ # - Handles go module cache (go env GOMODCACHE).
105+ # - Handles go build cache (go env GOCACHE).
106+ cache : true # Note that golangci-lint action already caches for us (https://github.com/golangci/golangci-lint-action#performance)
107+
108+ - name : golangci-lint
109+ if : steps.check_go.outputs.check_go == 'true'
110+ uses : golangci/golangci-lint-action@v8
111+ with :
112+ # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
113+ version : v2.6.1
114+
115+ # Optional: working directory, useful for monorepos
116+ # working-directory: somedir
117+
118+ # Optional: golangci-lint command line arguments.
119+ args : --fix=false
120+
121+ # Optional: show only new issues if it's a pull request. The default
122+ # value is `false`.
123+ # only-new-issues: true
124+
125+ # Optional: if set to true then the all caching functionality will be
126+ # completely disabled. Takes precedence over all other caching options.
127+ skip-cache : false
128+
129+ # Optional: if set to true then the action won't cache or restore ~/go/pkg.
130+ # skip-pkg-cache: true
131+
132+ # Optional: if set to true then the action won't cache or restore ~/.cache/go-build.
133+ # skip-build-cache: true
0 commit comments