🐛 QQ group rule #113
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Nightly | |
on: [push, pull_request] | |
env: | |
BINARY_PREFIX: "nbp_" | |
BINARY_SUFFIX: "" | |
PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request." | |
LD_FLAGS: "-w -s" | |
jobs: | |
build: | |
name: Build binary CI | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 | |
goos: [linux, windows] | |
goarch: ["386", amd64, arm, arm64] | |
exclude: | |
- goos: windows | |
goarch: arm | |
- goos: windows | |
goarch: arm64 | |
fail-fast: true | |
steps: | |
- uses: actions/checkout@master | |
- name: Setup Go environment | |
uses: actions/setup-go@master | |
with: | |
go-version: '1.20' | |
- name: Cache downloaded module | |
uses: actions/cache@master | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }} | |
- name: Build binary file | |
env: | |
GOOS: ${{ matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
IS_PR: ${{ !!github.head_ref }} | |
run: | | |
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 CGO_ENABLED=0 | |
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" . | |
- name: Upload artifact | |
uses: actions/upload-artifact@master | |
if: ${{ !github.head_ref }} | |
with: | |
name: ${{ matrix.goos }}_${{ matrix.goarch }} | |
path: output/ |