From 37d1c4e005fb83cf4c197403fa821c57b8ccd4ac Mon Sep 17 00:00:00 2001 From: Gouryella Date: Tue, 2 Dec 2025 16:55:30 +0800 Subject: [PATCH] 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. --- .github/workflows/release.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6aac003..61f8469 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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