Skip to content

Commit a993ac2

Browse files
authored
Feat/improve go actions (#2)
* 📝 Add gitignore and update readme * 🎨 Improve CI workflow + add new features * ✨ Add cd workflow for go release * 🔒 Add CODEOWNERS * 🎨 Implement review comments * remove cache restore Signed-off-by: Alexander Soelberg Heidarsson <89837986+alex5517@users.noreply.github.com> --------- Signed-off-by: Alexander Soelberg Heidarsson <89837986+alex5517@users.noreply.github.com>
1 parent 08f4087 commit a993ac2

6 files changed

Lines changed: 170 additions & 94 deletions

File tree

.github/workflows/go-cd.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
---
3+
name: Go Continuous Delivery
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
go-version:
9+
description: "The version of Go to use"
10+
required: false
11+
type: string
12+
go-private:
13+
description: "The GOPRIVATE environment variable"
14+
required: false
15+
type: string
16+
17+
jobs:
18+
release:
19+
env:
20+
GOPRIVATE: "${{ inputs.go-private }}"
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup Go
29+
if: inputs.go-version != ''
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: ${{ inputs.go-version }}
33+
34+
- name: Setup Go
35+
if: inputs.go-version == ''
36+
uses: actions/setup-go@v5
37+
with:
38+
go-version-file: go.mod
39+
40+
- name: Setup private repository access
41+
if: inputs.go-private != ''
42+
run: git config --global url."https://${{ secrets.gh_username }}:${{ secrets.gh_token }}@github.com".insteadOf "https://github.com"
43+
44+
- name: Run GoReleaser dry-run
45+
uses: goreleaser/goreleaser-action@v6
46+
with:
47+
distribution: goreleaser
48+
version: latest
49+
args: release --clean
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/go-ci.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
---
3+
name: Go Continuous Integration
4+
5+
on:
6+
workflow_call:
7+
secrets:
8+
gh_username:
9+
required: false
10+
gh_token:
11+
required: false
12+
inputs:
13+
go-version:
14+
description: "The version of Go to use"
15+
required: false
16+
type: string
17+
go-private:
18+
description: "The GOPRIVATE environment variable"
19+
required: false
20+
type: string
21+
run-benchmarks:
22+
description: "Run benchmarks"
23+
required: false
24+
default: false
25+
type: boolean
26+
run-release-test:
27+
description: "Run release dry-run using GoReleaser"
28+
required: false
29+
default: false
30+
type: boolean
31+
32+
jobs:
33+
tests:
34+
env:
35+
GOPRIVATE: "${{ inputs.go-private }}"
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v4
40+
41+
- name: Setup Go
42+
if: inputs.go-version != ''
43+
uses: actions/setup-go@v5
44+
with:
45+
go-version: ${{ inputs.go-version }}
46+
47+
- name: Setup Go
48+
if: inputs.go-version == ''
49+
uses: actions/setup-go@v5
50+
with:
51+
go-version-file: go.mod
52+
53+
- name: Setup private repository access
54+
if: inputs.go-private != ''
55+
run: git config --global url."https://${{ secrets.gh_username }}:${{ secrets.gh_token }}@github.com".insteadOf "https://github.com"
56+
57+
- name: Check go mod tidy
58+
run: |
59+
go mod tidy
60+
if git diff --exit-code go.mod go.sum; then
61+
echo "go.mod and go.sum are tidy."
62+
else
63+
echo "::error go.mod or go.sum are not tidy. Please run 'go mod tidy'."
64+
exit 1
65+
fi
66+
67+
- name: Install Go dependencies
68+
run: |
69+
go mod download
70+
go mod verify
71+
72+
- name: golangci-lint
73+
uses: golangci/golangci-lint-action@v6
74+
with:
75+
version: latest
76+
77+
# go test will compile the code, so we don't need to run go build
78+
- name: Go Compile and Test
79+
run: go test -cover -v ./...
80+
81+
- name: Run benchmarks
82+
if: inputs.run-benchmarks
83+
run: go test -bench=./...
84+
85+
- name: Install GoReleaser
86+
uses: goreleaser/goreleaser-action@v6
87+
with:
88+
distribution: goreleaser
89+
version: latest
90+
install-only: true
91+
92+
- name: Run GoReleaser healthcheck
93+
run: goreleaser healthcheck
94+
95+
- name: Check GoReleaser config
96+
run: goreleaser check
97+
98+
- name: Run GoReleaser dry-run
99+
if: inputs.run-release-test
100+
run: goreleaser release --snapshot --skip=publish --clean
101+
102+
vuln-scan:
103+
runs-on: ubuntu-latest
104+
steps:
105+
- name: Checkout code
106+
uses: actions/checkout@v4
107+
- name: Run Trivy vulnerability scanner
108+
uses: aquasecurity/trivy-action@0.30.0
109+
with:
110+
scan-type: "fs"
111+
format: "table"
112+
exit-code: "1"
113+
ignore-unfixed: true
114+
vuln-type: "library"

.github/workflows/go-ci.yml

Lines changed: 0 additions & 93 deletions
This file was deleted.

.github/workflows/go-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go-ci.yaml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Owner: platform-development @Netic
2+
* @neticdk/platform-development

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In your workflow do something like:
77
```yaml
88
jobs:
99
the-job:
10-
uses: neticdk/shared-github-actions/.github/workflows/the-flow.yml@main
10+
uses: neticdk/shared-github-actions/.github/workflows/the-flow.yaml@main
1111
with:
1212
my-input: my-value
1313
```

0 commit comments

Comments
 (0)