ci(release): Optimizes the way Git commit information is retrieved in the build workflow.

The previous method of obtaining commit hashes via `git rev-parse` has been changed to directly using the `github.sha` variable provided by GitHub Actions,

and the first 10 characters are truncated as the short version commit hash.

Unnecessary `fetch-depth` configuration has also been removed.
This commit is contained in:
Gouryella
2025-12-02 16:55:30 +08:00
parent 8aee33a53a
commit 37d1c4e005

View File

@@ -16,8 +16,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
@@ -31,9 +29,10 @@ jobs:
- name: Build for all platforms
run: |
VERSION=${{ steps.version.outputs.VERSION }}
COMMIT=$(git rev-parse --short=10 HEAD)
COMMIT=${{ github.sha }}
COMMIT_SHORT=${COMMIT:0:10}
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS="-s -w -X main.Version=${VERSION} -X main.GitCommit=${COMMIT} -X main.BuildTime=${BUILD_TIME}"
LDFLAGS="-s -w -X main.Version=${VERSION} -X main.GitCommit=${COMMIT_SHORT} -X main.BuildTime=${BUILD_TIME}"
# Linux amd64
GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o drip-${VERSION}-linux-amd64 ./cmd/drip