Skip to content

Commit

Permalink
Compile on GitHub using goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Oct 10, 2021
1 parent 9c57054 commit 7ceaca6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/pint
/.cover

dist/
34 changes: 34 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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:'
20 changes: 20 additions & 0 deletions cmd/pint/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"
"time"

Expand All @@ -16,6 +17,11 @@ const (
disabledFlag = "disabled"
)

var (
version = "unknown"
commit = "unknown"
)

func newApp() *cli.App {
return &cli.App{
Usage: "Prometheus rule linter",
Expand All @@ -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",
Expand Down Expand Up @@ -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
}

0 comments on commit 7ceaca6

Please sign in to comment.