From 7131a95a8b3d3c23222abef2a58f0805e02e5cad Mon Sep 17 00:00:00 2001 From: johlanse Date: Sun, 21 Aug 2022 16:29:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a12e974..0b3f73f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,11 +29,30 @@ jobs: goarch: arm fail-fast: true steps: - - uses: actions/checkout@v2 - - name: Setup Go environment - uses: actions/setup-go@v2.1.3 + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Fetch all tags + run: git fetch --force --tags + - name: Set up Go + uses: actions/setup-go@v3 with: go-version: 1.18 + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Check snapshot + if: "!startsWith(github.ref, 'refs/tags/')" + id: snapshot + run: echo '::set-output name=ARG::--snapshot' + - name: Build binary file env: GOOS: ${{ matrix.goos }} @@ -41,11 +60,11 @@ jobs: IS_PR: ${{ !!github.head_ref }} CGO_ENABLED: 0 run: | - echo $COMMIT_ID + echo ${steps.snapshot.outputs.ARG} if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi if $IS_PR ; then echo $PR_PROMPT; fi export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX" - export LD_FLAGS="-w -s -X main.VERSION=${COMMIT_ID::7}" + export LD_FLAGS="-w -s -X main.VERSION=${steps.snapshot.outputs.ARG}" go mod tidy go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" ./ - name: Upload artifact