Skip to content

CI

CI #9

Workflow file for this run

name: CI
on: [push, pull_request, workflow_dispatch]
env:
BINARY_PREFIX: "perpetua_"
BINARY_SUFFIX: ""
COMMIT_ID: "${{ github.sha }}"
PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
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, darwin]
goarch: ["386", amd64, arm, arm64]
exclude:
- goos: darwin
goarch: arm
- goos: darwin
goarch: "386"
fail-fast: true
steps:
- uses: actions/checkout@v3
- name: Setup Go environment
uses: actions/setup-go@v3
with:
cache: true
go-version: '1.21.4'
- name: Build binary file
env:
GOOS: ${{ matrix.goos }}
IS_PR: ${{ !!github.head_ref }}
BINARY_NAME: ${{ env.BINARY_PREFIX }}${{ matrix.goos }}_${{ matrix.goarch }}${{ env.BINARY_SUFFIX }}
LD_FLAGS: "-w -s -X github.com/IUnlimit/perpetua/internal/conf.Version=${{ env.COMMIT_ID }}"
run: |
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
if $IS_PR ; then echo $PR_PROMPT; fi
export CGO_ENABLED=0
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
- name: Upload artifact
uses: actions/upload-artifact@v3
if: ${{ !github.head_ref }}
with:
name: ${{ matrix.goos }}_${{ matrix.goarch }}
path: output/