Skip to content

Commit

Permalink
internal/ci: move away from using definitions in base
Browse files Browse the repository at this point in the history
The base package is a template package, not a set of schemas.
Definitions should only be used when something is truly a schema.

This change should not result in any .github/workflows changes.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ib0b226730e0a1cca88b9fd6fbd6c8b545a9add71
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551592
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
myitcv committed Mar 26, 2023
1 parent f446b87 commit d7a1740
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion internal/ci/base/codereview.cue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// #toCodeReviewCfg converts a #codeReview instance to
// the key: value
#toCodeReviewCfg: {
toCodeReviewCfg: {
#input: #codeReview
let parts = [ for k, v in #input {k + ": " + v}]

Expand Down
10 changes: 5 additions & 5 deletions internal/ci/base/gerrithub.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/SchemaStore/schemastore/src/schemas/json"
)

#trybotDispatchWorkflow: json.#Workflow & {
trybotDispatchWorkflow: json.#Workflow & {
#type: string
_#branchNameExpression: "\(#type)/${{ github.event.client_payload.payload.changeID }}/${{ github.event.client_payload.payload.commit }}/${{ steps.gerrithub_ref.outputs.gerrithub_ref }}"
name: "Dispatch \(#type)"
Expand All @@ -17,7 +17,7 @@ import (
"runs-on": linuxMachine
if: "${{ github.event.client_payload.type == '\(#type)' }}"
steps: [
#writeNetrcFile,
writeNetrcFile,
// Out of the entire ref (e.g. refs/changes/38/547738/7) we only
// care about the CL number and patchset, (e.g. 547738/7).
// Note that gerrithub_ref is two path elements.
Expand Down Expand Up @@ -51,7 +51,7 @@ import (
}
}

#pushTipToTrybotWorkflow: json.#Workflow & {
pushTipToTrybotWorkflow: json.#Workflow & {
jobs: [string]: defaults: run: shell: "bash"

name: "Push tip to \(trybot.key)"
Expand All @@ -60,7 +60,7 @@ import (

jobs: push: {
steps: [
#writeNetrcFile,
writeNetrcFile,
json.#step & {
name: "Push tip to trybot"
run: """
Expand All @@ -81,7 +81,7 @@ import (

}

#writeNetrcFile: json.#step & {
writeNetrcFile: json.#step & {
name: "Write netrc file for cueckoo Gerrithub"
run: """
cat <<EOD > ~/.netrc
Expand Down
26 changes: 13 additions & 13 deletions internal/ci/base/github.cue
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
"github.com/SchemaStore/schemastore/src/schemas/json"
)

#bashWorkflow: json.#Workflow & {
bashWorkflow: json.#Workflow & {
jobs: [string]: defaults: run: shell: "bash"
}

#installGo: json.#step & {
installGo: json.#step & {
name: "Install Go"
uses: "actions/setup-go@v3"
with: {
"go-version": *"${{ matrix.go-version }}" | string
}
}

#checkoutCode: {
checkoutCode: {
#actionsCheckout: json.#step & {
name: "Checkout code"
uses: "actions/checkout@v3"
Expand Down Expand Up @@ -61,7 +61,7 @@ import (
]
}

#earlyChecks: json.#step & {
earlyChecks: json.#step & {
name: "Early git and code sanity checks"
run: #"""
# Ensure the recent commit messages have Signed-off-by headers.
Expand Down Expand Up @@ -118,11 +118,11 @@ import (
"""#
}

#curlGitHubAPI: #"""
curlGitHubAPI: #"""
curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.\#(botGitHubUserTokenSecretsKey) }}" -H "X-GitHub-Api-Version: 2022-11-28"
"""#

#setupGoActionsCaches: {
setupGoActionsCaches: {
// #protectedBranchExpr is a GitHub expression
// (https://docs.github.com/en/actions/learn-github-actions/expressions)
// that evaluates to true if the workflow is running for a commit against a
Expand Down Expand Up @@ -180,20 +180,20 @@ import (
// job is running as a result of pushing to one of _#protectedBranchPatterns.
// It would be nice to use the "contains" builtin for simplicity,
// but array literals are not yet supported in expressions.
#isProtectedBranch: {
isProtectedBranch: {
"(" + strings.Join([ for branch in protectedBranchPatterns {
(_#matchPattern & {variable: "github.ref", pattern: "refs/heads/\(branch)"}).expr
(_matchPattern & {variable: "github.ref", pattern: "refs/heads/\(branch)"}).expr
}], " || ") + ")"
}

// #isReleaseTag creates a GitHub expression, based on the given release tag
// pattern, that evaluates to true if called in the context of a workflow that
// is part of a release.
#isReleaseTag: {
(_#matchPattern & {variable: "github.ref", pattern: "refs/tags/\(releaseTagPattern)"}).expr
isReleaseTag: {
(_matchPattern & {variable: "github.ref", pattern: "refs/tags/\(releaseTagPattern)"}).expr
}

#checkGitClean: json.#step & {
checkGitClean: json.#step & {
name: "Check that git is clean at the end of the job"
run: "test -z \"$(git status --porcelain)\" || (git status; git diff; false)"
}
Expand All @@ -202,7 +202,7 @@ let _#repositoryURL = githubRepositoryURL
let _#botGitHubUser = botGitHubUser
let _#botGitHubUserTokenSecretsKey = botGitHubUserTokenSecretsKey

#repositoryDispatch: json.#step & {
repositoryDispatch: json.#step & {
#repositoryURL: *_#repositoryURL | string
#botGitHubUser: *_#botGitHubUser | string
#botGitHubUserTokenSecretsKey: *_#botGitHubUserTokenSecretsKey | string
Expand All @@ -214,6 +214,6 @@ let _#botGitHubUserTokenSecretsKey = botGitHubUserTokenSecretsKey

name: string
run: #"""
\#(#curlGitHubAPI) -f --request POST --data-binary \#(strconv.Quote(encjson.Marshal(#arg))) https://github.com/gitapi/repos/\#(_#repositoryPath)/dispatches
\#(curlGitHubAPI) -f --request POST --data-binary \#(strconv.Quote(encjson.Marshal(#arg))) https://github.com/gitapi/repos/\#(_#repositoryPath)/dispatches
"""#
}
8 changes: 4 additions & 4 deletions internal/ci/base/helpers.cue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"strings"
)

// _#matchPattern returns a GitHub Actions expression which evaluates whether a
// _matchPattern returns a GitHub Actions expression which evaluates whether a
// variable matches a globbing pattern. For literal patterns it uses "==",
// and for suffix patterns it uses "startsWith".
// See https://docs.github.com/en/actions/learn-github-actions/expressions.
_#matchPattern: {
_matchPattern: {
variable: string
pattern: string
expr: [
Expand All @@ -25,15 +25,15 @@ _#matchPattern: {
][0]
}

#doNotEditMessage: {
doNotEditMessage: {
#generatedBy: string
"Code generated \(#generatedBy); DO NOT EDIT."
}

// #URLPath is a temporary measure to derive the path part of a URL.
//
// TODO: remove when cuelang.org/issue/1433 lands.
#URLPath: {
URLPath: {
#url: string
let parts = strings.Split(#url, "/")
strings.Join(list.Slice(parts, 3, len(parts)), "/")
Expand Down
6 changes: 3 additions & 3 deletions internal/ci/ci_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ command: gen: {
"generate \(_filename)": file.Create & {
$after: [ for v in remove {v}]
filename: path.Join([_dir, _filename], _goos)
let donotedit = base.#doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _}
let donotedit = base.doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _}
contents: "# \(donotedit)\n\n\(yaml.Marshal(_workflow))"
}
}
Expand All @@ -68,7 +68,7 @@ command: gen: {
command: gen: codereviewcfg: file.Create & {
_dir: path.FromSlash("../../", path.Unix)
filename: path.Join([_dir, "codereview.cfg"], _goos)
let res = base.#toCodeReviewCfg & {#input: core.codeReview, _}
let donotedit = base.#doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _}
let res = base.toCodeReviewCfg & {#input: core.codeReview, _}
let donotedit = base.doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _}
contents: "# \(donotedit)\n\n\(res)\n"
}
8 changes: 4 additions & 4 deletions internal/ci/github/evict_caches.cue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
//
// In testing with @mvdan, this resulted in cache sizes for Linux dropping from
// ~1GB to ~125MB. This is a considerable saving.
workflows: evict_caches: core.#bashWorkflow & {
workflows: evict_caches: core.bashWorkflow & {
name: "Evict caches"

on: {
Expand All @@ -66,8 +66,8 @@ workflows: evict_caches: core.#bashWorkflow & {
#repo: string
#branch: string
"""
id=$(\(core.#curlGitHubAPI) "https://github.com/gitapi/repos/\(#repo)/actions/workflows/trybot.yml/runs?branch=\(#branch)&event=push&per_page=1" | jq '.workflow_runs[] | .id')
\(core.#curlGitHubAPI) -X POST https://github.com/gitapi/repos/\(#repo)/actions/runs/$id/rerun
id=$(\(core.curlGitHubAPI) "https://github.com/gitapi/repos/\(#repo)/actions/workflows/trybot.yml/runs?branch=\(#branch)&event=push&per_page=1" | jq '.workflow_runs[] | .id')
\(core.curlGitHubAPI) -X POST https://github.com/gitapi/repos/\(#repo)/actions/runs/$id/rerun
"""
}
Expand All @@ -92,7 +92,7 @@ workflows: evict_caches: core.#bashWorkflow & {
# Now trigger the most recent workflow run on each of the default branches.
# We do this by listing all the branches on the main repo and finding those
# which match the protected branch patterns (globs).
for j in $(\(core.#curlGitHubAPI) -f https://github.com/gitapi/repos/\(core.githubRepositoryPath)/branches | jq -r '.[] | .name')
for j in $(\(core.curlGitHubAPI) -f https://github.com/gitapi/repos/\(core.githubRepositoryPath)/branches | jq -r '.[] | .name')
do
for i in \(branchPatterns)
do
Expand Down
2 changes: 1 addition & 1 deletion internal/ci/github/push_tip_to_trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// push_tip_to_trybot "syncs" active branches to the trybot repo.
// Since the workflow is triggered by a push to any of the branches,
// the step only needs to sync the pushed branch.
workflows: push_tip_to_trybot: core.#pushTipToTrybotWorkflow & {
workflows: push_tip_to_trybot: core.pushTipToTrybotWorkflow & {
on: {
push: branches: core.protectedBranchPatterns
}
Expand Down
14 changes: 7 additions & 7 deletions internal/ci/github/release.cue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
_#cueVersionRef: "${GITHUB_REF##refs/tags/}"

// The release workflow
workflows: release: core.#bashWorkflow & {
workflows: release: core.bashWorkflow & {

name: "Release"

Expand All @@ -44,8 +44,8 @@ workflows: release: core.#bashWorkflow & {
"runs-on": core.linuxMachine
if: "${{github.repository == '\(core.githubRepositoryPath)'}}"
steps: [
for v in core.#checkoutCode {v},
core.#installGo & {
for v in core.checkoutCode {v},
core.installGo & {
with: "go-version": core.pinnedReleaseGo
},
json.#step & {
Expand Down Expand Up @@ -85,17 +85,17 @@ workflows: release: core.#bashWorkflow & {
run: "cue cmd release"
"working-directory": "./internal/ci/goreleaser"
},
core.#repositoryDispatch & {
core.repositoryDispatch & {
name: "Re-test cuelang.org"
if: core.#isReleaseTag
if: core.isReleaseTag
#repositoryURL: "https://github.com/cue-lang/cuelang.org"
#arg: {
event_type: "Re-test post release of \(_#cueVersionRef)"
}
},
core.#repositoryDispatch & {
core.repositoryDispatch & {
name: "Trigger unity build"
if: core.#isReleaseTag
if: core.isReleaseTag
#repositoryURL: core.unityRepositoryURL
#arg: {
event_type: "Check against CUE \(_#cueVersionRef)"
Expand Down
6 changes: 3 additions & 3 deletions internal/ci/github/tip_triggers.cue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (

// The tip_triggers workflow. This fires for each new commit that hits the
// default branch.
workflows: tip_triggers: core.#bashWorkflow & {
workflows: tip_triggers: core.bashWorkflow & {

name: "Triggers on push to tip"
on: push: branches: [core.defaultBranch]
jobs: push: {
"runs-on": core.linuxMachine
if: "${{github.repository == '\(core.githubRepositoryPath)'}}"
steps: [
core.#repositoryDispatch & {
core.repositoryDispatch & {
name: "Trigger tip.cuelang.org deploy"
#repositoryURL: "https://github.com/cue-lang/cuelang.org"
#arg: {
Expand All @@ -38,7 +38,7 @@ workflows: tip_triggers: core.#bashWorkflow & {
}
}
},
core.#repositoryDispatch & {
core.repositoryDispatch & {
name: "Trigger unity build"
#repositoryURL: "https://github.com/cue-unity/unity"
#arg: {
Expand Down
20 changes: 10 additions & 10 deletions internal/ci/github/trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// The trybot workflow.
workflows: trybot: core.#bashWorkflow & {
workflows: trybot: core.bashWorkflow & {
name: core.trybot.name

on: {
Expand All @@ -39,11 +39,11 @@ workflows: trybot: core.#bashWorkflow & {
strategy: _#testStrategy
"runs-on": "${{ matrix.os }}"

let goCaches = core.#setupGoActionsCaches & {#protectedBranchExpr: core.#isProtectedBranch, _}
let goCaches = core.setupGoActionsCaches & {#protectedBranchExpr: core.isProtectedBranch, _}

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

// cachePre must come after installing Node and Go, because the cache locations
// are established by running each tool.
Expand All @@ -55,28 +55,28 @@ workflows: trybot: core.#bashWorkflow & {
// subsequent CLs in the trybot repo can leverage the updated
// cache. Therefore, we instead perform a clean of the testcache.
json.#step & {
if: "github.repository == '\(core.githubRepositoryPath)' && (\(core.#isProtectedBranch) || github.ref == 'refs/heads/\(core.testDefaultBranch)')"
if: "github.repository == '\(core.githubRepositoryPath)' && (\(core.isProtectedBranch) || github.ref == 'refs/heads/\(core.testDefaultBranch)')"
run: "go clean -testcache"
},

core.#earlyChecks & {
core.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: core.isLatestLinux
},
json.#step & {
if: "\(core.#isProtectedBranch) || \(core.isLatestLinux)"
if: "\(core.isProtectedBranch) || \(core.isLatestLinux)"
run: "echo CUE_LONG=true >> $GITHUB_ENV"
},
_#goGenerate,
_#goTest & {
if: "\(core.#isProtectedBranch) || !\(core.isLatestLinux)"
if: "\(core.isProtectedBranch) || !\(core.isLatestLinux)"
},
_#goTestRace & {
if: core.isLatestLinux
},
_#goCheck,
core.#checkGitClean,
core.checkGitClean,
_#pullThroughProxy,
]
}
Expand Down Expand Up @@ -123,7 +123,7 @@ workflows: trybot: core.#bashWorkflow & {
echo "giving up after a number of retries"
exit 1
"""
if: "\(core.#isProtectedBranch) && \(core.isLatestLinux)"
if: "\(core.isProtectedBranch) && \(core.isLatestLinux)"
}

_#goGenerate: json.#step & {
Expand Down
2 changes: 1 addition & 1 deletion internal/ci/github/trybot_dispatch.cue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ import (
)

// The trybot_dispatch workflow.
workflows: trybot_dispatch: core.#bashWorkflow & core.#trybotDispatchWorkflow & {
workflows: trybot_dispatch: core.bashWorkflow & core.trybotDispatchWorkflow & {
#type: core.trybot.key
}

0 comments on commit d7a1740

Please sign in to comment.