From de0b53a75e7cad70879406ab36700a39bb75fcdf Mon Sep 17 00:00:00 2001 From: Aavash Shrestha Date: Wed, 19 Nov 2025 01:04:05 +0100 Subject: [PATCH] chore: add go releaser config and workflow --- .github/workflows/release.yml | 60 +++++++++++++++++++++++++++ .gitignore | 1 + .goreleaser-darwin.yaml | 76 +++++++++++++++++++++++++++++++++++ .goreleaser-linux.yaml | 61 ++++++++++++++++++++++++++++ main.go | 13 ++++++ 5 files changed, 211 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser-darwin.yaml create mode 100644 .goreleaser-linux.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c29dc83 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + release-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Install cross-compilation dependencies + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu + + - name: Run GoReleaser for Linux + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: release --clean --config .goreleaser-linux.yaml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + release-darwin: + runs-on: macos-latest + needs: release-linux + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Run GoReleaser for macOS + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: release --clean --config .goreleaser-darwin.yaml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 3b859a5..ce7eb2e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ panda !.gitignore !.github +!.goreleaser* diff --git a/.goreleaser-darwin.yaml b/.goreleaser-darwin.yaml new file mode 100644 index 0000000..c55c2be --- /dev/null +++ b/.goreleaser-darwin.yaml @@ -0,0 +1,76 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +version: 2 + +before: + hooks: + - go mod tidy + - go mod verify + +builds: + - id: panda-darwin + main: ./main.go + binary: panda + env: + - CGO_ENABLED=1 + goos: + - darwin + goarch: + - amd64 + - arm64 + flags: + - -tags=fts5 + ldflags: + - -s -w + - -X main.version={{.Version}} + - -X main.commit={{.Commit}} + - -X main.date={{.Date}} + +archives: + - id: panda-archive + format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + files: + - README.md + - LICENSE* + +checksum: + name_template: 'checksums.txt' + +snapshot: + version_template: "{{ incpatch .Version }}-next" + +changelog: + sort: asc + use: github + filters: + exclude: + - '^docs:' + - '^test:' + - '^ci:' + - '^chore:' + - Merge pull request + - Merge branch + groups: + - title: 'New Features' + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: 'Bug Fixes' + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: 'Other Changes' + order: 999 + +release: + github: + owner: aavshr + name: panda + draft: false + prerelease: auto + mode: append + name_template: "{{.ProjectName}} v{{.Version}}" diff --git a/.goreleaser-linux.yaml b/.goreleaser-linux.yaml new file mode 100644 index 0000000..7ba093d --- /dev/null +++ b/.goreleaser-linux.yaml @@ -0,0 +1,61 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +version: 2 + +before: + hooks: + - go mod tidy + - go mod verify + +builds: + - id: panda-linux + main: ./main.go + binary: panda + env: + - CGO_ENABLED=1 + goos: + - linux + goarch: + - amd64 + - arm64 + flags: + - -tags=fts5 + ldflags: + - -s -w + - -X main.version={{.Version}} + - -X main.commit={{.Commit}} + - -X main.date={{.Date}} + overrides: + - goos: linux + goarch: arm64 + env: + - CC=aarch64-linux-gnu-gcc + +archives: + - id: panda-archive + format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + files: + - README.md + - LICENSE* + +checksum: + name_template: 'checksums.txt' + disable: true + +changelog: + disable: true + +release: + github: + owner: aavshr + name: panda + draft: true + prerelease: auto + mode: append + name_template: "{{.ProjectName}} v{{.Version}}" diff --git a/main.go b/main.go index 2245f2d..cc3de8b 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( _ "embed" + "fmt" "log" "os" @@ -16,6 +17,13 @@ import ( "golang.org/x/term" ) +// build information injected by goreleaser +var ( + version = "dev" + commit = "none" + date = "unknown" +) + //go:embed internal/db/schema/init.sql var dbSchemaInit string @@ -76,6 +84,11 @@ func initMockStore() *store.Mock { } func main() { + if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "-v") { + fmt.Printf("panda %s\ncommit: %s\nbuilt at: %s\n", version, commit, date) + os.Exit(0) + } + isDev := strings.ToLower(os.Getenv("PANDA_ENV")) == "dev" dataDirPath := config.GetDataDir() databaseName := DefaultDatabaseName