mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Add versioning support to build artifacts and log outputs
- Introduced `Version` variable, set during build via `-ldflags`, to embed application version. - Updated Dockerfile to accept `APP_VERSION` argument for version injection during build. - Modified `.goreleaser.yml` to pass GitHub release tag as version via `ldflags`. - Added version logging in the application startup.
This commit is contained in:
2
.github/workflows/release.yaml
vendored
2
.github/workflows/release.yaml
vendored
@@ -21,6 +21,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
go-version: '>=1.24.0'
|
go-version: '>=1.24.0'
|
||||||
cache: true
|
cache: true
|
||||||
|
- name: "Set custom GORELEASER_CURRENT_TAG"
|
||||||
|
run: echo "GORELEASER_CURRENT_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
|
||||||
- uses: goreleaser/goreleaser-action@v3
|
- uses: goreleaser/goreleaser-action@v3
|
||||||
with:
|
with:
|
||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ builds:
|
|||||||
- arm64
|
- arm64
|
||||||
main: ./cmd/server/
|
main: ./cmd/server/
|
||||||
binary: cli-proxy-api
|
binary: cli-proxy-api
|
||||||
|
ldflags:
|
||||||
|
- -X 'main.Version={{.Env.GORELEASER_CURRENT_TAG}}'
|
||||||
archives:
|
archives:
|
||||||
- id: "cli-proxy-api"
|
- id: "cli-proxy-api"
|
||||||
format: tar.gz
|
format: tar.gz
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ RUN go mod download
|
|||||||
|
|
||||||
COPY . .
|
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
|
FROM alpine:3.22.0
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Version = "dev"
|
||||||
|
|
||||||
// LogFormatter defines a custom log format for logrus.
|
// LogFormatter defines a custom log format for logrus.
|
||||||
// This formatter adds timestamp, log level, and source location information
|
// This formatter adds timestamp, log level, and source location information
|
||||||
// to each log entry for better debugging and monitoring.
|
// 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
|
// It parses command-line flags, loads configuration, and starts the appropriate
|
||||||
// service based on the provided flags (login, codex-login, or server mode).
|
// service based on the provided flags (login, codex-login, or server mode).
|
||||||
func main() {
|
func main() {
|
||||||
|
log.Infof("CLIProxyAPI Version: %v", Version)
|
||||||
|
|
||||||
// Command-line flags to control the application's behavior.
|
// Command-line flags to control the application's behavior.
|
||||||
var login bool
|
var login bool
|
||||||
var codexLogin bool
|
var codexLogin bool
|
||||||
|
|||||||
Reference in New Issue
Block a user