diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index d07517c3..7fee2270 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -32,6 +32,10 @@ jobs: - name: Check out code uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Compile binaries - run: make + uses: goreleaser/goreleaser-action@v2 + with: + args: build -p 2 --snapshot --rm-dist diff --git a/.gitignore b/.gitignore index db93789c..1a2631f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /pint /.cover + +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..b224b3c9 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,34 @@ +builds: + - main: ./cmd/pint + flags: + - '-trimpath' + ldflags: + - '-s -X main.version={{.Version}} -X main.commit={{.Commit}}' + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + ignore: + - goos: windows + goarch: arm64 + no_unique_dist_dir: true + binary: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" +archives: + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/cmd/pint/main.go b/cmd/pint/main.go index 1c68484a..e4c437c6 100644 --- a/cmd/pint/main.go +++ b/cmd/pint/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" "time" @@ -16,6 +17,11 @@ const ( disabledFlag = "disabled" ) +var ( + version = "unknown" + commit = "unknown" +) + func newApp() *cli.App { return &cli.App{ Usage: "Prometheus rule linter", @@ -34,6 +40,11 @@ func newApp() *cli.App { }, }, Commands: []*cli.Command{ + { + Name: "version", + Usage: "Print version and exit", + Action: actionVersion, + }, { Name: "lint", Usage: "Lint specified files", @@ -80,3 +91,12 @@ func main() { os.Exit(1) } } + +func actionVersion(c *cli.Context) (err error) { + err = initLogger(c.String(logLevelFlag)) + if err != nil { + return fmt.Errorf("failed to set log level: %s", err) + } + fmt.Printf("%s (revision: %s)\n", version, commit) + return nil +}