Skip to content

Commit c01e545

Browse files
Boilerplate Github workflow (#14)
* add CODEOWNERS to generated project * Add base pipeline for generated project * add formatting check to project workflow * run tests in the generated project's workflow * use fixed go version set by cookiecutter * Remove dependecy on format being done for build * Set go version for the whole project from cookiecutter * Remove default go version * Require user to set a specific go version * update cookiecutter test pipeline to use go 1.25.4 * use same go version throughout the cc test pipeline
1 parent 3de7b18 commit c01e545

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

.github/workflows/cookiecutter-pipeline.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [ "main" ]
88

9+
env:
10+
GO_VERSION: "1.25.4"
11+
912
jobs:
1013
cookiecutter:
1114
runs-on: ubuntu-latest
@@ -25,6 +28,7 @@ jobs:
2528
run: |
2629
echo 'default_context:
2730
module: gha-test
31+
go_version: ${{ env.GO_VERSION }}
2832
' > cc-context.yaml
2933
3034
- name: Build project
@@ -51,7 +55,7 @@ jobs:
5155
- name: Setup Go
5256
uses: actions/setup-go@v5.5.0
5357
with:
54-
go-version: 'stable'
58+
go-version: ${{ env.GO_VERSION }}
5559

5660
- name: Check formatting
5761
run: |
@@ -79,7 +83,7 @@ jobs:
7983
- name: Setup Go
8084
uses: actions/setup-go@v5.5.0
8185
with:
82-
go-version: 'stable'
86+
go-version: ${{ env.GO_VERSION }}
8387
cache: true
8488

8589
- name: Build

cookiecutter.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"component": "dummy",
66
"description": "Dummy description",
77
"module": "tapir-analyse-{{cookiecutter.component}}",
8-
"module_path": "github.com/dnstapir/{{cookiecutter.module}}"
8+
"module_path": "github.com/dnstapir/{{cookiecutter.module}}",
9+
"go_version": ""
910
}

hooks/pre_gen_project.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
#!/bin/bash
2+
3+
# Validate that go_version is provided
4+
if [ -z "{{cookiecutter.go_version}}" ]; then
5+
echo "ERROR: go_version is required. Please provide a Go version (e.g., '1.25.4')."
6+
exit 1
7+
fi
8+
29
exit 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @dnstapir/core
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Base Pipeline
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
GO_VERSION: "{{ cookiecutter.go_version }}"
11+
jobs:
12+
format:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Go
19+
uses: actions/setup-go@v5.5.0
20+
with:
21+
go-version: {% raw %}${{ env.GO_VERSION }}{% endraw %}
22+
23+
- name: Check formatting
24+
run: |
25+
files=$(gofmt -l ./)
26+
27+
if [ -n "$files" ]; then
28+
while IFS= read -r file; do
29+
echo "::warning file=$file::File is not gofmt formatted"
30+
done <<< "$files"
31+
exit 1
32+
else
33+
echo "✅ All files are properly formatted."
34+
fi
35+
36+
test:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
- name: Setup Go
43+
uses: actions/setup-go@v5.5.0
44+
with:
45+
go-version: {% raw %}${{ env.GO_VERSION }}{% endraw %}
46+
47+
- name: Build
48+
run: |
49+
make build
50+
51+
- name: Test
52+
run: |
53+
make test

{{cookiecutter.module}}/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/dnstapir/{{cookiecutter.module}}
22

3-
go 1.23.6
3+
go {{ cookiecutter.go_version }}
44

55
require github.com/nats-io/nats.go v1.39.1
66

0 commit comments

Comments
 (0)