github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/.github/workflows/main.yml (about)

     1  name: CI
     2  
     3  on: [push, pull_request]
     4  
     5  env:
     6    BINARY_PREFIX: "baidupcs-go_"
     7    BINARY_SUFFIX: ""
     8    PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
     9    LD_FLAGS: "-w -s"
    10  
    11  jobs:
    12    build:
    13      name: Build binary CI
    14      runs-on: ubuntu-latest
    15      strategy:
    16        matrix:
    17          # build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
    18          goos: [linux, windows, darwin]
    19          goarch: ["386", amd64, arm, arm64]
    20          exclude:
    21            - goos: darwin
    22              goarch: arm
    23            - goos: darwin
    24              goarch: "386"
    25            - goos: windows
    26              goarch: arm64
    27        fail-fast: true
    28      steps:
    29        - uses: actions/checkout@v2
    30        - name: Setup Go environment
    31          uses: actions/setup-go@v2.1.3
    32          with:
    33            go-version: 1.17
    34        - name: Cache downloaded module
    35          uses: actions/cache@v2
    36          with:
    37            path: |
    38              ~/.cache/go-build
    39              ~/go/pkg/mod
    40            key: ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }}
    41        - name: Build binary file
    42          env:
    43            GOOS: ${{ matrix.goos }}
    44            GOARCH: ${{ matrix.goarch }}
    45            IS_PR: ${{ !!github.head_ref }}
    46          run: |
    47            if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
    48            if $IS_PR ; then echo $PR_PROMPT; fi
    49            export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
    50            export CGO_ENABLED=0
    51            go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
    52        - name: Upload artifact
    53          uses: actions/upload-artifact@v2
    54          if: ${{ !github.head_ref }}
    55          with:
    56            name: ${{ matrix.goos }}_${{ matrix.goarch }}
    57            path: output/