summaryrefslogtreecommitdiff
path: root/.github/workflows/cross-build.yml
blob: 277f22ca5a755798b0e6075c436ed33fc983a127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Cross-Build

on:
  push:
    branches:
      - master
      - 2.*
  pull_request:
    branches:
      - master
      - 2.*

jobs:
  cross-build-test:
    strategy:
      fail-fast: false
      matrix:
        goos: ['android', 'linux', 'solaris', 'illumos', 'dragonfly', 'freebsd', 'openbsd', 'plan9', 'windows', 'darwin', 'netbsd']
        go: [ '1.16', '1.17' ]
    runs-on: ubuntu-latest
    continue-on-error: true
    steps:
      - name: Install Go
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go }}

      - name: Print Go version and environment
        id: vars
        run: |
          printf "Using go at: $(which go)\n"
          printf "Go version: $(go version)\n"
          printf "\n\nGo environment:\n\n"
          go env
          printf "\n\nSystem environment:\n\n"
          env
          echo "::set-output name=go_cache::$(go env GOCACHE)"

      - name: Cache the build cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.vars.outputs.go_cache }}
          key: cross-build-go${{ matrix.go }}-${{ matrix.goos }}-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            cross-build-go${{ matrix.go }}-${{ matrix.goos }}

      - name: Checkout code into the Go module directory
        uses: actions/checkout@v2

      - name: Run Build
        env:
          CGO_ENABLED: 0
          GOOS: ${{ matrix.goos }}
        shell: bash
        continue-on-error: true
        working-directory: ./cmd/caddy
        run: |
          GOOS=$GOOS go build -trimpath -o caddy-"$GOOS"-amd64 2> /dev/null
          if [ $? -ne 0 ]; then
            echo "::warning ::$GOOS Build Failed"
            exit 0
          fi