Skip to content

Commit

Permalink
Automatic releases that handle --version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jille committed Jan 23, 2023
1 parent fcbf3c6 commit d747988
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:

release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3

- run: mkdir _publish

- name: Build for linux/amd64
run: go build -v -ldflags "-X main.version=${{github.ref_name}}" -o _publish/pgperms-linux-amd64 ./cmd/pgperms/
env:
CGO_ENABLED: 0
GOARCH: amd64

- name: Build for linux/arm64
run: go build -v -ldflags "-X main.version=${{github.ref_name}}" -o _publish/pgperms-linux-arm64 ./cmd/pgperms/
env:
CGO_ENABLED: 0
GOARCH: arm64

- name: Release
uses: softprops/action-gh-release@v1
with:
files: _publish/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions cmd/pgperms/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@ import (

var (
dump = pflag.Bool("dump", false, "Whether to dump the current permissions")
showVersion = pflag.Bool("version", false, "Dump the version and exit")

// Injected by releaser
version string
)

func main() {
pflag.Parse()
if *showVersion {
if version != "" {
fmt.Fprintf(os.Stderr, "pgperms version %s\n", version)
} else {
fmt.Fprintf(os.Stderr, "pgperms built without versioning information\n")
}
return
}
ctx := context.Background()
conn, err := pgx.Connect(ctx, os.Getenv("DSN"))
if err != nil {
Expand Down

0 comments on commit d747988

Please sign in to comment.