Skip to content

Commit 4dffbac

Browse files
committed
chore: add GoReleaser
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent 650ffc0 commit 4dffbac

File tree

4 files changed

+274
-33
lines changed

4 files changed

+274
-33
lines changed

.github/goreleaser.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
version: 2
3+
4+
before:
5+
hooks:
6+
- go mod tidy
7+
8+
builds:
9+
- id: protoc-gen-connect-go-servicestruct
10+
main: ./cmd/protoc-gen-connect-go-servicestruct
11+
binary: protoc-gen-connect-go-servicestruct
12+
skip: '{{ ne .Env.BUILD_COMPONENT "protoc-gen-connect-go-servicestruct" }}'
13+
env:
14+
- CGO_ENABLED=0
15+
goos:
16+
- linux
17+
- darwin
18+
- windows
19+
goarch:
20+
- amd64
21+
- arm64
22+
ldflags:
23+
- -s -w
24+
- -X main.version={{.Version}}
25+
- -X main.commit={{.Commit}}
26+
- -X main.date={{.Date}}
27+
28+
- id: protoc-gen-elixir-grpc
29+
main: ./cmd/protoc-gen-elixir-grpc
30+
binary: protoc-gen-elixir-grpc
31+
skip: '{{ ne .Env.BUILD_COMPONENT "protoc-gen-elixir-grpc" }}'
32+
env:
33+
- CGO_ENABLED=0
34+
goos:
35+
- linux
36+
- darwin
37+
- windows
38+
goarch:
39+
- amd64
40+
- arm64
41+
ldflags:
42+
- -s -w
43+
- -X main.version={{.Version}}
44+
- -X main.commit={{.Commit}}
45+
- -X main.date={{.Date}}
46+
47+
archives:
48+
- id: default
49+
name_template: >-
50+
{{ .Env.BUILD_COMPONENT }}_
51+
{{- .Version }}_
52+
{{- title .Os }}_
53+
{{- if eq .Arch "amd64" }}x86_64
54+
{{- else if eq .Arch "386" }}i386
55+
{{- else }}{{ .Arch }}{{ end }}
56+
{{- if .Arm }}v{{ .Arm }}{{ end }}
57+
files:
58+
- LICENSE
59+
- README.md
60+
- cmd/*/README.md
61+
- cmd/*/CHANGELOG.md
62+
63+
checksum:
64+
name_template: "checksums.txt"
65+
66+
snapshot:
67+
version_template: "{{ .Branch }}-{{ .ShortCommit }}-snapshot"
68+
69+
changelog:
70+
sort: asc
71+
use: github
72+
filters:
73+
exclude:
74+
- "^docs:"
75+
- "^test:"
76+
- "^chore:"
77+
- "Merge pull request"
78+
- "Merge remote-tracking branch"
79+
groups:
80+
- title: Features
81+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
82+
order: 0
83+
- title: "Bug Fixes"
84+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
85+
order: 1
86+
- title: Others
87+
order: 999
88+
89+
release:
90+
github:
91+
owner: TrogonStack
92+
name: protoc-gen
93+
draft: false
94+
prerelease: auto
95+
mode: append
96+
name_template: "{{.Tag}}"

.github/workflows/cd.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
name: cd
3+
4+
on:
5+
release:
6+
types: [published]
7+
workflow_dispatch:
8+
inputs:
9+
dry_run:
10+
description: 'Run in dry-run mode (snapshot, no publish)'
11+
required: false
12+
default: 'true'
13+
type: choice
14+
options:
15+
- 'true'
16+
- 'false'
17+
tag:
18+
description: 'Tag to use for version extraction (optional, e.g., protoc-gen-elixir-grpc@v0.2.0)'
19+
required: false
20+
type: string
21+
22+
permissions:
23+
contents: write
24+
packages: write
25+
id-token: write
26+
attestations: write
27+
28+
jobs:
29+
# Run tests only for manual workflow_dispatch triggers to catch issues during testing.
30+
# For actual releases, CI has already validated the code.
31+
# TODO: Consider removing workflow_dispatch entirely once the release process is stable.
32+
test:
33+
name: Run Tests
34+
if: github.event_name == 'workflow_dispatch'
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v5.0.0
39+
40+
- name: Set up Go
41+
uses: actions/setup-go@v6.0.0
42+
with:
43+
go-version: "1.24"
44+
45+
- name: Run Tests
46+
run: go test -race -v ./...
47+
48+
- name: Run Vet
49+
run: go vet ./...
50+
51+
goreleaser:
52+
name: Release with GoReleaser
53+
needs: test
54+
if: |
55+
always() &&
56+
(needs.test.result == 'success' || needs.test.result == 'skipped')
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v5.0.0
61+
with:
62+
fetch-depth: 0
63+
64+
- name: Set up Go
65+
uses: actions/setup-go@v6.0.0
66+
with:
67+
go-version: "1.24"
68+
69+
- name: Extract Version from Tag
70+
id: version
71+
run: |
72+
# Extract version from monorepo tags like protoc-gen-elixir-grpc@v0.1.0
73+
if [ "${{ github.event_name }}" = "release" ]; then
74+
TAG="${{ github.event.release.tag_name }}"
75+
elif [ -n "${{ github.event.inputs.tag }}" ]; then
76+
# Use tag from workflow_dispatch input if provided
77+
TAG="${{ github.event.inputs.tag }}"
78+
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
79+
# Use the ref if it's a tag
80+
TAG="${{ github.ref_name }}"
81+
else
82+
echo "ERROR: No tag provided. Please provide a tag via workflow_dispatch input."
83+
echo "Example: gh workflow run cd.yml -f dry_run=true -f tag=protoc-gen-elixir-grpc@v0.1.0"
84+
exit 1
85+
fi
86+
87+
# Validate tag format (must contain @ separator)
88+
if [[ ! "$TAG" =~ @ ]]; then
89+
echo "ERROR: Tag must follow pattern 'component@version', got: ${TAG}"
90+
echo "Examples: protoc-gen-elixir-grpc@v0.1.0, protoc-gen-connect-go-servicestruct@v0.2.0"
91+
exit 1
92+
fi
93+
94+
VERSION="${TAG##*@}"
95+
COMPONENT="${TAG%%@*}"
96+
97+
# Validate version is not empty
98+
if [ -z "$VERSION" ]; then
99+
echo "ERROR: Failed to extract version from tag: ${TAG}"
100+
exit 1
101+
fi
102+
103+
# Validate component is known
104+
case "$COMPONENT" in
105+
protoc-gen-elixir-grpc|protoc-gen-connect-go-servicestruct)
106+
echo "Valid component: ${COMPONENT}"
107+
;;
108+
*)
109+
echo "ERROR: Unknown component: ${COMPONENT}"
110+
echo "Valid components: protoc-gen-elixir-grpc, protoc-gen-connect-go-servicestruct"
111+
exit 1
112+
;;
113+
esac
114+
115+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
116+
echo "component=${COMPONENT}" >> $GITHUB_OUTPUT
117+
echo "Extracted component: ${COMPONENT}"
118+
echo "Extracted version: ${VERSION}"
119+
120+
- name: Run GoReleaser (Snapshot)
121+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true'
122+
uses: goreleaser/goreleaser-action@v6
123+
with:
124+
distribution: goreleaser
125+
version: "~> v2"
126+
args: release --snapshot --clean --skip=publish --config .github/goreleaser.yml
127+
env:
128+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.version }}
130+
BUILD_COMPONENT: ${{ steps.version.outputs.component }}
131+
132+
- name: Run GoReleaser (Release)
133+
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'false')
134+
uses: goreleaser/goreleaser-action@v6
135+
with:
136+
distribution: goreleaser
137+
version: "~> v2"
138+
args: release --clean --config .github/goreleaser.yml
139+
env:
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.version }}
142+
BUILD_COMPONENT: ${{ steps.version.outputs.component }}
143+
144+
- name: Attest Build Provenance
145+
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'false')
146+
uses: actions/attest-build-provenance@v2.0.0
147+
with:
148+
subject-path: "dist/**/*.tar.gz"
149+
150+
- name: Upload Snapshot Artifacts
151+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true'
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: snapshot-${{ steps.version.outputs.component }}-${{ steps.version.outputs.version }}
155+
path: dist/*
156+
retention-days: 7

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ go.work.sum
3434
# Generated protoc plugin binaries (root directory only)
3535
/protoc-gen-*
3636
/protoc-gen-*.wasm
37+
38+
# GoReleaser artifacts
39+
dist/

Taskfile.yml

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ tasks:
55
desc: Run fmt, vet, lint, and test
66
deps: [fmt, vet, lint, test]
77

8-
help:
9-
desc: Show available tasks
10-
cmds:
11-
- task --list
12-
138
test:
149
desc: Run all tests
1510
cmds:
@@ -28,16 +23,6 @@ tasks:
2823
- echo "Running tests with coverage..."
2924
- go test -cover ./...
3025

31-
test-coverage-html:
32-
desc: Run tests and generate HTML coverage report
33-
deps: [clean]
34-
cmds:
35-
- echo "Running tests and generating HTML coverage report..."
36-
- go test -coverprofile=coverage.out -covermode=count ./...
37-
- go tool cover -html=coverage.out -o coverage.html
38-
- echo "Coverage report generated at coverage.html"
39-
- echo "Open coverage.html in your browser to view the report"
40-
4126
fmt:
4227
desc: Format code with gofmt
4328
cmds:
@@ -50,17 +35,22 @@ tasks:
5035
- echo "Running go vet..."
5136
- go vet ./...
5237

38+
golangci-lint-check-installed:
39+
desc: Check if golangci-lint is installed
40+
internal: true
41+
preconditions:
42+
- sh: command -v golangci-lint
43+
msg: |
44+
golangci-lint not found. Install with:
45+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
46+
or visit https://golangci-lint.run/welcome/install/
47+
5348
lint:
54-
desc: Run golangci-lint (if available)
49+
desc: Run golangci-lint
50+
deps: [golangci-lint-check-installed]
5551
cmds:
5652
- echo "Running linter..."
57-
- |
58-
if command -v golangci-lint >/dev/null 2>&1; then
59-
golangci-lint run
60-
else
61-
echo "golangci-lint not found, skipping lint check"
62-
echo "Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"
63-
fi
53+
- golangci-lint run
6454

6555
build:
6656
desc: Build the package
@@ -87,14 +77,10 @@ tasks:
8777
- echo "Building Elixir gRPC protoc plugin binary..."
8878
- go build -o protoc-gen-elixir-grpc ./cmd/protoc-gen-elixir-grpc
8979

90-
dev-test:
91-
desc: Development workflow - fmt, vet, and generate coverage HTML
92-
deps: [fmt, vet, test-coverage-html]
93-
cmds:
94-
- echo "Development test complete - check coverage.html"
95-
96-
ci-test:
97-
desc: CI workflow - fmt, vet, and test with coverage
98-
deps: [fmt, vet, test-coverage]
80+
clean:
81+
desc: Clean build artifacts and coverage files
9982
cmds:
100-
- echo "CI test complete"
83+
- echo "Cleaning artifacts..."
84+
- rm -rf dist/
85+
- rm -f coverage.out coverage.html
86+
- rm -f protoc-gen-*

0 commit comments

Comments
 (0)