ci/cd: 版本信息构建

This commit is contained in:
Akizon77
2025-06-03 23:21:57 +08:00
parent 8ed2e5a774
commit 864b91fad1
5 changed files with 23 additions and 6 deletions

View File

@@ -12,8 +12,8 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
#- name: Create dummy index.html #- name: Create dummy index.html
# run: | # run: |
# mkdir -p public/dist # mkdir -p public/dist
@@ -39,7 +39,8 @@ jobs:
GOOS: linux GOOS: linux
GOARCH: amd64 GOARCH: amd64
run: | 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 - name: Upload binary as artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

View File

@@ -44,3 +44,6 @@ jobs:
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.ref_name }}
VERSION_HASH=${{ github.sha }}

View File

@@ -55,7 +55,9 @@ jobs:
if [ "${{ matrix.goos }}" = "windows" ]; then if [ "${{ matrix.goos }}" = "windows" ]; then
BINARY_NAME=${BINARY_NAME}.exe BINARY_NAME=${BINARY_NAME}.exe
fi 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 - name: Upload binary to release
env: env:
@@ -97,4 +99,7 @@ jobs:
context: . context: .
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.event.release.tag_name }}
VERSION_HASH=${{ github.sha }}

View File

@@ -16,8 +16,10 @@ COPY . .
COPY --from=frontend /web/dist ./public/dist COPY --from=frontend /web/dist ./public/dist
ENV CGO_ENABLED=1 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 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 scratch
FROM alpine:3.21 FROM alpine:3.21

6
utils/version.go Normal file
View File

@@ -0,0 +1,6 @@
package utils
var (
CurrentVersion = "0.0.1"
VersionHash = "unknown"
)