Skip to content

Commit d6e09cf

Browse files
committed
ci: add release please workflow
1 parent f8084a0 commit d6e09cf

File tree

8 files changed

+141
-40
lines changed

8 files changed

+141
-40
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,17 @@ jobs:
1010
test:
1111
name: Test
1212
runs-on: ubuntu-latest
13-
1413
steps:
1514
- name: Checkout code
1615
uses: actions/checkout@v5
1716

1817
- name: Set up Go
1918
uses: actions/setup-go@v6
2019
with:
21-
go-version: '1.25'
22-
23-
- name: Run tests
24-
run: go test -v -race -coverprofile=coverage.out ./...
25-
26-
- name: Check coverage
27-
run: go tool cover -func=coverage.out
28-
29-
lint:
30-
name: Lint
31-
runs-on: ubuntu-latest
32-
33-
steps:
34-
- name: Checkout code
35-
uses: actions/checkout@v5
36-
37-
- name: Set up Go
38-
uses: actions/setup-go@v5
39-
with:
40-
go-version: '1.25'
41-
42-
- name: golangci-lint
43-
uses: golangci/golangci-lint-action@v8
44-
with:
45-
version: latest
20+
go-version-file: "go.mod"
4621

47-
benchmark:
48-
name: Benchmark
49-
runs-on: ubuntu-latest
50-
51-
steps:
52-
- name: Checkout code
53-
uses: actions/checkout@v5
54-
55-
- name: Set up Go
56-
uses: actions/setup-go@v5
57-
with:
58-
go-version: '1.25'
22+
- name: Install Mage
23+
run: go install github.com/magefile/mage@latest
5924

60-
- name: Run benchmarks
61-
run: go test -bench=. -benchmem
25+
- name: Run CI
26+
run: mage ci
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
release-please:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: googleapis/release-please-action@v4
18+
id: release
19+
with:
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Checkout
23+
if: ${{ steps.release.outputs.release_created }}
24+
uses: actions/checkout@v6
25+
26+
- name: Setup Go
27+
if: ${{ steps.release.outputs.release_created }}
28+
uses: actions/setup-go@v6
29+
with:
30+
go-version-file: "go.mod"
31+
32+
- name: Install Mage
33+
if: ${{ steps.release.outputs.release_created }}
34+
run: go install github.com/magefile/mage@latest
35+
36+
- name: Run full CI validation
37+
if: ${{ steps.release.outputs.release_created }}
38+
run: mage ci

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.3.4"
3+
}

VERSION

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

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/contriboss/pubgrub-go
22

33
go 1.25
4+
5+
require github.com/magefile/mage v1.15.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
2+
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=

magefile.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//go:build mage
2+
// +build mage
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
"os"
9+
10+
"github.com/magefile/mage/sh"
11+
)
12+
13+
// CI runs all validation checks (tests, linting, coverage, benchmarks)
14+
func CI() error {
15+
fmt.Println("Running full CI validation...")
16+
17+
if err := Test(); err != nil {
18+
return err
19+
}
20+
21+
if err := Lint(); err != nil {
22+
return err
23+
}
24+
25+
if err := Benchmark(); err != nil {
26+
return err
27+
}
28+
29+
fmt.Println("All CI checks passed!")
30+
return nil
31+
}
32+
33+
// Test runs all tests with race detection and coverage
34+
func Test() error {
35+
fmt.Println("Running tests with race detection...")
36+
if err := sh.RunV("go", "test", "-v", "-race", "-coverprofile=coverage.out", "./..."); err != nil {
37+
return err
38+
}
39+
40+
fmt.Println("Generating coverage report...")
41+
return sh.RunV("go", "tool", "cover", "-func=coverage.out")
42+
}
43+
44+
// Lint runs golangci-lint
45+
func Lint() error {
46+
fmt.Println("Running linter...")
47+
return sh.RunV("golangci-lint", "run", "--timeout=5m")
48+
}
49+
50+
// Benchmark runs all benchmarks
51+
func Benchmark() error {
52+
fmt.Println("Running benchmarks...")
53+
return sh.RunV("go", "test", "-bench=.", "-benchmem")
54+
}
55+
56+
// Clean removes build artifacts and coverage files
57+
func Clean() error {
58+
fmt.Println("Cleaning build artifacts...")
59+
os.Remove("coverage.out")
60+
return nil
61+
}
62+
63+
// Fmt formats all Go code
64+
func Fmt() error {
65+
fmt.Println("Formatting code...")
66+
return sh.RunV("go", "fmt", "./...")
67+
}
68+
69+
// Vet runs go vet
70+
func Vet() error {
71+
fmt.Println("Running go vet...")
72+
return sh.RunV("go", "vet", "./...")
73+
}
74+
75+
// ModTidy tidies go.mod
76+
func ModTidy() error {
77+
fmt.Println("Tidying go.mod...")
78+
return sh.RunV("go", "mod", "tidy")
79+
}

release-please-config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"release-type": "simple",
3+
"packages": {
4+
".": {
5+
"version-file": "VERSION",
6+
"package-name": "pubgrub-go",
7+
"include-component-in-tag": false,
8+
"tag-separator": ""
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)