1- name : 最新版
1+ name : Build Library
22
33on :
4- workflow_run :
5- workflows : [PushLint, PullLint]
6- types :
7- - completed
4+ workflow_call :
5+ inputs :
6+ prefix :
7+ type : string
8+ required : true
9+ upload_artifact :
10+ type : boolean
11+ required : true
812
913env :
10- BINARY_PREFIX : " zbp_"
11- BINARY_SUFFIX : " "
14+ BINARY_SUFFIX : " ${{ inputs.prefix }}"
1215 PR_PROMPT : " ::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
1316 LD_FLAGS : " -w -s"
1417
1518jobs :
1619 build :
1720 name : Build binary CI
1821 runs-on : ubuntu-latest
19- if : ${{ github.event.workflow_run.conclusion == 'success' }}
2022 strategy :
2123 matrix :
2224 # build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
@@ -34,10 +36,12 @@ jobs:
3436 - uses : actions/checkout@master
3537 with :
3638 fetch-depth : 0
39+
3740 - name : Setup Go environment
3841 uses : actions/setup-go@master
3942 with :
4043 go-version : ' ^1.25'
44+
4145 - name : Cache downloaded module
4246 uses : actions/cache@master
4347 continue-on-error : true
@@ -46,21 +50,24 @@ jobs:
4650 ~/.cache/go-build
4751 ~/go/pkg/mod
4852 key : ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }}
53+
4954 - name : Build binary file
5055 env :
5156 GOOS : ${{ matrix.goos }}
5257 GOARCH : ${{ matrix.goarch }}
53- IS_PR : ${{ !!github.head_ref }}
58+ IS_PR : ${{ !inputs.upload_artifact }}
59+ BINARY_PREFIX : ${{ inputs.BINARY_PREFIX }}
5460 run : |
5561 GOOS= GOARCH= go generate ./...
5662 if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
5763 if $IS_PR ; then echo $PR_PROMPT; fi
5864 export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
5965 export CGO_ENABLED=0
6066 go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
67+
6168 - name : Upload artifact
6269 uses : actions/upload-artifact@master
63- if : ${{ !github.head_ref }}
70+ if : ${{ inputs.upload_artifact }}
6471 with :
6572 name : ${{ matrix.goos }}_${{ matrix.goarch }}
6673 path : output/
0 commit comments