diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c0558b4a..49cf9848 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -21,6 +21,8 @@ jobs: with: go-version: '>=1.24.0' cache: true + - name: "Set custom GORELEASER_CURRENT_TAG" + run: echo "GORELEASER_CURRENT_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV - uses: goreleaser/goreleaser-action@v3 with: distribution: goreleaser diff --git a/.goreleaser.yml b/.goreleaser.yml index 4f79944f..dfc4d3c6 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -9,6 +9,8 @@ builds: - arm64 main: ./cmd/server/ binary: cli-proxy-api + ldflags: + - -X 'main.Version={{.GORELEASER_CURRENT_TAG}}' archives: - id: "cli-proxy-api" format: tar.gz diff --git a/Dockerfile b/Dockerfile index 087ebfec..edd642d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,9 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o ./CLIProxyAPI ./cmd/server/ +ARG APP_VERSION="dev" + +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'main.Version=${APP_VERSION}'" -o ./CLIProxyAPI ./cmd/server/ FROM alpine:3.22.0 diff --git a/cmd/server/main.go b/cmd/server/main.go index 27dc88ea..fe106d06 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -17,6 +17,8 @@ import ( log "github.com/sirupsen/logrus" ) +var Version = "dev" + // LogFormatter defines a custom log format for logrus. // This formatter adds timestamp, log level, and source location information // to each log entry for better debugging and monitoring. @@ -58,6 +60,8 @@ func init() { // It parses command-line flags, loads configuration, and starts the appropriate // service based on the provided flags (login, codex-login, or server mode). func main() { + log.Infof("CLIProxyAPI Version: %v", Version) + // Command-line flags to control the application's behavior. var login bool var codexLogin bool