Skip to content

Commit 87f3719

Browse files
committed
feat: add automated releases with GoReleaser
1 parent 0b39ef3 commit 87f3719

File tree

6 files changed

+150
-1
lines changed

6 files changed

+150
-1
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: '1.24'
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v6
27+
with:
28+
distribution: goreleaser
29+
version: latest
30+
args: release --clean
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build artifacts
22
bin/
3+
dist/
34

45
# Batch processing results
56
batch_results/

.goreleaser.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
version: 2
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
7+
builds:
8+
- id: go-promptguard
9+
main: ./cmd/go-promptguard
10+
binary: go-promptguard
11+
env:
12+
- CGO_ENABLED=0
13+
goos:
14+
- linux
15+
- darwin
16+
- windows
17+
goarch:
18+
- amd64
19+
- arm64
20+
ldflags:
21+
- -s -w
22+
- -X main.version={{.Version}}
23+
- -X main.commit={{.Commit}}
24+
- -X main.date={{.Date}}
25+
26+
archives:
27+
- id: go-promptguard
28+
format: tar.gz
29+
name_template: >-
30+
{{ .ProjectName }}_
31+
{{- .Version }}_
32+
{{- .Os }}_
33+
{{- .Arch }}
34+
format_overrides:
35+
- goos: windows
36+
format: zip
37+
files:
38+
- README.md
39+
- LICENSE
40+
41+
checksum:
42+
name_template: 'checksums.txt'
43+
44+
snapshot:
45+
version_template: "{{ incpatch .Version }}-next"
46+
47+
changelog:
48+
sort: asc
49+
filters:
50+
exclude:
51+
- '^docs:'
52+
- '^test:'
53+
- '^chore:'
54+
- Merge pull request
55+
- Merge branch
56+
57+
release:
58+
github:
59+
owner: mdombrov-33
60+
name: go-promptguard
61+
name_template: "v{{.Version}}"

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: build clean install test release-snapshot help
2+
3+
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
4+
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
5+
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
6+
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
7+
8+
help:
9+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
10+
11+
build:
12+
@echo "Building go-promptguard $(VERSION)..."
13+
@go build -ldflags "$(LDFLAGS)" -o bin/go-promptguard ./cmd/go-promptguard
14+
@echo "✓ Built to bin/go-promptguard"
15+
16+
install:
17+
@echo "Installing go-promptguard $(VERSION)..."
18+
@go install -ldflags "$(LDFLAGS)" ./cmd/go-promptguard
19+
@echo "✓ Installed to $(shell go env GOPATH)/bin/go-promptguard"
20+
21+
clean:
22+
@rm -rf bin/ dist/
23+
@go clean
24+
@echo "✓ Cleaned"
25+
26+
test:
27+
@go test -v ./...
28+
29+
release-snapshot:
30+
@goreleaser release --snapshot --clean
31+
@echo "✓ Snapshot built to dist/"
32+
33+
release-test:
34+
@goreleaser release --skip=publish --clean
35+
@echo "✓ Release tested"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ go get github.com/mdombrov-33/go-promptguard
3232

3333
**CLI (standalone tool):**
3434

35-
If you have Go 1.21+:
35+
If you have Go 1.24+:
3636
```bash
3737
go install github.com/mdombrov-33/go-promptguard/cmd/go-promptguard@latest
3838
```

cmd/go-promptguard/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import (
88
"github.com/spf13/cobra"
99
)
1010

11+
var (
12+
version = "dev"
13+
commit = "none"
14+
date = "unknown"
15+
)
16+
1117
var rootCmd = &cobra.Command{
1218
Use: "go-promptguard",
1319
Short: "Prompt injection detection for LLM applications",
@@ -28,6 +34,20 @@ Run 'go-promptguard [command] --help' for more information.`,
2834
},
2935
}
3036

37+
var versionCmd = &cobra.Command{
38+
Use: "version",
39+
Short: "Print version information",
40+
Run: func(cmd *cobra.Command, args []string) {
41+
fmt.Printf("go-promptguard %s\n", version)
42+
fmt.Printf("commit: %s\n", commit)
43+
fmt.Printf("built: %s\n", date)
44+
},
45+
}
46+
47+
func init() {
48+
rootCmd.AddCommand(versionCmd)
49+
}
50+
3151
func main() {
3252
godotenv.Load()
3353

0 commit comments

Comments
 (0)