Skip to content

Commit 21ac54d

Browse files
committed
feat: adding predefined go actions
1 parent c22907f commit 21ac54d

4 files changed

Lines changed: 251 additions & 0 deletions

File tree

.github/workflows/go-build.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Go Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
path:
7+
description: 'Working directory (path to module root)'
8+
required: false
9+
default: '.'
10+
type: string
11+
go_version:
12+
description: 'Go version to use'
13+
required: false
14+
default: 'stable'
15+
type: string
16+
output:
17+
description: 'Output binary path passed to -o (omit to skip -o)'
18+
required: false
19+
default: ''
20+
type: string
21+
ldflags:
22+
description: 'Linker flags passed to -ldflags'
23+
required: false
24+
default: ''
25+
type: string
26+
runner:
27+
description: 'Runner label'
28+
required: false
29+
default: 'self-hosted'
30+
type: string
31+
32+
jobs:
33+
go-build:
34+
runs-on: ${{ inputs.runner }}
35+
defaults:
36+
run:
37+
working-directory: ${{ inputs.path }}
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
41+
42+
- name: Set up Go
43+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
44+
with:
45+
go-version: ${{ inputs.go_version }}
46+
cache-dependency-path: ${{ inputs.path }}/go.sum
47+
48+
- name: Build
49+
env:
50+
OUTPUT: ${{ inputs.output }}
51+
LDFLAGS: ${{ inputs.ldflags }}
52+
run: |
53+
ARGS=()
54+
[ -n "${OUTPUT}" ] && ARGS+=(-o "${OUTPUT}")
55+
[ -n "${LDFLAGS}" ] && ARGS+=(-ldflags "${LDFLAGS}")
56+
go build "${ARGS[@]}" ./...

.github/workflows/go-test.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Go Test
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
path:
7+
description: 'Working directory (path to module root)'
8+
required: false
9+
default: '.'
10+
type: string
11+
go_version:
12+
description: 'Go version to use'
13+
required: false
14+
default: 'stable'
15+
type: string
16+
race:
17+
description: 'Enable race detector (-race)'
18+
required: false
19+
default: false
20+
type: boolean
21+
run:
22+
description: 'Test filter passed to -run'
23+
required: false
24+
default: ''
25+
type: string
26+
args:
27+
description: 'Extra arguments passed to go test'
28+
required: false
29+
default: ''
30+
type: string
31+
runner:
32+
description: 'Runner label'
33+
required: false
34+
default: 'self-hosted'
35+
type: string
36+
37+
jobs:
38+
go-test:
39+
runs-on: ${{ inputs.runner }}
40+
defaults:
41+
run:
42+
working-directory: ${{ inputs.path }}
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46+
47+
- name: Set up Go
48+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
49+
with:
50+
go-version: ${{ inputs.go_version }}
51+
cache-dependency-path: ${{ inputs.path }}/go.sum
52+
53+
- name: Test
54+
env:
55+
RACE: ${{ inputs.race }}
56+
RUN_FILTER: ${{ inputs.run }}
57+
EXTRA_ARGS: ${{ inputs.args }}
58+
run: |
59+
ARGS=()
60+
[ "${RACE}" == "true" ] && ARGS+=(-race)
61+
[ -n "${RUN_FILTER}" ] && ARGS+=(-run "${RUN_FILTER}")
62+
[ -n "${EXTRA_ARGS}" ] && ARGS+=(${EXTRA_ARGS})
63+
go test "${ARGS[@]}" ./...
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: golangci-lint
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
path:
7+
description: 'Working directory (path to module root)'
8+
required: false
9+
default: '.'
10+
type: string
11+
go_version:
12+
description: 'Go version to use'
13+
required: false
14+
default: 'stable'
15+
type: string
16+
golangci_lint_version:
17+
description: 'golangci-lint version'
18+
required: false
19+
default: 'v1.64.8' # renovate: datasource=github-releases depName=golangci/golangci-lint
20+
type: string
21+
args:
22+
description: 'Extra arguments passed to golangci-lint run'
23+
required: false
24+
default: ''
25+
type: string
26+
runner:
27+
description: 'Runner label'
28+
required: false
29+
default: 'self-hosted'
30+
type: string
31+
32+
jobs:
33+
golangci-lint:
34+
runs-on: ${{ inputs.runner }}
35+
defaults:
36+
run:
37+
working-directory: ${{ inputs.path }}
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
41+
42+
- name: Set up Go
43+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
44+
with:
45+
go-version: ${{ inputs.go_version }}
46+
cache-dependency-path: ${{ inputs.path }}/go.sum
47+
48+
- name: golangci-lint
49+
uses: golangci/golangci-lint-action@82606bf257cbaff209d206a39f5134f0cfbfd2ee # v9.2.1
50+
with:
51+
version: ${{ inputs.golangci_lint_version }}
52+
working-directory: ${{ inputs.path }}
53+
args: ${{ inputs.args }}

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,85 @@ deploy:
165165

166166
---
167167

168+
### `go-build.yml` — Go Build
169+
170+
Compiles all packages in a Go module with `go build ./...`.
171+
172+
#### Inputs
173+
174+
| Name | Required | Default | Description |
175+
|------|----------|---------|-------------|
176+
| `path` | no | `'.'` | Working directory (path to module root) |
177+
| `go_version` | no | `'stable'` | Go version to use |
178+
| `output` | no | `''` | Output binary path passed to `-o` (omit to skip) |
179+
| `ldflags` | no | `''` | Linker flags passed to `-ldflags` |
180+
| `runner` | no | `'self-hosted'` | Runner label |
181+
182+
#### Example
183+
184+
```yaml
185+
build:
186+
uses: mogenius/github-actions/.github/workflows/go-build.yml@<sha> # main
187+
with:
188+
go_version: '1.24.x'
189+
ldflags: '-X main.version=${{ needs.prepare.outputs.version }}'
190+
```
191+
192+
---
193+
194+
### `go-test.yml` — Go Test
195+
196+
Runs `go test ./...` with optional race detector and test filtering.
197+
198+
#### Inputs
199+
200+
| Name | Required | Default | Description |
201+
|------|----------|---------|-------------|
202+
| `path` | no | `'.'` | Working directory (path to module root) |
203+
| `go_version` | no | `'stable'` | Go version to use |
204+
| `race` | no | `false` | Enable race detector (`-race`) |
205+
| `run` | no | `''` | Test filter passed to `-run` |
206+
| `args` | no | `''` | Extra arguments passed to `go test` |
207+
| `runner` | no | `'self-hosted'` | Runner label |
208+
209+
#### Example
210+
211+
```yaml
212+
test:
213+
uses: mogenius/github-actions/.github/workflows/go-test.yml@<sha> # main
214+
with:
215+
go_version: '1.24.x'
216+
race: true
217+
```
218+
219+
---
220+
221+
### `golangci-lint.yml` — golangci-lint
222+
223+
Runs [golangci-lint](https://golangci-lint.run/) via the official action. Respects a `.golangci.yml` config in the repository if present.
224+
225+
#### Inputs
226+
227+
| Name | Required | Default | Description |
228+
|------|----------|---------|-------------|
229+
| `path` | no | `'.'` | Working directory (path to module root) |
230+
| `go_version` | no | `'stable'` | Go version to use |
231+
| `golangci_lint_version` | no | `'v1.64.8'` | golangci-lint version (Renovate-tracked) |
232+
| `args` | no | `''` | Extra arguments passed to `golangci-lint run` |
233+
| `runner` | no | `'self-hosted'` | Runner label |
234+
235+
#### Example
236+
237+
```yaml
238+
lint:
239+
uses: mogenius/github-actions/.github/workflows/golangci-lint.yml@<sha> # main
240+
with:
241+
go_version: '1.24.x'
242+
args: '--timeout 5m'
243+
```
244+
245+
---
246+
168247
### `helm-lint.yml` — Helm Lint
169248

170249
Runs `helm lint` against a chart directory.

0 commit comments

Comments
 (0)