11name : Test and Release Go CLI
22
3- on : [push]
3+ on :
4+ pull_request :
5+ push :
6+ branches : [main, master, prod]
7+ tags : ["*"]
48
59# The list of permissions is explained on the GitHub doc:
610# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
@@ -11,84 +15,28 @@ permissions:
1115 pull-requests : read
1216
1317jobs :
14- linter-pull-request :
15- name : golangci-lint on a PR or from a tag
16- runs-on : ubuntu-22.04
17- if : github.ref != 'refs/heads/master'
18+ linter :
19+ name : Linter on a PR
20+ if : ${{ github.event_name == 'pull_request' }}
21+ runs-on : ubuntu-24.04
1822 steps :
19- - uses : actions/checkout@v5
20- with :
21- # We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch
22- fetch-depth : 0
23- - uses : actions/setup-go@v6
24- with :
25- go-version-file : " go.mod"
26- check-latest : true
27- - name : Get golangci-lint configuration file
28- run : wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
29- - name : Get master branch commit ID
30- id : new-from-merge-base
31- run : echo "NEW-FROM-MERGE-BASE=$( git rev-parse origin/master )" >> "$GITHUB_OUTPUT"
32- - name : " Execute golangci-lint on a pull request"
33- uses : golangci/golangci-lint-action@v8
34- with :
35- # The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
36- # We rather decided to use the suggestion from the FAQ (https://golangci-lint.run/welcome/faq/#how-to-integrate-golangci-lint-into-large-project-with-thousands-of-issues) and use `--new-from-merge-base`
37- # only-new-issues: false
38- args : " --config=$(pwd)/.golangci.yml --new-from-merge-base=${{ steps.new-from-merge-base.outputs.NEW-FROM-MERGE-BASE }}"
39-
40- linter-master :
41- name : golangci-lint on master branch
42- runs-on : ubuntu-22.04
43- if : github.ref == 'refs/heads/master'
44- steps :
45- - uses : actions/checkout@v5
46- with :
47- # We need to define the fetch-depth to 2 so that we can get new offenses since HEAD~1
48- fetch-depth : 2
49- - uses : actions/setup-go@v6
50- with :
51- go-version-file : " go.mod"
52- check-latest : true
53- - name : Get golangci-lint configuration file
54- run : wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
55- - name : " Execute golangci-lint on the master branch"
56- uses : golangci/golangci-lint-action@v8
57- with :
58- # The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
59- # We rather decided to use the suggestion from the FAQ (https://golangci-lint.run/usage/faq/#how-to-integrate-golangci-lint-into-large-project-with-thousands-of-issues) and use `--new-from-merge-base`
60- # only-new-issues: false
61- args : " --config=$(pwd)/.golangci.yml --new-from-merge-base=HEAD~1"
23+ - uses : Scalingo/actions/go-linter@main
6224
6325 tests :
6426 name : Unit Tests
65- runs-on : ubuntu-22 .04
27+ runs-on : ubuntu-24 .04
6628 steps :
67- - uses : actions/checkout@v5
68- - uses : actions/setup-go@v6
69- with :
70- go-version-file : " go.mod"
71- check-latest : true
72- - name : go mod vendor
73- run : go mod vendor
74- - name : Execute the tests
75- run : go test -race ./...
29+ - uses : Scalingo/actions/go-tests@main
7630
7731 releases :
78- needs : [linter-master, linter-pull-request, tests]
32+ needs : [tests]
7933 name : GoReleaser Build on All OS but Windows
80- # Usage of needs implies that the job will only run if all the jobs it depends on are successful.
81- # But in our case, either linter-master or linter-pull-request will be skipped.
82- # So we need to add a condition to check if the linter-master or linter-pull-request job is successful.
83- # To do so, we use the `if` condition but we also need to add `always()` to make sure the job is run
84- # related to https://github.com/actions/runner/issues/2205
85- # since a success() is added by default and skipped jobs make success to fail we need this workaround
86- if : always() && startsWith(github.ref, 'refs/tags/') && (needs.linter-master.result == 'success' || needs.linter-pull-request.result == 'success')
87- runs-on : ubuntu-22.04
34+ if : ${{ github.ref_type == 'tag' }}
35+ runs-on : ubuntu-24.04
8836 steps :
8937 - uses : actions/checkout@v5
9038 with :
91- fetch-depth : 0 # See: https://goreleaser.com/ci/actions/
39+ fetch-depth : 0 # required by GoReleaser ( https://goreleaser.com/ci/actions/#fetch-all-history)
9240 - uses : actions/setup-go@v6
9341 with :
9442 go-version-file : " go.mod"
@@ -103,20 +51,14 @@ jobs:
10351 CGO_ENABLED : 0
10452
10553 releases-windows :
106- needs : [linter-master, linter-pull-request, tests]
54+ needs : [tests]
10755 name : GoReleaser Build on Windows
108- # Usage of needs implies that the job will only run if all the jobs it depends on are successful.
109- # But in our case, either linter-master or linter-pull-request will be skipped.
110- # So we need to add a condition to check if the linter-master or linter-pull-request job is successful.
111- # To do so, we use the `if` condition but we also need to add `always()` to make sure the job is run
112- # related to https://github.com/actions/runner/issues/2205
113- # since a success() is added by default and skipped jobs make success to fail we need this workaround
114- if : always() && startsWith(github.ref, 'refs/tags/') && (needs.linter-master.result == 'success' || needs.linter-pull-request.result == 'success')
56+ if : ${{ github.ref_type == 'tag' }}
11557 runs-on : windows-latest
11658 steps :
11759 - uses : actions/checkout@v5
11860 with :
119- fetch-depth : 0 # See: https://goreleaser.com/ci/actions/
61+ fetch-depth : 0 # required by GoReleaser ( https://goreleaser.com/ci/actions/#fetch-all-history)
12062 - uses : actions/setup-go@v6
12163 with :
12264 go-version-file : " go.mod"
0 commit comments