-
Notifications
You must be signed in to change notification settings - Fork 24
123 lines (116 loc) · 5.29 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Test and Release Go CLI
on: [push]
permissions:
contents: read
# allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
jobs:
linter-pull-request:
name: golangci-lint on a PR
runs-on: ubuntu-22.04
if: github.ref != 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
# We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Get golangci-lint configuration file
run: wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
- name: Get master branch commit ID
id: new-from-rev
run: echo "NEW_FROM_REV=$( git rev-parse origin/master )" >> "$GITHUB_OUTPUT"
- name: "Execute golangci-lint on a pull request"
uses: golangci/golangci-lint-action@v4
with:
# The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
# 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-rev`
# only-new-issues: false
args: "--config=$(pwd)/.golangci.yml --new-from-rev=${{ steps.new-from-rev.outputs.NEW_FROM_REV }}"
linter-master:
name: golangci-lint on master branch
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
# We need to define the fetch-depth to 2 so that we can get new offenses since HEAD~1
fetch-depth: 2
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Get golangci-lint configuration file
run: wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
- name: "Execute golangci-lint on the master branch"
uses: golangci/golangci-lint-action@v4
with:
# The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
# 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-rev`
# only-new-issues: false
args: "--config=$(pwd)/.golangci.yml --new-from-rev=HEAD~1"
tests:
name: Unit Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Execute the tests
run: go test -race ./...
releases:
needs: [linter-master, linter-pull-request, tests]
name: GoReleaser Build on All OS but Windows
# Usage of needs implies that the job will only run if all the jobs it depends on are successful.
# But in our case, either linter-master or linter-pull-request will be skipped.
# So we need to add a condition to check if the linter-master or linter-pull-request job is successful.
# related to https://github.com/actions/runner/issues/2205
# since a success() is added by default and skipped jobs make success to fail we need this workaround
if: always() && startsWith(github.ref, 'refs/tags/') && (needs.linter-master.result == 'success' || needs.linter-pull-request.result == 'success')
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CGO_ENABLED: 0
releases-windows:
needs: [linter-master, linter-pull-request, tests]
name: GoReleaser Build on Windows
# Usage of needs implies that the job will only run if all the jobs it depends on are successful.
# But in our case, either linter-master or linter-pull-request will be skipped.
# So we need to add a condition to check if the linter-master or linter-pull-request job is successful.
# related to https://github.com/actions/runner/issues/2205
# since a success() is added by default and skipped jobs make success to fail we need this workaround
if: always() && startsWith(github.ref, 'refs/tags/') && (needs.linter-master.result == 'success' || needs.linter-pull-request.result == 'success')
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --config .goreleaser-windows.yaml --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}