-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (156 loc) · 6.11 KB
/
go.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: CI
on:
push:
branches: ["**"]
paths-ignore:
- "**.md"
- "docs/**"
- ".github/dependabot.yml"
pull_request:
paths-ignore:
- "**.md"
branches: [main]
env:
BINARY: "server"
GO_VERSION: "1.23"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
# Lint check, using https://github.com/mgechev/revive
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Run Revive Action
uses: docker://morphy/revive-action:v2
with:
config: ./revive.toml
name: "Linter"
pre_flight:
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.tag_version.outputs.new_tag }}
changelog: ${{ steps.tag_version.outputs.changelog }}
steps:
- name: Establish tags and versions
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
framework:
runs-on: ubuntu-latest
needs: [pre_flight]
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^${{ env.GO_VERSION }}"
- name: Setting Up protoc
uses: arduino/setup-protoc@v2
- name: Install protoc Plugins
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
go install github.com/fluffy-bunny/grpcdotnetgo/protoc-gen-go-di/cmd/protoc-gen-go-di
# - name: go mod vendor
# run: |
# go mod tidy -compat="${{ env.GO_VERSION }}"
# go mod download
# go mod vendor
- name: make proto go
run: |
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --grpc-gateway_out . --grpc-gateway_opt paths=source_relative --go-di_out=. --go-di_opt=paths=source_relative,grpc_gateway=true protoc-gen-go-di/helloworld/helloworld.proto
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --grpc-gateway_out . --grpc-gateway_opt paths=source_relative --go-di_out=. --go-di_opt=paths=source_relative,grpc_gateway=true example/internal/grpcContracts/helloworld/helloworld.proto
# - name: move vendor sub folders
# run: |
# mv ./vendor/github.com/fluffy-bunny/sarulabsdi/genny/ ./genny/sarulabsdi/
# rm -rf ./vendor/
#
# - name: Install Mockgen
# run: |
# go install github.com/golang/mock/mockgen@latest
#
#
# - name: Install genny
# run: |
# go version
# go install github.com/cheekybits/genny@latest
#
# - name: GO GENERATE
# run: |
# go generate -x ./...
# rm -rf ./genny/sarulabsdi/
# go mod tidy -compat="${{ env.GO_VERSION }}"
#
# # NOTE: This will NOT trigger another run of CI.yml
# - name: AutoCommit
# uses: stefanzweifel/git-auto-commit-action@v4.16.0
# with:
# commit_message: Apply genny and mockgen changes
###########################################################################
# Test pkg for -race
- name: Test
run: |
go test -v ./... -race
- name: Build
run: |
go build -mod=mod -v -a -tags netgo -ldflags "-X 'main.version=${{ steps.tag_version.outputs.new_tag }}' -extldflags '-static'" ./example/cmd/server
# https://github.com/actions/runner/issues/1353
# -coverpkg not working in this project, but it does work elsewhere
# go test -v ./... -cover -short -coverpkg=./... -coverprofile=coverage/cov.out -json > coverage/report.json
- name: Generate coverage report and lint
run: |
mkdir -p coverage
go test -v ./... -cover -short -coverprofile=coverage/cov.out -json > coverage/report.json
go tool cover -html=coverage/cov.out -o coverage/cov.html
go tool cover -func=coverage/cov.out > coverage/byfunc.txt
go install github.com/mgechev/revive@latest
revive -config ./revive.toml -formatter default ./... > coverage/golint.txt
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage
# Copied from https://github.com/remast/service_sonar/tree/feature/go-build
# and https://dev.to/remast/go-for-sonarcloud-with-github-actions-3pmn
sonar:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: [pre_flight, framework]
steps:
- uses: actions/checkout@v3
- name: Download code coverage results
uses: actions/download-artifact@v3
with:
name: coverage-report
path: coverage
- name: Update version in SonarCloud config
run: |
echo "" >> sonar-project.properties
echo "sonar.projectVersion=${{needs.pre_flight.outputs.new_tag}}" >> sonar-project.properties
- name: Fix GoLint paths
run: sed -i 's~${{ github.workspace }}~/github/workspace~g' coverage/golint.txt
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
release:
needs: [pre_flight, framework]
runs-on: ubuntu-latest
steps:
- run: |
echo new_tag: ${{needs.pre_flight.outputs.new_tag}}
echo changelog: ${{needs.pre_flight.outputs.changelog}}
- name: Create a GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{needs.pre_flight.outputs.new_tag}}
release_name: Release ${{needs.pre_flight.outputs.new_tag}}
body: ${{needs.pre_flight.outputs.changelog}}