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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// Copyright 2022 The CUE Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package github
import (
"list"
"path"
"github.com/SchemaStore/schemastore/src/schemas/json"
)
// The trybot workflow.
workflows: trybot: _repo.bashWorkflow & {
name: _repo.trybot.name
on: {
push: {
branches: list.Concat([[_repo.testDefaultBranch], _repo.protectedBranchPatterns]) // do not run PR branches
}
pull_request: {}
}
jobs: {
test: {
"runs-on": _repo.linuxMachine
let runnerOSExpr = "runner.os"
let runnerOSVal = "${{ \(runnerOSExpr) }}"
let installGo = _repo.installGo & {
#setupGo: with: "go-version": _repo.latestGo
_
}
let _setupGoActionsCaches = _repo.setupGoActionsCaches & {
#goVersion: _repo.latestGo
#os: runnerOSVal
_
}
// Only run the trybot workflow if we have the trybot trailer, or
// if we have no special trailers. Note this condition applies
// after and in addition to the "on" condition above.
if: "\(_repo.containsTrybotTrailer) || ! \(_repo.containsDispatchTrailer)"
steps: [
for v in _repo.checkoutCode {v},
for v in installGo {v},
for v in _setupGoActionsCaches {v},
_repo.earlyChecks,
for _, v in perModuleChecks {v},
// Run "go work sync" after we have checked and tested every module.
// This way, if a "go test" command fails, it is much easier for the developer
// to reproduce on their machine without having to remember "go work sync".
// If "go work sync" makes any changes, then the git clean check below will fail anyway.
json.#step & {
run: "go work sync"
},
_repo.checkGitClean,
]
}
}
let perModuleChecks = [
for _, goModPath in _repo.modules
let modDir = path.Dir(goModPath)
let modIsInternal = _#goModDirIsInternal & {#goModDir: modDir, _}
for _, gowork in ["", if !modIsInternal {"off"}]
for _, step in [_#goGenerate, _#goTest, _#goCheck] {
step & {
#name: modDir + [if gowork != "" {" with GOWORK=\(gowork)"}, ""][0]
"working-directory": modDir
env: {
GOWORK: gowork
}
}
},
]
// _#goModIsInternal determins whether a repo root-relative directory path
// to a go.mod filepath is internal from a Go modules perspective.
_#goModDirIsInternal: {
// #path is the repo root-relative directory path containing a go.mod
// file
#goModDir: string
let pathElems = path.Split(#goModDir)
let isInternal = [for _, v in pathElems {v == "internal"}]
_res: [for i, v in isInternal {[if i == 0 {false}, _res[i-1]][0] || v}]
// In case the root is a module
*_res[0] | false
}
_#goGenerate: json.#step & {
#name: string
name: "Generate \(#name)"
run: "go generate ./..."
}
_#goTest: json.#step & {
#name: string
name: "Test \(#name)"
run: "go test ./..."
}
_#goCheck: json.#step & {
// These checks can vary between platforms, as different code can be built
// based on GOOS and GOARCH build tags.
// However, CUE does not have any such build tags yet, and we don't use
// 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.
#name: string
name: "Check \(#name)"
run: "go vet ./..."
}
}
|