Skip to content

Commit

Permalink
internal/ci: remove mention of matrix and runner from base
Browse files Browse the repository at this point in the history
The use of a matrix or runner in a workflow should be something local
and specific to that workflow, especially for matrix.

The base package should therefore not make any mention of the concept of
matrix (or runner), until such time as we clearly establish a
pattern/default where this makes sense.

The oft-used logic isLatestLinux is by definition dependent on the
matrix definition and should also be local to the workflow. Therefore,
matrix should not (in general) be mentioned in repo either.

Also move away from using the term os in the test matrix. It is not an
os, rather it is a runner image. Use the field name runner instead.
runner.os _is_ an OS. DRY up the trybot declaration accordingly.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ic6261a7f30353b2f49e08a2ccb5a8e3e88037e0a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551939
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
myitcv committed Mar 30, 2023
1 parent 5cd427a commit 3ed9f92
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/trybot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
go-version:
- 1.19.x
- 1.20.x
os:
runner:
- ubuntu-22.04
- macos-11
- windows-2022
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.runner }}
defaults:
run:
shell: bash
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
restore-keys: ${{ runner.os }}-${{ matrix.go-version }}
- if: github.repository == 'cue-lang/cue' && ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) || github.ref == 'refs/heads/ci/test')
run: go clean -testcache
- if: (matrix.go-version == '1.20.x' && matrix.os == 'ubuntu-22.04')
- if: (matrix.go-version == '1.20.x' && matrix.runner == 'ubuntu-22.04')
name: Early git and code sanity checks
run: |-
# Ensure the recent commit messages have Signed-off-by headers.
Expand Down Expand Up @@ -119,18 +119,18 @@ jobs:
echo "commit author email address does not match signed-off-by trailer"
exit 1
fi
- if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) || (matrix.go-version == '1.20.x' && matrix.os == 'ubuntu-22.04')
- if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) || (matrix.go-version == '1.20.x' && matrix.runner == 'ubuntu-22.04')
run: echo CUE_LONG=true >> $GITHUB_ENV
- if: (matrix.go-version == '1.20.x' && matrix.os == 'ubuntu-22.04')
- if: (matrix.go-version == '1.20.x' && matrix.runner == 'ubuntu-22.04')
name: Generate
run: go generate ./...
- if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) || !(matrix.go-version == '1.20.x' && matrix.os == 'ubuntu-22.04')
- if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) || !(matrix.go-version == '1.20.x' && matrix.runner == 'ubuntu-22.04')
name: Test
run: go test ./...
- if: (matrix.go-version == '1.20.x' && matrix.os == 'ubuntu-22.04')
- if: (matrix.go-version == '1.20.x' && matrix.runner == 'ubuntu-22.04')
name: Test with -race
run: go test -race ./...
- if: (matrix.go-version == '1.20.x' && matrix.os == 'ubuntu-22.04')
- if: (matrix.go-version == '1.20.x' && matrix.runner == 'ubuntu-22.04')
name: Check
run: go vet ./...
- name: Check that git is clean at the end of the job
Expand Down
6 changes: 4 additions & 2 deletions internal/ci/base/github.cue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ installGo: json.#step & {
with: {
// We do our own caching in setupGoActionsCaches.
cache: false
"go-version": *"${{ matrix.go-version }}" | string
"go-version": string
}
}

Expand Down Expand Up @@ -135,6 +135,8 @@ setupGoActionsCaches: {
// encapsulates our needs.
#readonly: *false | bool
#cleanTestCache: *!#readonly | bool
#goVersion: string
#os: string

let goModCacheDirID = "go-mod-cache-dir"
let goCacheDirID = "go-cache-dir"
Expand All @@ -144,7 +146,7 @@ setupGoActionsCaches: {
// that participate in Go caching.
let cacheDirs = [ "${{ steps.\(goModCacheDirID).outputs.dir }}/cache/download", "${{ steps.\(goCacheDirID).outputs.dir }}"]

let cacheRestoreKeys = "${{ runner.os }}-${{ matrix.go-version }}"
let cacheRestoreKeys = "\(#os)-\(#goVersion)"

let cacheStep = json.#step & {
with: {
Expand Down
41 changes: 31 additions & 10 deletions internal/ci/github/trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -35,52 +35,73 @@ workflows: trybot: _repo.bashWorkflow & {
jobs: {
test: {
strategy: _testStrategy
"runs-on": "${{ matrix.os }}"
"runs-on": "${{ matrix.runner }}"

let _setupGoActionsCaches = _repo.setupGoActionsCaches & {
#goVersion: goVersionVal
#os: runnerOSVal
_
}

steps: [
for v in _repo.checkoutCode {v},
_repo.installGo,

_repo.installGo & {
with: "go-version": goVersionVal
},

// cachePre must come after installing Node and Go, because the cache locations
// are established by running each tool.
for v in _repo.setupGoActionsCaches {v},
for v in _setupGoActionsCaches {v},

_repo.earlyChecks & {
// These checks don't vary based on the Go version or OS,
// so we only need to run them on one of the matrix jobs.
if: _repo.isLatestLinux
if: _isLatestLinux
},
json.#step & {
if: "\(_repo.isProtectedBranch) || \(_repo.isLatestLinux)"
if: "\(_repo.isProtectedBranch) || \(_isLatestLinux)"
run: "echo CUE_LONG=true >> $GITHUB_ENV"
},
_goGenerate,
_goTest & {
if: "\(_repo.isProtectedBranch) || !\(_repo.isLatestLinux)"
if: "\(_repo.isProtectedBranch) || !\(_isLatestLinux)"
},
_goTestRace & {
if: _repo.isLatestLinux
if: _isLatestLinux
},
_goCheck,
_repo.checkGitClean,
]
}
}

let runnerOS = "runner.os"
let runnerOSVal = "${{ \(runnerOS) }}"
let matrixRunner = "matrix.runner"
let goVersion = "matrix.go-version"
let goVersionVal = "${{ \(goVersion) }}"

_testStrategy: {
"fail-fast": false
matrix: {
"go-version": ["1.19.x", _repo.latestStableGo]
os: [_repo.linuxMachine, _repo.macosMachine, _repo.windowsMachine]
runner: [_repo.linuxMachine, _repo.macosMachine, _repo.windowsMachine]
}
}

// _isLatestLinux returns a GitHub expression that evaluates to true if the job
// is running on Linux with the latest version of Go. This expression is often
// used to run certain steps just once per CI workflow, to avoid duplicated
// work.
_isLatestLinux: "(\(goVersion) == '\(_repo.latestStableGo)' && \(matrixRunner) == '\(_repo.linuxMachine)')"

_goGenerate: json.#step & {
name: "Generate"
run: "go generate ./..."
// The Go version corresponds to the precise version specified in
// the matrix. Skip windows for now until we work out why re-gen is flaky
if: _repo.isLatestLinux
if: _isLatestLinux
}

_goTest: json.#step & {
Expand All @@ -95,7 +116,7 @@ workflows: trybot: _repo.bashWorkflow & {
// dependencies that vary wildly between platforms.
// For now, to save CI resources, just run the checks on one matrix job.
// TODO: consider adding more checks as per https://github.com/golang/go/issues/42119.
if: "\(_repo.isLatestLinux)"
if: "\(_isLatestLinux)"
name: "Check"
run: "go vet ./..."
}
Expand Down
6 changes: 0 additions & 6 deletions internal/ci/repo/repo.cue
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,3 @@ zeroReleaseTagSuffix: "-0.dev"
zeroReleaseTagPattern: "*" + zeroReleaseTagSuffix

codeReview: "cue-unity": unityRepositoryURL

// isLatestLinux returns a GitHub expression that evaluates to true if the job
// is running on Linux with the latest version of Go. This expression is often
// used to run certain steps just once per CI workflow, to avoid duplicated
// work.
isLatestLinux: "(matrix.go-version == '\(latestStableGo)' && matrix.os == '\(linuxMachine)')"

0 comments on commit 3ed9f92

Please sign in to comment.