Skip to content

Commit 6e7d68a

Browse files
committed
Add CI, release pipelines and release tooling
Add GitHub Actions workflows for CI and releases, plus goreleaser and git-cliff configuration. Include scripts/release.sh and Makefile targets for release/snapshot and enable build-time vars (AppVersion, BuildDate, GitCommit) injectable via ldflags in cmd/root.go.
1 parent 5c8311c commit 6e7d68a

25 files changed

Lines changed: 2141 additions & 1248 deletions

File tree

.github/workflows/ci.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# ==============================================================================
2+
# .github/workflows/ci.yml — cpp-gen
3+
# ==============================================================================
4+
# Continuous integration pipeline. Runs on every push to main/master
5+
# and on pull requests, ensuring the project compiles and passes tests.
6+
# ==============================================================================
7+
8+
name: CI
9+
10+
on:
11+
push:
12+
branches:
13+
- main
14+
- master
15+
# Ignores tag pushes (covered by the release.yml workflow)
16+
tags-ignore:
17+
- "**"
18+
pull_request:
19+
branches:
20+
- main
21+
- master
22+
23+
# Cancels previous runs of the same PR/branch to save minutes
24+
concurrency:
25+
group: ci-${{ github.ref }}
26+
cancel-in-progress: true
27+
28+
jobs:
29+
# ── Build & Test ─────────────────────────────────────────────────────────────
30+
build:
31+
name: Build & Test (Go ${{ matrix.go-version }})
32+
runs-on: ubuntu-latest
33+
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
go-version:
38+
- "1.22"
39+
- "1.23"
40+
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
45+
- name: Setup Go ${{ matrix.go-version }}
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: ${{ matrix.go-version }}
49+
cache: true
50+
51+
- name: Verify dependencies
52+
run: |
53+
go mod verify
54+
go mod tidy
55+
git diff --exit-code go.mod go.sum
56+
57+
- name: go vet
58+
run: go vet ./...
59+
60+
- name: Build
61+
run: |
62+
go build -trimpath -ldflags "-s -w \
63+
-X cpp-gen/cmd.AppVersion=ci \
64+
-X cpp-gen/cmd.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
65+
-X cpp-gen/cmd.GitCommit=${GITHUB_SHA::7}" \
66+
-o /dev/null .
67+
68+
- name: Test
69+
run: go test -v -race -coverprofile=coverage.out ./...
70+
71+
- name: Upload coverage
72+
if: matrix.go-version == '1.22'
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: coverage
76+
path: coverage.out
77+
retention-days: 7
78+
79+
# ── Cross-compilation check ───────────────────────────────────────────────────
80+
# Ensures the binary compiles for all targets that goreleaser will generate.
81+
cross-build:
82+
name: Cross-compile (${{ matrix.goos }}/${{ matrix.goarch }})
83+
runs-on: ubuntu-latest
84+
85+
strategy:
86+
fail-fast: false
87+
matrix:
88+
include:
89+
- goos: linux
90+
goarch: amd64
91+
- goos: linux
92+
goarch: arm64
93+
- goos: darwin
94+
goarch: amd64
95+
- goos: darwin
96+
goarch: arm64
97+
98+
steps:
99+
- name: Checkout
100+
uses: actions/checkout@v4
101+
102+
- name: Setup Go
103+
uses: actions/setup-go@v5
104+
with:
105+
go-version: "1.22"
106+
cache: true
107+
108+
- name: Cross-compile ${{ matrix.goos }}/${{ matrix.goarch }}
109+
env:
110+
GOOS: ${{ matrix.goos }}
111+
GOARCH: ${{ matrix.goarch }}
112+
CGO_ENABLED: "0"
113+
run: |
114+
go build -trimpath -ldflags "-s -w \
115+
-X cpp-gen/cmd.AppVersion=ci \
116+
-X cpp-gen/cmd.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
117+
-X cpp-gen/cmd.GitCommit=${GITHUB_SHA::7}" \
118+
-o /dev/null .
119+
120+
# ── Lint ──────────────────────────────────────────────────────────────────────
121+
lint:
122+
name: Lint
123+
runs-on: ubuntu-latest
124+
125+
steps:
126+
- name: Checkout
127+
uses: actions/checkout@v4
128+
129+
- name: Setup Go
130+
uses: actions/setup-go@v5
131+
with:
132+
go-version: "1.22"
133+
cache: true
134+
135+
- name: golangci-lint
136+
uses: golangci/golangci-lint-action@v6
137+
with:
138+
version: latest
139+
args: --timeout=5m

.github/workflows/release.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# ==============================================================================
2+
# .github/workflows/release.yml — cpp-gen
3+
# ==============================================================================
4+
# Release pipeline. Triggered automatically when a tag in the format
5+
# vX.Y.Z is pushed to the repository (e.g.: via `make release` or scripts/release.sh).
6+
#
7+
# Full flow:
8+
# git commit → scripts/release.sh → tag vX.Y.Z → this workflow → goreleaser
9+
#
10+
# binários + archives + GitHub Release
11+
# ==============================================================================
12+
13+
name: Release
14+
15+
on:
16+
push:
17+
tags:
18+
- "v[0-9]+.[0-9]+.[0-9]+" # v1.2.3
19+
- "v[0-9]+.[0-9]+.[0-9]+-*" # v1.2.3-beta.1 (pre-release)
20+
21+
# Minimum permissions required for goreleaser to create the release
22+
permissions:
23+
contents: write # create releases and upload assets
24+
packages: write # publish packages (if needed in the future)
25+
26+
jobs:
27+
# ── Goreleaser ───────────────────────────────────────────────────────────────
28+
goreleaser:
29+
name: Release ${{ github.ref_name }}
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout (com histórico completo)
34+
uses: actions/checkout@v4
35+
with:
36+
# fetch-depth 0 is required for goreleaser to generate the changelog
37+
# correctly from the full commit and tag history.
38+
fetch-depth: 0
39+
40+
- name: Setup Go
41+
uses: actions/setup-go@v5
42+
with:
43+
go-version-file: go.mod
44+
cache: true
45+
46+
- name: Verify dependencies
47+
run: |
48+
go mod verify
49+
go mod tidy
50+
git diff --exit-code go.mod go.sum
51+
52+
# Runs tests before publishing — failure here aborts the release
53+
- name: Test
54+
run: go test -race ./...
55+
56+
- name: Run goreleaser
57+
uses: goreleaser/goreleaser-action@v6
58+
with:
59+
distribution: goreleaser
60+
version: "~> v2"
61+
args: release --clean
62+
env:
63+
# GitHub token to create the release and upload assets.
64+
# GITHUB_TOKEN is automatically injected by Actions — no extra configuration needed.
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
67+
# ── Completion notification ───────────────────────────────────────────────────
68+
notify:
69+
name: Notify
70+
runs-on: ubuntu-latest
71+
needs: goreleaser
72+
if: always()
73+
74+
steps:
75+
- name: Release succeeded
76+
if: needs.goreleaser.result == 'success'
77+
run: |
78+
echo "::notice title=Release publicada::cpp-gen ${{ github.ref_name }} foi publicada com sucesso!"
79+
echo "URL: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}"
80+
81+
- name: Release failed
82+
if: needs.goreleaser.result == 'failure'
83+
run: |
84+
echo "::error title=Falha na release::O goreleaser falhou para a tag ${{ github.ref_name }}."
85+
exit 1

.goreleaser.yaml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# ==============================================================================
2+
# .goreleaser.yaml — cpp-gen
3+
# ==============================================================================
4+
# Documentation: https://goreleaser.com/customization/
5+
#
6+
# Trigger:
7+
# goreleaser release --clean → full release (CI)
8+
# goreleaser release --snapshot --clean → local build without publishing
9+
# ==============================================================================
10+
11+
version: 2
12+
13+
# ── Project metadata ─────────────────────────────────────────────────────────
14+
15+
project_name: cpp-gen
16+
17+
# ── Pre-build hooks ───────────────────────────────────────────────────────────
18+
19+
before:
20+
hooks:
21+
- go mod tidy
22+
- go mod verify
23+
24+
# ── Global environment variables ─────────────────────────────────────────────
25+
26+
env:
27+
- CGO_ENABLED=0
28+
29+
# ── Builds ────────────────────────────────────────────────────────────────────
30+
31+
builds:
32+
- id: cpp-gen
33+
main: .
34+
binary: cpp-gen
35+
36+
goos:
37+
- linux
38+
- darwin
39+
40+
goarch:
41+
- amd64
42+
- arm64
43+
44+
# Compilation flags
45+
flags:
46+
- -trimpath
47+
48+
# Injects version, date and commit into the binary — same variables as the Makefile.
49+
# NOTE: AppVersion, BuildDate and GitCommit must be declared as
50+
# `var` (not `const`) in cmd/root.go for the injection to work.
51+
ldflags:
52+
- -s -w
53+
- -X cpp-gen/cmd.AppVersion={{.Version}}
54+
- -X cpp-gen/cmd.BuildDate={{.Date}}
55+
- -X cpp-gen/cmd.GitCommit={{.ShortCommit}}
56+
57+
# ── Archives ──────────────────────────────────────────────────────────────────
58+
59+
archives:
60+
- id: default
61+
format: tar.gz
62+
# cpp-gen_1.2.3_linux_amd64.tar.gz
63+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
64+
files:
65+
- LICENSE
66+
- README.md
67+
68+
# ── Checksums ─────────────────────────────────────────────────────────────────
69+
70+
checksum:
71+
name_template: checksums.txt
72+
algorithm: sha256
73+
74+
# ── Changelog ─────────────────────────────────────────────────────────────────
75+
# Generated from commit messages following the Conventional Commits convention.
76+
77+
changelog:
78+
use: git
79+
sort: asc
80+
81+
filters:
82+
exclude:
83+
- "^docs:"
84+
- "^test:"
85+
- "^ci:"
86+
- "^chore:"
87+
- "^style:"
88+
- "Merge pull request"
89+
- "Merge branch"
90+
91+
groups:
92+
- title: "💥 Breaking Changes"
93+
regexp: '^.*!(\(.+\))?:.*'
94+
order: 0
95+
- title: "⚡ Novas Funcionalidades"
96+
regexp: "^feat"
97+
order: 1
98+
- title: "🐛 Correções"
99+
regexp: "^fix"
100+
order: 2
101+
- title: "🚀 Performance"
102+
regexp: "^perf"
103+
order: 3
104+
- title: "♻️ Refatorações"
105+
regexp: "^refactor"
106+
order: 4
107+
- title: "🔧 Outros"
108+
order: 999
109+
110+
# ── GitHub Release ────────────────────────────────────────────────────────────
111+
112+
release:
113+
# Automatically detects pre-release by semver suffixes (e.g.: v1.0.0-beta.1)
114+
prerelease: auto
115+
116+
# false = publishes immediately; true = saves as draft
117+
draft: false
118+
119+
name_template: "v{{.Version}}"
120+
121+
header: |
122+
## cpp-gen v{{.Version}}
123+
124+
Gerador moderno de projetos C++ com CMake, VCPKG, FetchContent e suporte a múltiplas IDEs.
125+
126+
footer: |
127+
---
128+
129+
### Instalação
130+
131+
**Arch Linux (AUR)**
132+
```sh
133+
yay -S cpp-gen
134+
```
135+
136+
**Linux / macOS — manual**
137+
```sh
138+
# Exemplo para Linux x86_64
139+
curl -LO https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/cpp-gen/releases/download/v{{.Version}}/cpp-gen_{{.Version}}_linux_amd64.tar.gz
140+
tar -xzf cpp-gen_{{.Version}}_linux_amd64.tar.gz
141+
install -m755 cpp-gen ~/.local/bin/
142+
```
143+
144+
> **Verifique o checksum:** `sha256sum -c checksums.txt`

0 commit comments

Comments
 (0)