Skip to content

Commit

Permalink
ci: Set Go version consistently via .go-version
Browse files Browse the repository at this point in the history
Ensure Go version is determined consistently for CI and Docker builds
rather than spread across several different files.

The intent is to eventually replace this with use of the `toolchain`
directive in Go 1.21.
  • Loading branch information
zalimeni committed Jan 3, 2024
1 parent 55d7e95 commit ea888cd
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 83 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ jobs:
name: Setup outputs
run: ./.github/scripts/get_runner_classes.sh

get-go-version:
uses: ./.github/workflows/reusable-get-go-version.yml

dev-build-push:
needs: setup
needs:
- setup
- get-go-version
runs-on: ${{ fromJSON(needs.setup.outputs.compute-large) }}
permissions:
id-token: write # NOTE: this permission is explicitly required for Vault auth.
Expand Down Expand Up @@ -65,7 +70,7 @@ jobs:

- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
go-version: ${{ needs.get-go-version.outputs.go-version }}

- run: go env

Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/build-distros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,25 @@ jobs:
name: Setup outputs
run: ./.github/scripts/get_runner_classes.sh

get-go-version:
uses: ./.github/workflows/reusable-get-go-version.yml

check-go-mod:
needs:
- setup
- get-go-version
uses: ./.github/workflows/reusable-check-go-mod.yml
with:
runs-on: ${{ needs.setup.outputs.compute-medium }}
repository-name: ${{ github.repository }}
go-version: ${{ needs.get-go-version.outputs.go-version }}
secrets:
elevated-github-token: ${{ secrets.ELEVATED_GITHUB_TOKEN }}

build-386:
needs:
- setup
- get-go-version
- check-go-mod
env:
XC_OS: "freebsd linux windows"
Expand All @@ -63,7 +69,7 @@ jobs:

- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: Build
run: |
for os in $XC_OS; do
Expand All @@ -73,6 +79,7 @@ jobs:
build-amd64:
needs:
- setup
- get-go-version
- check-go-mod
env:
XC_OS: "darwin freebsd linux solaris windows"
Expand All @@ -87,7 +94,7 @@ jobs:

- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: Build
run: |
for os in $XC_OS; do
Expand All @@ -97,6 +104,7 @@ jobs:
build-arm:
needs:
- setup
- get-go-version
- check-go-mod
runs-on: ${{ fromJSON(needs.setup.outputs.compute-xl) }}
env:
Expand All @@ -113,7 +121,7 @@ jobs:

- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
go-version: ${{ needs.get-go-version.outputs.go-version }}
- run: |
sudo apt-get update --allow-releaseinfo-change-suite --allow-releaseinfo-change-version && sudo apt-get install -y gcc-arm-linux-gnueabi gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
Expand All @@ -126,6 +134,7 @@ jobs:
if: ${{ endsWith(github.repository, '-enterprise') }}
needs:
- setup
- get-go-version
- check-go-mod
runs-on: ${{ fromJSON(needs.setup.outputs.compute-xl) }}
steps:
Expand All @@ -137,7 +146,7 @@ jobs:

- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: Build
run: GOOS=linux GOARCH=s390x CGO_ENABLED=0 go build -tags "${{ env.GOTAGS }}"

Expand Down
58 changes: 28 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ env:
GOPRIVATE: github.com/hashicorp # Required for enterprise deps

jobs:
get-go-version:
uses: ./.github/workflows/reusable-get-go-version.yml

set-product-version:
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -81,32 +84,25 @@ jobs:
path: ${{ steps.generate-metadata-file.outputs.filepath }}

build:
needs: set-product-version
needs:
- set-product-version
- get-go-version
runs-on: ubuntu-latest
strategy:
matrix:
include:
- {go: "1.20.12",
goos: "linux", goarch: "386"}
- {go: "1.20.12",
goos: "linux", goarch: "amd64"}
- {go: "1.20.12",
goos: "linux", goarch: "arm"}
- {go: "1.20.12",
goos: "linux", goarch: "arm64"}
- {go: "1.20.12",
goos: "freebsd", goarch: "386"}
- {go: "1.20.12",
goos: "freebsd", goarch: "amd64"}
- {go: "1.20.12",
goos: "windows", goarch: "386"}
- {go: "1.20.12",
goos: "windows", goarch: "amd64"}
- {go: "1.20.12",
goos: "solaris", goarch: "amd64"}
- {goos: "linux", goarch: "386"}
- {goos: "linux", goarch: "amd64"}
- {goos: "linux", goarch: "arm"}
- {goos: "linux", goarch: "arm64"}
- {goos: "freebsd", goarch: "386"}
- {goos: "freebsd", goarch: "amd64"}
- {goos: "windows", goarch: "386"}
- {goos: "windows", goarch: "amd64"}
- {goos: "solaris", goarch: "amd64"}
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

Expand Down Expand Up @@ -140,7 +136,7 @@ jobs:
with:
product_name: ${{ env.PKG_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
go_version: ${{ matrix.go }}
go_version: ${{ needs.get-go-version.outputs.go-version }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: report
Expand Down Expand Up @@ -186,17 +182,18 @@ jobs:
path: out/${{ env.DEB_PACKAGE }}

build-s390x:
needs: set-product-version
needs:
- set-product-version
- get-go-version
if: ${{ endsWith(github.repository, '-enterprise') }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
- {go: "1.20.12",
goos: "linux", goarch: "s390x"}
- {goos: "linux", goarch: "s390x"}
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

Expand Down Expand Up @@ -230,24 +227,25 @@ jobs:
with:
product_name: ${{ env.PKG_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
go_version: ${{ matrix.go }}
go_version: ${{ needs.get-go-version.outputs.go-version }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: report
instructions: |-
go build -ldflags="$GOLDFLAGS" -o "$BIN_PATH" -trimpath -buildvcs=false
build-darwin:
needs: set-product-version
needs:
- set-product-version
- get-go-version
runs-on: macos-latest
strategy:
matrix:
goos: [ darwin ]
goarch: [ "amd64", "arm64" ]
go: [ "1.20.12" ]
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

Expand Down Expand Up @@ -279,7 +277,7 @@ jobs:
with:
product_name: ${{ env.PKG_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
go_version: ${{ matrix.go }}
go_version: ${{ needs.get-go-version.outputs.go-version }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: report
Expand Down
Loading

0 comments on commit ea888cd

Please sign in to comment.