From 864b91fad1b6bb1e8b14e0125c51b151f1a67e63 Mon Sep 17 00:00:00 2001 From: Akizon77 Date: Tue, 3 Jun 2025 23:21:57 +0800 Subject: [PATCH] =?UTF-8?q?ci/cd:=20=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/development.yml | 7 ++++--- .github/workflows/docker-publish.yml | 3 +++ .github/workflows/release.yml | 9 +++++++-- Dockerfile | 4 +++- utils/version.go | 6 ++++++ 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 utils/version.go diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index a59c43a..1713215 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -12,8 +12,8 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 - + uses: actions/checkout@v4 + #- name: Create dummy index.html # run: | # mkdir -p public/dist @@ -39,7 +39,8 @@ jobs: GOOS: linux GOARCH: amd64 run: | - go build -o komari . + VERSION_SHA="${{ github.sha }}" + go build -ldflags "-X github.com/komari-monitor/komari/utils.CurrentVersion=dev -X github.com/komari-monitor/komari/utils.VersionHash=${VERSION_SHA}" -o komari . - name: Upload binary as artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 717197d..6ec3190 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -44,3 +44,6 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ github.ref_name }} + VERSION_HASH=${{ github.sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 93245c1..246cc5e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,7 +55,9 @@ jobs: if [ "${{ matrix.goos }}" = "windows" ]; then BINARY_NAME=${BINARY_NAME}.exe fi - go build -trimpath -ldflags="-s -w" -o $BINARY_NAME + VERSION="${{ github.event.release.tag_name }}" + VERSION_HASH="${{ github.sha }}" + go build -trimpath -ldflags="-s -w -X github.com/komari-monitor/komari/utils.CurrentVersion=${VERSION} -X github.com/komari-monitor/komari/utils.VersionHash=${VERSION_HASH}" -o $BINARY_NAME - name: Upload binary to release env: @@ -97,4 +99,7 @@ jobs: context: . push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ github.event.release.tag_name }} + VERSION_HASH=${{ github.sha }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 18fc2c7..11739d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,10 @@ COPY . . COPY --from=frontend /web/dist ./public/dist ENV CGO_ENABLED=1 +ARG VERSION=unknown +ARG VERSION_HASH=unknown # RUN CC=musl-gcc go build -trimpath -ldflags="-s -w -linkmode external -extldflags -static" -o komari . -RUN go build -trimpath -ldflags="-s -w -linkmode external -extldflags -static" -o komari . +RUN go build -trimpath -ldflags="-s -w -linkmode external -extldflags -static -X github.com/komari-monitor/komari/utils.CurrentVersion=${VERSION} -X github.com/komari-monitor/komari/utils.VersionHash=${VERSION_HASH}" -o komari . # FROM scratch FROM alpine:3.21 diff --git a/utils/version.go b/utils/version.go new file mode 100644 index 0000000..85cf221 --- /dev/null +++ b/utils/version.go @@ -0,0 +1,6 @@ +package utils + +var ( + CurrentVersion = "0.0.1" + VersionHash = "unknown" +)