Skip to content

Commit d9aaac0

Browse files
committed
internal/ci: apply the top-level githubactions.#Workflow schema
We used to not do this in workflows.cue for the sake of performance, but those issues are now resolved. Thanks to that, all the lists of steps under workflows no longer need to unify all steps with the #Step schema; we now only do that with reusable steps for the sake of showing errors early in the config. While here, checkoutCode can now be a simple list as it no longer has any logic which requires parameters via a nested definition. Similarly, installGo had an unnecessary embedding remaining from earlier logic which is now gone. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ie2e118e3e549e3e4260bfc9d7c68396b8377eca1 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1218614 Reviewed-by: Paul Jolly <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent eac9728 commit d9aaac0

File tree

5 files changed

+80
-90
lines changed

5 files changed

+80
-90
lines changed

.github/workflows/trybot_dispatch.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ jobs:
2222
password ${{ secrets.CUECKOO_GERRITHUB_PASSWORD }}
2323
EOD
2424
chmod 600 ~/.netrc
25-
- id: payload
25+
- name: Write fake payload
26+
id: payload
2627
if: github.repository == 'cue-lang/cue' && (github.ref == 'refs/heads/ci/test')
27-
name: Write fake payload
2828
run: |-
2929
cat <<EOD >> $GITHUB_OUTPUT
3030
value<<DOE
3131
null
3232
DOE
3333
EOD
34-
- if: github.event.client_payload.type != 'trybot'
35-
name: Trigger TryBot (fake data)
34+
- name: Trigger TryBot (fake data)
35+
if: github.event.client_payload.type != 'trybot'
3636
run: |-
3737
mkdir tmpgit
3838
cd tmpgit
@@ -81,8 +81,8 @@ jobs:
8181
echo "Giving up"
8282
exit 1
8383
fi
84-
- if: github.event.client_payload.type == 'trybot'
85-
name: Trigger TryBot (repository_dispatch payload)
84+
- name: Trigger TryBot (repository_dispatch payload)
85+
if: github.event.client_payload.type == 'trybot'
8686
run: |-
8787
mkdir tmpgit
8888
cd tmpgit

internal/ci/base/gerrithub.cue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ trybotDispatchWorkflow: bashWorkflow & {
6868
steps: [
6969
writeNetrcFile,
7070

71-
githubactions.#Step & {
71+
{
7272
name: "Write fake payload"
7373
id: "payload"
7474
if: "github.repository == '\(githubRepositoryPath)' && \(isTestDefaultBranch)"
@@ -97,7 +97,7 @@ trybotDispatchWorkflow: bashWorkflow & {
9797
for v in cases {
9898
let localBranchExpr = "local_${{ \(v.expr).targetBranch }}"
9999
let targetBranchExpr = "${{ \(v.expr).targetBranch }}"
100-
githubactions.#Step & {
100+
{
101101
name: "Trigger \(trybot.name) (\(v.nameSuffix))"
102102
if: "github.event.client_payload.type \(v.condition) '\(trybot.key)'"
103103
run: """
@@ -172,7 +172,7 @@ pushTipToTrybotWorkflow: bashWorkflow & {
172172
jobs: push: {
173173
steps: [
174174
writeNetrcFile,
175-
githubactions.#Step & {
175+
{
176176
name: "Push tip to trybot"
177177
run: """
178178
mkdir tmpgit

internal/ci/base/github.cue

Lines changed: 64 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,25 @@ installGo: {
5151
[
5252
#setupGo,
5353

54-
{
55-
githubactions.#Step & {
56-
name: "Set common go env vars"
57-
run: """
58-
go env -w GOTOOLCHAIN=local
59-
60-
case $(go env GOARCH) in
61-
amd64) go env -w GOAMD64=v3 ;; # 2013 and later; makes `go test -race` 15% faster
62-
arm64) go env -w GOARM64=v8.6 ;; # Apple M2 and later
63-
esac
64-
65-
# Dump env for good measure
66-
go env
67-
"""
68-
}
54+
githubactions.#Step & {
55+
name: "Set common go env vars"
56+
run: """
57+
go env -w GOTOOLCHAIN=local
58+
59+
case $(go env GOARCH) in
60+
amd64) go env -w GOAMD64=v3 ;; # 2013 and later; makes `go test -race` 15% faster
61+
arm64) go env -w GOARM64=v8.6 ;; # Apple M2 and later
62+
esac
63+
64+
# Dump env for good measure
65+
go env
66+
"""
6967
},
7068
]
7169
}
7270

73-
checkoutCode: {
74-
#actionsCheckout: githubactions.#Step & {
71+
checkoutCode: [...githubactions.#Step] & [
72+
{
7573
name: "Checkout code"
7674
uses: "actions/checkout@v4" // TODO(mvdan): switch to namespacelabs/nscloud-checkout-action@v1 once Windows supports caching
7775

@@ -84,64 +82,58 @@ checkoutCode: {
8482
ref: "${{ github.event.pull_request.head.sha }}"
8583
"fetch-depth": 0 // see the docs below
8684
}
87-
}
85+
},
8886

89-
[
90-
#actionsCheckout,
91-
92-
// Restore modified times to work around https://go.dev/issues/58571,
93-
// as otherwise we would get lots of unnecessary Go test cache misses.
94-
// Note that this action requires actions/checkout to use a fetch-depth of 0.
95-
// Since this is a third-party action which runs arbitrary code,
96-
// we pin a commit hash for v2 to be in control of code updates.
97-
// Also note that git-restore-mtime does not update all directories,
98-
// per the bug report at https://github.com/MestreLion/git-tools/issues/47,
99-
// so we first reset all directory timestamps to a static time as a fallback.
100-
// TODO(mvdan): May be unnecessary once the Go bug above is fixed.
101-
githubactions.#Step & {
102-
name: "Reset git directory modification times"
103-
run: "touch -t 202211302355 $(find * -type d)"
104-
},
105-
githubactions.#Step & {
106-
name: "Restore git file modification times"
107-
uses: "chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe"
108-
},
87+
// Restore modified times to work around https://go.dev/issues/58571,
88+
// as otherwise we would get lots of unnecessary Go test cache misses.
89+
// Note that this action requires actions/checkout to use a fetch-depth of 0.
90+
// Since this is a third-party action which runs arbitrary code,
91+
// we pin a commit hash for v2 to be in control of code updates.
92+
// Also note that git-restore-mtime does not update all directories,
93+
// per the bug report at https://github.com/MestreLion/git-tools/issues/47,
94+
// so we first reset all directory timestamps to a static time as a fallback.
95+
// TODO(mvdan): May be unnecessary once the Go bug above is fixed.
96+
{
97+
name: "Reset git directory modification times"
98+
run: "touch -t 202211302355 $(find * -type d)"
99+
},
100+
{
101+
name: "Restore git file modification times"
102+
uses: "chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe"
103+
},
109104

110-
{
111-
githubactions.#Step & {
112-
name: "Try to extract \(dispatchTrailer)"
113-
id: dispatchTrailerStepID
114-
run: """
115-
x="$(git log -1 --pretty='%(trailers:key=\(dispatchTrailer),valueonly)')"
116-
if [[ "$x" == "" ]]
117-
then
118-
# Some steps rely on the presence or otherwise of the Dispatch-Trailer.
119-
# We know that we don't have a Dispatch-Trailer in this situation,
120-
# hence we use the JSON value null in order to represent that state.
121-
# This means that GitHub expressions can determine whether a Dispatch-Trailer
122-
# is present or not by checking whether the fromJSON() result of the
123-
# output from this step is the JSON value null or not.
124-
x=null
125-
fi
126-
echo "\(_dispatchTrailerDecodeStepOutputVar)<<EOD" >> $GITHUB_OUTPUT
127-
echo "$x" >> $GITHUB_OUTPUT
128-
echo "EOD" >> $GITHUB_OUTPUT
129-
"""
130-
}
131-
},
105+
{
106+
name: "Try to extract \(dispatchTrailer)"
107+
id: dispatchTrailerStepID
108+
run: """
109+
x="$(git log -1 --pretty='%(trailers:key=\(dispatchTrailer),valueonly)')"
110+
if [[ "$x" == "" ]]
111+
then
112+
# Some steps rely on the presence or otherwise of the Dispatch-Trailer.
113+
# We know that we don't have a Dispatch-Trailer in this situation,
114+
# hence we use the JSON value null in order to represent that state.
115+
# This means that GitHub expressions can determine whether a Dispatch-Trailer
116+
# is present or not by checking whether the fromJSON() result of the
117+
# output from this step is the JSON value null or not.
118+
x=null
119+
fi
120+
echo "\(_dispatchTrailerDecodeStepOutputVar)<<EOD" >> $GITHUB_OUTPUT
121+
echo "$x" >> $GITHUB_OUTPUT
122+
echo "EOD" >> $GITHUB_OUTPUT
123+
"""
124+
},
132125

133-
// Safety nets to flag if we ever have a Dispatch-Trailer slip through the
134-
// net and make it to master
135-
githubactions.#Step & {
136-
name: "Check we don't have \(dispatchTrailer) on a protected branch"
137-
if: "\(isProtectedBranch) && \(containsDispatchTrailer)"
138-
run: """
139-
echo "\(_dispatchTrailerVariable) contains \(dispatchTrailer) but we are on a protected branch"
140-
false
141-
"""
142-
},
143-
]
144-
}
126+
// Safety nets to flag if we ever have a Dispatch-Trailer slip through the
127+
// net and make it to master
128+
{
129+
name: "Check we don't have \(dispatchTrailer) on a protected branch"
130+
if: "\(isProtectedBranch) && \(containsDispatchTrailer)"
131+
run: """
132+
echo "\(_dispatchTrailerVariable) contains \(dispatchTrailer) but we are on a protected branch"
133+
false
134+
"""
135+
},
136+
]
145137

146138
earlyChecks: githubactions.#Step & {
147139
name: "Early git and code sanity checks"

internal/ci/github/release.cue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package github
1616

1717
import (
1818
"list"
19-
"cue.dev/x/githubactions"
2019
)
2120

2221
// _cueVersionRef is a workflow job-runtime expression that evaluates to the
@@ -49,15 +48,15 @@ workflows: release: _repo.bashWorkflow & {
4948
steps: [
5049
for v in _repo.checkoutCode {v},
5150
for v in installGo {v},
52-
githubactions.#Step & {
51+
{
5352
name: "Setup qemu"
5453
uses: "docker/setup-qemu-action@v3"
5554
},
56-
githubactions.#Step & {
55+
{
5756
name: "Set up Docker Buildx"
5857
uses: "docker/setup-buildx-action@v3"
5958
},
60-
githubactions.#Step & {
59+
{
6160
name: "Docker Login"
6261
uses: "docker/login-action@v3"
6362
with: {
@@ -69,7 +68,7 @@ workflows: release: _repo.bashWorkflow & {
6968

7069
_repo.loginCentralRegistry,
7170

72-
githubactions.#Step & {
71+
{
7372
name: "Install GoReleaser"
7473
uses: "goreleaser/goreleaser-action@v5"
7574
with: {

internal/ci/github/workflows.cue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// package github declares the workflows for this project.
1616
package github
1717

18+
import "cue.dev/x/githubactions"
19+
1820
// Note: the name of the workflows (and hence the corresponding .yaml filenames)
1921
// correspond to the environment variable names for gerritstatusupdater.
2022
// Therefore, this filename must only be change in combination with also
@@ -34,10 +36,7 @@ package github
3436
// We explicitly use close() here instead of a definition in order that we can
3537
// cue export the github package as a test.
3638
workflows: close({
37-
// Adding this constraint here, whilst clear for the reader,
38-
// blows out evaluation time. This will be fixed as part of
39-
// the performance work which is covered under various issues.
40-
// [string]: json.#Workflow
39+
[string]: githubactions.#Workflow
4140

4241
_repo.trybotWorkflows
4342

0 commit comments

Comments
 (0)