diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..37cde42 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/cmd/pgperms/cli.go b/cmd/pgperms/cli.go index 1a4055f..86570b1 100644 --- a/cmd/pgperms/cli.go +++ b/cmd/pgperms/cli.go @@ -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 {