build: Consolidate build-darwin job into just "build"

We can use an extra matrix dimension to select which execution environment
we'll use for each GOOS/GOARCH pair, and thus avoid duplicating the
job definition for darwin just to set runs-on: macos-latest for it.

This is not really an intended use of a matrix dimension because it's
directly related to the existing "goos" one, rather than being an
independent third dimension, but it doesn't matter in practice because
we're using the "include" option to specify exact combinations, and thus
we're not relying on the built-in functionality to generate all possible
matrix combinations.
This commit is contained in:
Martin Atkins 2022-01-03 10:27:42 -08:00
parent 218e55b23c
commit 3bf758eaf5
1 changed files with 35 additions and 54 deletions

View File

@ -62,10 +62,11 @@ jobs:
generate-metadata-file: generate-metadata-file:
name: "Generate release metadata" name: "Generate release metadata"
needs: get-product-version
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: get-product-version
outputs: outputs:
filepath: ${{ steps.generate-metadata-file.outputs.filepath }} filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Generate package metadata - name: Generate package metadata
@ -81,27 +82,31 @@ jobs:
path: ${{ steps.generate-metadata-file.outputs.filepath }} path: ${{ steps.generate-metadata-file.outputs.filepath }}
build: build:
needs: ["get-product-version", "get-go-version"] name: Build for ${{ matrix.goos }}_${{ matrix.goarch }}
runs-on: ubuntu-latest runs-on: ${{ matrix.runson }}
needs:
- get-product-version
- get-go-version
strategy: strategy:
matrix: matrix:
include: include:
- {goos: "freebsd", goarch: "386"} - {goos: "freebsd", goarch: "386", runson: "ubuntu-latest"}
- {goos: "freebsd", goarch: "amd64"} - {goos: "freebsd", goarch: "amd64", runson: "ubuntu-latest"}
- {goos: "freebsd", goarch: "arm"} - {goos: "freebsd", goarch: "arm", runson: "ubuntu-latest"}
- {goos: "linux", goarch: "386"} - {goos: "linux", goarch: "386", runson: "ubuntu-latest"}
- {goos: "linux", goarch: "amd64"} - {goos: "linux", goarch: "amd64", runson: "ubuntu-latest"}
- {goos: "linux", goarch: "arm"} - {goos: "linux", goarch: "arm", runson: "ubuntu-latest"}
- {goos: "linux", goarch: "arm64"} - {goos: "linux", goarch: "arm64", runson: "ubuntu-latest"}
- {goos: "openbsd", goarch: "386"} - {goos: "openbsd", goarch: "386", runson: "ubuntu-latest"}
- {goos: "openbsd", goarch: "amd64"} - {goos: "openbsd", goarch: "amd64", runson: "ubuntu-latest"}
- {goos: "solaris", goarch: "amd64"} - {goos: "solaris", goarch: "amd64", runson: "ubuntu-latest"}
- {goos: "windows", goarch: "386"} - {goos: "windows", goarch: "386", runson: "ubuntu-latest"}
- {goos: "windows", goarch: "amd64"} - {goos: "windows", goarch: "amd64", runson: "ubuntu-latest"}
- {goos: "darwin", goarch: "amd64", runson: "macos-latest"}
- {goos: "darwin", goarch: "arm64", runson: "macos-latest"}
fail-fast: false fail-fast: false
name: Build for ${{ matrix.goos }}_${{ matrix.goarch }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -110,13 +115,22 @@ jobs:
with: with:
go-version: ${{ needs.get-go-version.outputs.go-version }} go-version: ${{ needs.get-go-version.outputs.go-version }}
# FIXME: We're not currently setting the hard-coded version string in
# version/version.go at any point here, which means that the packages
# this process builds are not suitable for release. Once we're using
# Go 1.18 we may begin using the version information automatically
# embedded by the Go toolchain, at which point we won't need any
# special steps during build, but failing that we'll need to rework
# the version/version.go package so we can more readily update it
# using linker flags rather than direct code modification.
- name: Build - name: Build
env: env:
GOOS: ${{ matrix.goos }} GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }} GOARCH: ${{ matrix.goarch }}
run: | run: |
mkdir dist out mkdir dist out
go build -o dist/ . go build -ldflags "-w -s" -o dist/ .
zip -r -j out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/ zip -r -j out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v2
@ -145,6 +159,8 @@ jobs:
echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV
echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV
# FIXME: Generate homebrew packages when targeting macOS.
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v2
if: ${{ matrix.goos == 'linux' }} if: ${{ matrix.goos == 'linux' }}
with: with:
@ -157,41 +173,6 @@ jobs:
name: ${{ env.DEB_PACKAGE }} name: ${{ env.DEB_PACKAGE }}
path: out/${{ env.DEB_PACKAGE }} path: out/${{ env.DEB_PACKAGE }}
build-darwin:
needs: ["get-product-version", "get-go-version"]
runs-on: macos-latest
strategy:
matrix:
include:
- {goos: "darwin", goarch: "amd64"}
- {goos: "darwin", goarch: "arm64"}
fail-fast: false
name: Build for ${{ matrix.goos }}_${{ matrix.goarch }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
steps:
- uses: actions/checkout@v2
- name: Install Go toolchain
uses: actions/setup-go@v2
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: Build
run: |
mkdir dist out
go build -o dist/
zip -r -j out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/
- uses: actions/upload-artifact@v2
with:
name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip
path: out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip
build-docker: build-docker:
name: Build Docker image for linux_${{ matrix.arch }} name: Build Docker image for linux_${{ matrix.arch }}
needs: needs:
@ -319,7 +300,7 @@ jobs:
runs-on: macos-latest runs-on: macos-latest
needs: needs:
- get-product-version - get-product-version
- build-darwin - build
- e2etest-build - e2etest-build
strategy: strategy: