diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d14147b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: Release + +on: + release: + types: [created] + +permissions: + contents: write + +jobs: + goreleaser: + name: GoReleaser + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Install Go + uses: actions/setup-go@v6 + with: + go-version: 1.25.x + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..48f4e90 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,39 @@ +version: 2 + +builds: + - id: saferwall-cli + binary: saferwall-cli + main: ./cli.go + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} + +archives: + - id: saferwall-cli + formats: + - tar.gz + format_overrides: + - goos: windows + formats: + - zip + name_template: >- + {{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }} + +checksum: + name_template: "checksums.txt" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + - "^ci:" diff --git a/cli.go b/cli.go index 91a2327..7d1e483 100755 --- a/cli.go +++ b/cli.go @@ -8,6 +8,13 @@ import ( "github.com/saferwall/cli/cmd" ) +var ( + version = "dev" + commit = "none" + date = "unknown" +) + func main() { + cmd.SetVersionInfo(version, commit, date) cmd.Execute() } diff --git a/cmd/version.go b/cmd/version.go index 09e9dba..78cfba6 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,15 +10,30 @@ import ( "github.com/spf13/cobra" ) -const ( - version = "0.5.0" +var ( + version = "dev" + commit = "none" + date = "unknown" ) +// SetVersionInfo sets the build-time version information. +func SetVersionInfo(v, c, d string) { + if v != "" { + version = v + } + if c != "" { + commit = c + } + if d != "" { + date = d + } +} + var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number", Long: "Print the version number", Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("You are using version %s\n", version) + fmt.Printf("You are using version %s (commit: %s, built: %s)\n", version, commit, date) }, }