Skip to content

Commit

Permalink
set version at build time (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
amalshaji authored Mar 2, 2025
1 parent 2128695 commit b1de0f9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ jobs:
linux/amd64
linux/arm64
file: ${{ matrix.dockerfile }}
build-args: |
VERSION=${{ github.ref_name }}
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ builds:
- amd64
- arm64
ldflags:
- -s -w -X main.build={{.Version}}
- -s -w -X main.version={{.Version}}

archives:
- format: zip
Expand Down
4 changes: 3 additions & 1 deletion tunnel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ RUN go mod download

COPY . /app/

RUN CGO_ENABLED=1 go build -ldflags="-s -w -linkmode external -extldflags \"-static\"" -o portrd ./cmd/portrd
ARG VERSION=dev

RUN CGO_ENABLED=1 go build -ldflags="-s -w -linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -o portrd ./cmd/portrd

FROM alpine:3.20 AS final

Expand Down
5 changes: 3 additions & 2 deletions tunnel/cmd/portr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
"github.com/urfave/cli/v2"
)

const VERSION = "0.0.29-beta"
// Set at build time
var version = "0.0.0"

func main() {
app := &cli.App{
Name: "portr",
Usage: "Expose local ports to the public internet",
Version: VERSION,
Version: version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Expand Down
5 changes: 3 additions & 2 deletions tunnel/cmd/portrd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import (
"github.com/urfave/cli/v2"
)

const VERSION = "0.0.29-beta"
// Set at build time
var version = "0.0.0"

func main() {
app := &cli.App{
Name: "portrd",
Usage: "portr server",
Version: VERSION,
Version: version,
Commands: []*cli.Command{
{
Name: "start",
Expand Down

0 comments on commit b1de0f9

Please sign in to comment.