Skip to content

Commit fa00a90

Browse files
committed
πŸš€ Add complete CI/CD pipeline with GitHub Actions and pre-commit hooks ✨
- **Added .github/workflows/ci.yml**: Comprehensive CI workflow that runs tests, linting, and builds across Go versions 1.21-1.23 with coverage reporting to Codecov πŸ“Š - **Added .github/workflows/release.yml**: GoReleaser workflow for automated releases on version tags with macOS runner and Homebrew tap support 🍺 - **Added .pre-commit-config.yaml**: Pre-commit hooks for code quality including Go formatting, imports, linting, tests, and file validation to catch issues before commits πŸ”§ - **Updated go.mod**: Fixed dependency declarations by moving actual dependencies (toml, dateparse, sqlite3, cobra) from indirect to direct requires - this properly reflects what the code actually imports πŸ“¦ The CI pipeline ensures code quality with multi-version testing and race detection, while the pre-commit hooks catch issues early in development. The release workflow enables automated binary distribution when tags are pushed! πŸŽ‰
1 parent a7dd21b commit fa00a90

5 files changed

Lines changed: 192 additions & 4 deletions

File tree

β€Ž.github/workflows/ci.ymlβ€Ž

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# ABOUTME: GitHub Actions CI workflow for pagen
2+
# ABOUTME: Runs tests, linting, and builds on multiple Go versions
3+
name: CI
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
pull_request:
9+
branches: [ main ]
10+
11+
jobs:
12+
test:
13+
name: Test
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
go-version: ['1.21', '1.22', '1.23']
18+
steps:
19+
- name: Check out code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: ${{ matrix.go-version }}
28+
cache: true
29+
30+
- name: Cache Go modules
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/go/pkg/mod
34+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
35+
restore-keys: |
36+
${{ runner.os }}-go-
37+
38+
- name: Download dependencies
39+
run: go mod download
40+
41+
- name: Run tests
42+
run: make test-race
43+
44+
- name: Run tests with coverage
45+
if: matrix.go-version == '1.23'
46+
run: make test-coverage
47+
48+
- name: Upload coverage to Codecov
49+
if: matrix.go-version == '1.23'
50+
uses: codecov/codecov-action@v4
51+
with:
52+
file: ./coverage.out
53+
flags: unittests
54+
fail_ci_if_error: false
55+
56+
lint:
57+
name: Lint
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Check out code
61+
uses: actions/checkout@v4
62+
63+
- name: Set up Go
64+
uses: actions/setup-go@v5
65+
with:
66+
go-version: '1.23'
67+
cache: true
68+
69+
- name: Run golangci-lint
70+
uses: golangci/golangci-lint-action@v6
71+
with:
72+
version: latest
73+
args: --timeout=10m
74+
75+
build:
76+
name: Build
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Check out code
80+
uses: actions/checkout@v4
81+
82+
- name: Set up Go
83+
uses: actions/setup-go@v5
84+
with:
85+
go-version: '1.23'
86+
cache: true
87+
88+
- name: Build binary
89+
run: make build
90+
91+
- name: Verify binary
92+
run: ./pagen --version
93+
94+
- name: Upload binary artifact
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: pagen-linux-amd64
98+
path: pagen
99+
retention-days: 7
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
release:
14+
name: Release
15+
runs-on: macos-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: '1.21'
26+
cache: true
27+
28+
- name: Run GoReleaser
29+
uses: goreleaser/goreleaser-action@v6
30+
with:
31+
distribution: goreleaser
32+
version: latest
33+
args: release --clean
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}

β€Ž.pre-commit-config.yamlβ€Ž

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# ABOUTME: Pre-commit hooks configuration for pagen project
2+
# ABOUTME: Runs formatting, linting, and tests before each commit
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.6.0
6+
hooks:
7+
- id: trailing-whitespace
8+
exclude: ^go\.(mod|sum)$
9+
- id: end-of-file-fixer
10+
exclude: ^go\.(mod|sum)$
11+
- id: check-yaml
12+
- id: check-added-large-files
13+
args: ['--maxkb=1000'] # Block files > 1MB (except binary)
14+
exclude: ^pagen$ # Allow the binary
15+
- id: check-merge-conflict
16+
- id: mixed-line-ending
17+
args: ['--fix=lf']
18+
- id: check-case-conflict
19+
20+
- repo: https://github.com/dnephin/pre-commit-golang
21+
rev: v0.5.1
22+
hooks:
23+
- id: go-fmt
24+
- id: go-imports
25+
- id: go-mod-tidy
26+
- id: golangci-lint
27+
args: ['--timeout=10m', '--fix']
28+
- id: go-unit-tests
29+
args: ['-race', '-count=1', './...'] # -count=1 disables test caching
30+
31+
- repo: local
32+
hooks:
33+
- id: go-mod-verify
34+
name: go mod verify
35+
entry: go mod verify
36+
language: system
37+
files: go\.(mod|sum)$
38+
pass_filenames: false
39+
40+
- id: go-vet
41+
name: go vet
42+
entry: go vet
43+
language: system
44+
args: ['./...']
45+
files: \.go$
46+
pass_filenames: false

β€Žgo.modβ€Ž

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ module github.com/harper/chronicle
33
go 1.22
44

55
require (
6-
github.com/BurntSushi/toml v1.5.0 // indirect
7-
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
6+
github.com/BurntSushi/toml v1.5.0
7+
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
8+
github.com/mattn/go-sqlite3 v1.14.32
9+
github.com/spf13/cobra v1.10.1
10+
)
11+
12+
require (
813
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9-
github.com/mattn/go-sqlite3 v1.14.32 // indirect
10-
github.com/spf13/cobra v1.10.1 // indirect
1114
github.com/spf13/pflag v1.0.10 // indirect
1215
)

β€Žgo.sumβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2
33
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA=
44
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
55
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
6+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
67
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
78
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
89
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
910
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
1011
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
1112
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1214
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1315
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
1416
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -19,7 +21,9 @@ github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
1921
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
2022
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
2123
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
24+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
2225
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2326
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2427
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
28+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2529
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
Β (0)