Skip to content

Commit

Permalink
internal/ci: move core package away from definitions
Browse files Browse the repository at this point in the history
The data values in the core package are just that: common values used by
other configuration packages. They do not, therefore, need to be
definitions. Indeed the use of # is just noisy for values that are all
concrete (and therefore cannot be changed).

The principal use of # is to enforce closedness. The values in core are
either concrete (most are strings) or the container values (structs and
lists) abide by definitions from other packages.

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

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: Ib06cfe118051b201c57d3ad2d1b8d1307ba4ce0f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551387
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
myitcv committed Mar 25, 2023
1 parent e1a8bee commit 5475370
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 51 deletions.
52 changes: 26 additions & 26 deletions internal/ci/core/core.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
)

// Define core URLs that will be used in the codereview.cfg and GitHub workflows
#githubRepositoryURL: "https://github.com/cue-lang/cue"
#gerritRepositoryURL: "https://review.gerrithub.io/a/cue-lang/cue"
#githubRepositoryPath: _#URLPath & {#url: #githubRepositoryURL, _}
#unityRepositoryURL: "https://github.com/cue-unity/unity"
githubRepositoryURL: "https://github.com/cue-lang/cue"
gerritRepositoryURL: "https://review.gerrithub.io/a/cue-lang/cue"
githubRepositoryPath: _#URLPath & {#url: githubRepositoryURL, _}
unityRepositoryURL: "https://github.com/cue-unity/unity"

// Not ideal, but hack together something that gives us the path
// of a URL. In lieu of cuelang.org/issue/1433
Expand All @@ -24,34 +24,34 @@ _#URLPath: {

// Use the latest Go version for extra checks,
// such as running tests with the data race detector.
#latestStableGo: "1.19.x"
latestStableGo: "1.19.x"

// Use a specific latest version for release builds.
// Note that we don't want ".x" for the sake of reproducibility,
// so we instead pin a specific Go release.
#pinnedReleaseGo: "1.19.7"
pinnedReleaseGo: "1.19.7"

#goreleaserVersion: "v1.13.1"
goreleaserVersion: "v1.13.1"

#defaultBranch: "master"
defaultBranch: "master"

// #releaseBranchPrefix is the git branch name prefix used to identify
// releaseBranchPrefix is the git branch name prefix used to identify
// release branches.
#releaseBranchPrefix: "release-branch."
releaseBranchPrefix: "release-branch."

// #releaseBranchPattern is the GitHub pattern that corresponds to
// #releaseBranchPrefix.
#releaseBranchPattern: #releaseBranchPrefix + "*"
// releaseBranchPattern is the GitHub pattern that corresponds to
// releaseBranchPrefix.
releaseBranchPattern: releaseBranchPrefix + "*"

// #releaseTagPrefix is the prefix used to identify all git tag that correspond
// releaseTagPrefix is the prefix used to identify all git tag that correspond
// to semver releases
#releaseTagPrefix: "v"
releaseTagPrefix: "v"

// #releaseTagPattern is the GitHub glob pattern that corresponds to
// #releaseTagPrefix.
#releaseTagPattern: #releaseTagPrefix + "*"
// releaseTagPattern is the GitHub glob pattern that corresponds to
// releaseTagPrefix.
releaseTagPattern: releaseTagPrefix + "*"

// #zeroReleaseTagSuffix is the suffix used to identify all "zero" releases.
// zeroReleaseTagSuffix is the suffix used to identify all "zero" releases.
// When we create a release branch for v0.$X.0, it's likely that commits on the
// default branch will from that point onwards be intended for the $X+1
// version. However, unless we tag the next commit after the release branch, it
Expand All @@ -61,11 +61,11 @@ _#URLPath: {
// A "zero" tag fixes this when applied to the first commit after a release
// branch. Critically, the -0.dev pre-release suffix is ordered before -alpha.
// tags.
#zeroReleaseTagSuffix: "-0.dev"
zeroReleaseTagSuffix: "-0.dev"

// #zeroReleaseTagPattern is the GitHub glob pattern that corresponds
// #zeroReleaseTagSuffix.
#zeroReleaseTagPattern: "*" + #zeroReleaseTagSuffix
// zeroReleaseTagPattern is the GitHub glob pattern that corresponds
// zeroReleaseTagSuffix.
zeroReleaseTagPattern: "*" + zeroReleaseTagSuffix

#codeReview: {
gerrit?: string
Expand All @@ -74,9 +74,9 @@ _#URLPath: {
}

codeReview: #codeReview & {
github: #githubRepositoryURL
gerrit: #gerritRepositoryURL
"cue-unity": #unityRepositoryURL
github: githubRepositoryURL
gerrit: gerritRepositoryURL
"cue-unity": unityRepositoryURL
}

// #toCodeReviewCfg converts a #codeReview instance to
Expand Down
10 changes: 5 additions & 5 deletions internal/ci/github/evict_caches.cue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ workflows: evict_caches: _base.#bashWorkflow & {
jobs: {
test: {
// We only want to run this in the main repo
if: "${{github.repository == '\(core.#githubRepositoryPath)'}}"
if: "${{github.repository == '\(core.githubRepositoryPath)'}}"
"runs-on": _#linuxMachine
steps: [
json.#step & {
Expand All @@ -77,7 +77,7 @@ workflows: evict_caches: _base.#bashWorkflow & {
echo ${{ secrets.CUECKOO_GITHUB_PAT }} | gh auth login --with-token
gh extension install actions/gh-actions-cache
for i in \(core.#githubRepositoryURL) \(core.#githubRepositoryURL)-trybot
for i in \(core.githubRepositoryURL) \(core.githubRepositoryURL)-trybot
do
echo "Evicting caches for $i"
cd $(mktemp -d)
Expand All @@ -92,7 +92,7 @@ workflows: evict_caches: _base.#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 $(\(_base.#curlGitHubAPI) -f https://github.com/gitapi/repos/\(core.#githubRepositoryPath)/branches | jq -r '.[] | .name')
for j in $(\(_base.#curlGitHubAPI) -f https://github.com/gitapi/repos/\(core.githubRepositoryPath)/branches | jq -r '.[] | .name')
do
for i in \(branchPatterns)
do
Expand All @@ -101,8 +101,8 @@ workflows: evict_caches: _base.#bashWorkflow & {
fi
echo "$j is a match with $i"
\(rerunLatestWorkflow & {#repo: core.#githubRepositoryPath, #branch: "$j", _})
\(rerunLatestWorkflow & {#repo: core.#githubRepositoryPath + "-trybot", #branch: "$j", _})
\(rerunLatestWorkflow & {#repo: core.githubRepositoryPath, #branch: "$j", _})
\(rerunLatestWorkflow & {#repo: core.githubRepositoryPath + "-trybot", #branch: "$j", _})
done
done
"""
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 @@ -34,7 +34,7 @@ workflows: push_tip_to_trybot: _base.#bashWorkflow & {

jobs: push: {
"runs-on": _#linuxMachine
if: "${{github.repository == '\(core.#githubRepositoryPath)'}}"
if: "${{github.repository == '\(core.githubRepositoryPath)'}}"
steps: [
_gerrithub.#writeNetrcFile,
json.#step & {
Expand Down
10 changes: 5 additions & 5 deletions internal/ci/github/release.cue
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ workflows: release: _base.#bashWorkflow & {
concurrency: "release"

on: push: {
tags: [core.#releaseTagPattern, "!" + core.#zeroReleaseTagPattern]
tags: [core.releaseTagPattern, "!" + core.zeroReleaseTagPattern]
branches: list.Concat([[_base.#testDefaultBranch], _#protectedBranchPatterns])
}
jobs: goreleaser: {
"runs-on": _#linuxMachine
if: "${{github.repository == '\(core.#githubRepositoryPath)'}}"
if: "${{github.repository == '\(core.githubRepositoryPath)'}}"
steps: [
for v in _base.#checkoutCode {v},
_base.#installGo & {
with: "go-version": core.#pinnedReleaseGo
with: "go-version": core.pinnedReleaseGo
},
json.#step & {
name: "Setup qemu"
Expand Down Expand Up @@ -74,7 +74,7 @@ workflows: release: _base.#bashWorkflow & {
uses: "goreleaser/goreleaser-action@v3"
with: {
"install-only": true
version: core.#goreleaserVersion
version: core.goreleaserVersion
}
},
json.#step & {
Expand All @@ -96,7 +96,7 @@ workflows: release: _base.#bashWorkflow & {
_base.#repositoryDispatch & {
name: "Trigger unity build"
if: _#isReleaseTag
#repositoryURL: core.#unityRepositoryURL
#repositoryURL: core.unityRepositoryURL
#arg: {
event_type: "Check against CUE \(_#cueVersionRef)"
client_payload: {
Expand Down
4 changes: 2 additions & 2 deletions internal/ci/github/tip_triggers.cue
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
workflows: tip_triggers: _base.#bashWorkflow & {

name: "Triggers on push to tip"
on: push: branches: [core.#defaultBranch]
on: push: branches: [core.defaultBranch]
jobs: push: {
"runs-on": _#linuxMachine
if: "${{github.repository == '\(core.#githubRepositoryPath)'}}"
if: "${{github.repository == '\(core.githubRepositoryPath)'}}"
steps: [
_base.#repositoryDispatch & {
name: "Trigger tip.cuelang.org deploy"
Expand Down
6 changes: 3 additions & 3 deletions internal/ci/github/trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ workflows: trybot: _base.#bashWorkflow & {
on: {
push: {
branches: list.Concat([["trybot/*/*", _base.#testDefaultBranch], _#protectedBranchPatterns]) // do not run PR branches
"tags-ignore": [core.#releaseTagPattern]
"tags-ignore": [core.releaseTagPattern]
}
pull_request: {}
}
Expand All @@ -59,7 +59,7 @@ workflows: trybot: _base.#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)' && (\(_#isProtectedBranch) || github.ref == 'refs/heads/\(_base.#testDefaultBranch)')"
if: "github.repository == '\(core.githubRepositoryPath)' && (\(_#isProtectedBranch) || github.ref == 'refs/heads/\(_base.#testDefaultBranch)')"
run: "go clean -testcache"
},

Expand Down Expand Up @@ -87,7 +87,7 @@ workflows: trybot: _base.#bashWorkflow & {
}

_#pullThroughProxy: json.#step & {
name: "Pull this commit through the proxy on \(core.#defaultBranch)"
name: "Pull this commit through the proxy on \(core.defaultBranch)"
run: """
v=$(git rev-parse HEAD)
cd $(mktemp -d)
Expand Down
14 changes: 7 additions & 7 deletions internal/ci/github/workflows.cue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ workflows: close({
// This includes the default branch and release branches,
// but excludes any others like feature branches or short-lived branches.
// Note that #testDefaultBranch is excluded as it is GitHub-only.
_#protectedBranchPatterns: [core.#defaultBranch, core.#releaseBranchPattern]
_#protectedBranchPatterns: [core.defaultBranch, core.releaseBranchPattern]

// _#matchPattern returns a GitHub Actions expression which evaluates whether a
// variable matches a globbing pattern. For literal patterns it uses "==",
Expand Down Expand Up @@ -87,7 +87,7 @@ _#isProtectedBranch: "(" + strings.Join([ for branch in _#protectedBranchPattern
(_#matchPattern & {variable: "github.ref", pattern: "refs/heads/\(branch)"}).expr
}], " || ") + ")"

_#isReleaseTag: (_#matchPattern & {variable: "github.ref", pattern: "refs/tags/\(core.#releaseTagPattern)"}).expr
_#isReleaseTag: (_#matchPattern & {variable: "github.ref", pattern: "refs/tags/\(core.releaseTagPattern)"}).expr

_#linuxMachine: "ubuntu-22.04"
_#macosMachine: "macos-11"
Expand All @@ -96,20 +96,20 @@ _#windowsMachine: "windows-2022"
// _#isLatestLinux 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 == '\(core.#latestStableGo)' && matrix.os == '\(_#linuxMachine)')"
_#isLatestLinux: "(matrix.go-version == '\(core.latestStableGo)' && matrix.os == '\(_#linuxMachine)')"

_#testStrategy: {
"fail-fast": false
matrix: {
"go-version": ["1.18.x", core.#latestStableGo]
"go-version": ["1.18.x", core.latestStableGo]
os: [_#linuxMachine, _#macosMachine, _#windowsMachine]
}
}

// _gerrithub is an instance of ./gerrithub, parameterised by the properties of
// this project
_gerrithub: gerrithub & {
#repositoryURL: core.#githubRepositoryURL
#repositoryURL: core.githubRepositoryURL
#botGitHubUser: "cueckoo"
#botGitHubUserTokenSecretsKey: "CUECKOO_GITHUB_PAT"
#botGitHubUserEmail: "cueckoo@gmail.com"
Expand All @@ -125,8 +125,8 @@ _gerrithub: gerrithub & {
// Perhaps rename the import to something more obviously not intended to be
// used, and then rename the field base?
_base: base & {
#repositoryURL: core.#githubRepositoryURL
#defaultBranch: core.#defaultBranch
#repositoryURL: core.githubRepositoryURL
#defaultBranch: core.defaultBranch
#botGitHubUser: "cueckoo"
#botGitHubUserTokenSecretsKey: "CUECKOO_GITHUB_PAT"
}
Expand Down
4 changes: 2 additions & 2 deletions internal/ci/goreleaser/goreleaser_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ command: release: {
"goreleaser", "release", "-f", "-", "--rm-dist",

// Only run the full release when running on GitHub actions for a release tag.
// Keep in sync with core.#releaseTagPattern, which is a globbing pattern
// Keep in sync with core.releaseTagPattern, which is a globbing pattern
// rather than a regular expression.
if _githubRef !~ "refs/tags/\(core.#releaseTagPrefix).*" {
if _githubRef !~ "refs/tags/\(core.releaseTagPrefix).*" {
"--snapshot"
},
]
Expand Down

0 comments on commit 5475370

Please sign in to comment.