Skip to content

Commit fce83a6

Browse files
committed
internal/ci: update to the latest base from cue-lang/cue
This brings this repo inline with the latest internal/ci/base package in the cue-lang/cue repo in https://cuelang.org/cl/1196926. Signed-off-by: Paul Jolly <[email protected]> Change-Id: I62eaf47f03dd0778d11555153c42d805692ed7a1 Reviewed-on: https://review.gerrithub.io/c/cue-lang/proposal/+/1196929 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent fe257d4 commit fce83a6

File tree

6 files changed

+74
-130
lines changed

6 files changed

+74
-130
lines changed

.github/workflows/evict_caches.yml

+2-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
shell: bash
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717
with:
1818
ref: ${{ github.event.pull_request.head.sha }}
1919
fetch-depth: 0
@@ -44,16 +44,7 @@ jobs:
4444
Dispatch-Trailer: {"type":"'))
4545
name: Check we don't have Dispatch-Trailer on a protected branch
4646
run: |-
47-
echo "github.event.head_commit.message contains Dispatch-Trailer"
48-
echo "github.event.head_commit.message value"
49-
cat <<EOD
50-
${{ github.event.head_commit.message }}
51-
EOD
52-
echo "containsDispatchTrailer expression"
53-
cat <<EOD
54-
(contains(github.event.head_commit.message, '
55-
Dispatch-Trailer: {"type":"'))
56-
EOD
47+
echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch"
5748
false
5849
- name: Delete caches
5950
run: |-

.github/workflows/trybot.yml

+32-56
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
Dispatch-Trailer: {"type":"'))
2121
steps:
2222
- name: Checkout code
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2424
with:
2525
ref: ${{ github.event.pull_request.head.sha }}
2626
fetch-depth: 0
@@ -51,19 +51,10 @@ jobs:
5151
Dispatch-Trailer: {"type":"'))
5252
name: Check we don't have Dispatch-Trailer on a protected branch
5353
run: |-
54-
echo "github.event.head_commit.message contains Dispatch-Trailer"
55-
echo "github.event.head_commit.message value"
56-
cat <<EOD
57-
${{ github.event.head_commit.message }}
58-
EOD
59-
echo "containsDispatchTrailer expression"
60-
cat <<EOD
61-
(contains(github.event.head_commit.message, '
62-
Dispatch-Trailer: {"type":"'))
63-
EOD
54+
echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch"
6455
false
6556
- name: Install Go
66-
uses: actions/setup-go@v4
57+
uses: actions/setup-go@v5
6758
with:
6859
cache: false
6960
go-version: 1.20.x
@@ -76,7 +67,7 @@ jobs:
7667
- if: |-
7768
(((github.ref == 'refs/heads/main') && (! (contains(github.event.head_commit.message, '
7869
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test'))
79-
uses: actions/cache@v3
70+
uses: actions/cache@v4
8071
with:
8172
path: |-
8273
${{ steps.go-mod-cache-dir.outputs.dir }}/cache/download
@@ -86,7 +77,7 @@ jobs:
8677
- if: |-
8778
! (((github.ref == 'refs/heads/main') && (! (contains(github.event.head_commit.message, '
8879
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test'))
89-
uses: actions/cache/restore@v3
80+
uses: actions/cache/restore@v4
9081
with:
9182
path: |-
9283
${{ steps.go-mod-cache-dir.outputs.dir }}/cache/download
@@ -99,20 +90,6 @@ jobs:
9990
run: go clean -testcache
10091
- name: Early git and code sanity checks
10192
run: |-
102-
# Ensure the recent commit messages have Signed-off-by headers. We
103-
# only need to check the HEAD commit because all commits are tested
104-
# in CI. Unclear why git log outputs blank lines when parsing trailers
105-
# in this way, but we remove those blank lines so as not to skew the
106-
# count of the trailers we are searching for.
107-
#
108-
# TODO: Remove once this is enforced for admins too;
109-
# see https://bugs.chromium.org/p/gerrit/issues/detail?id=15229
110-
if [[ "$(git log -1 --pretty='%(trailers:key=Signed-off-by)' | sed '/^\s*$/d' | wc -l)" -eq 0 ]]; then
111-
echo -e "\nRecent commit is lacking Signed-off-by:\n"
112-
git show --quiet
113-
exit 1
114-
fi
115-
11693
# Ensure that commit messages have a blank second line.
11794
# We know that a commit message must be longer than a single
11895
# line because each commit must be signed-off.
@@ -121,34 +98,32 @@ jobs:
12198
exit 1
12299
fi
123100
124-
# Ensure that the commit author is the same as the signed-off-by. This
125-
# is a basic requirement of DCO. It is enforced by Gerrit (although
126-
# noting that in Gerrit the author name does not have to match, only
127-
# the email address), but _not_ by the DCO GitHub app:
101+
# All authors, including co-authors, must have a signed-off trailer by email.
102+
# Note that trailers are in the form "Name <email>", so grab the email with sed.
103+
# For now, we require the sorted lists of author and signer emails to match.
104+
# Note that this also fails if a commit isn't signed-off at all.
128105
#
129-
# https://github.com/dcoapp/app/issues/201
130-
#
131-
# Provide a sanity check as part of GitHub workflows that should enforce
132-
# this, e.g. trybot workflows.
133-
#
134-
# We do so by comparing the commit author and "Signed-off-by" trailer for
135-
# strict equality. Whilst this is more strict than Gerrit, it should
136-
# generally be the case, and we can always relax this when presented with
137-
# specific situations where it is is a problem.
138-
139-
# commit author email address
140-
commitauthor="$(git log -1 --pretty="%ae")"
141-
142-
# signed-off-by trailer email address. There is no way to parse just the
143-
# email address from the trailer in the same way as git log, so instead
144-
# grab the relevant trailer and then take the last whitespace-delimited
145-
# part as the "<>" contained email address.
146-
# Getting the Signed-off-by trailer in this way causes blank
147-
# lines for some reason. Use awk to remove them.
148-
commitsigner="$(git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p')"
149-
150-
if [[ "$commitauthor" != "$commitsigner" ]]; then
151-
echo "commit author email address does not match signed-off-by trailer"
106+
# In Gerrit we already enable a form of this via https://gerrit-review.googlesource.com/Documentation/project-configuration.html#require-signed-off-by,
107+
# but it does not support co-authors nor can it be used when testing GitHub PRs.
108+
commit_authors="$(
109+
{
110+
git log -1 --pretty='%ae'
111+
git log -1 --pretty='%(trailers:key=Co-authored-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
112+
} | sort -u
113+
)"
114+
commit_signers="$(
115+
{
116+
git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
117+
} | sort -u
118+
)"
119+
if [[ "${commit_authors}" != "${commit_signers}" ]]; then
120+
echo "Error: commit author email addresses do not match signed-off-by trailers"
121+
echo
122+
echo "Authors:"
123+
echo "${commit_authors}"
124+
echo
125+
echo "Signers:"
126+
echo "${commit_signers}"
152127
exit 1
153128
fi
154129
- name: Generate
@@ -157,5 +132,6 @@ jobs:
157132
run: go test ./...
158133
- name: Check
159134
run: go vet ./...
160-
- name: Check that git is clean at the end of the job
135+
- if: always()
136+
name: Check that git is clean at the end of the job
161137
run: test -z "$(git status --porcelain)" || (git status; git diff; false)

internal/ci/base/base.cue

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ gerritHubRepositoryURL: *("https://\(gerritHubHostname)/a/" + githubRepositoryPa
4242
trybotRepositoryPath: *(githubRepositoryPath + "-" + trybot.key) | string
4343
trybotRepositoryURL: *("https://github.com/" + trybotRepositoryPath) | string
4444

45-
defaultBranch: *"master" | string
46-
testDefaultBranch: *"ci/test" | _
45+
defaultBranch: *"master" | string
46+
testDefaultBranch: *"ci/test" | _
4747
protectedBranchPatterns: *[defaultBranch] | [...string]
48-
releaseTagPrefix: *"v" | string
49-
releaseTagPattern: *(releaseTagPrefix + "*") | string
48+
releaseTagPrefix: *"v" | string
49+
releaseTagPattern: *(releaseTagPrefix + "*") | string
5050

5151
botGitHubUser: string
5252
botGitHubUserTokenSecretsKey: *(strings.ToUpper(botGitHubUser) + "_GITHUB_PAT") | string

internal/ci/base/codereview.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// the key: value
2222
toCodeReviewCfg: {
2323
#input: #codeReview
24-
let parts = [ for k, v in #input {k + ": " + v}]
24+
let parts = [for k, v in #input {k + ": " + v}]
2525

2626
// Per https://pkg.go.dev/golang.org/x/review/git-codereview#hdr-Configuration
2727
strings.Join(parts, "\n")

internal/ci/base/gerrithub.cue

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ trybotDispatchWorkflow: bashWorkflow & {
4545
(trybot.key): {
4646
"runs-on": linuxMachine
4747

48-
let goodDummyData = [ if encjson.Marshal(#dummyDispatch) != _|_ {true}, false][0]
48+
let goodDummyData = [if encjson.Marshal(#dummyDispatch) != _|_ {true}, false][0]
4949

5050
// We set the "on" conditions above, but this would otherwise mean we
5151
// run for all dispatch events.

internal/ci/base/github.cue

+34-57
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bashWorkflow: json.#Workflow & {
1717

1818
installGo: json.#step & {
1919
name: "Install Go"
20-
uses: "actions/setup-go@v4"
20+
uses: "actions/setup-go@v5"
2121
with: {
2222
// We do our own caching in setupGoActionsCaches.
2323
cache: false
@@ -28,7 +28,7 @@ installGo: json.#step & {
2828
checkoutCode: {
2929
#actionsCheckout: json.#step & {
3030
name: "Checkout code"
31-
uses: "actions/checkout@v3"
31+
uses: "actions/checkout@v4"
3232

3333
// "pull_request" builds will by default use a merge commit,
3434
// testing the PR's HEAD merged on top of the master branch.
@@ -91,15 +91,7 @@ checkoutCode: {
9191
name: "Check we don't have \(dispatchTrailer) on a protected branch"
9292
if: "\(isProtectedBranch) && \(containsDispatchTrailer)"
9393
run: """
94-
echo "\(_dispatchTrailerVariable) contains \(dispatchTrailer)"
95-
echo "\(_dispatchTrailerVariable) value"
96-
cat <<EOD
97-
${{ \(_dispatchTrailerVariable) }}
98-
EOD
99-
echo "containsDispatchTrailer expression"
100-
cat <<EOD
101-
\(containsDispatchTrailer)
102-
EOD
94+
echo "\(_dispatchTrailerVariable) contains \(dispatchTrailer) but we are on a protected branch"
10395
false
10496
"""
10597
},
@@ -109,20 +101,6 @@ checkoutCode: {
109101
earlyChecks: json.#step & {
110102
name: "Early git and code sanity checks"
111103
run: #"""
112-
# Ensure the recent commit messages have Signed-off-by headers. We
113-
# only need to check the HEAD commit because all commits are tested
114-
# in CI. Unclear why git log outputs blank lines when parsing trailers
115-
# in this way, but we remove those blank lines so as not to skew the
116-
# count of the trailers we are searching for.
117-
#
118-
# TODO: Remove once this is enforced for admins too;
119-
# see https://bugs.chromium.org/p/gerrit/issues/detail?id=15229
120-
if [[ "$(git log -1 --pretty='%(trailers:key=Signed-off-by)' | sed '/^\s*$/d' | wc -l)" -eq 0 ]]; then
121-
echo -e "\nRecent commit is lacking Signed-off-by:\n"
122-
git show --quiet
123-
exit 1
124-
fi
125-
126104
# Ensure that commit messages have a blank second line.
127105
# We know that a commit message must be longer than a single
128106
# line because each commit must be signed-off.
@@ -131,34 +109,32 @@ earlyChecks: json.#step & {
131109
exit 1
132110
fi
133111
134-
# Ensure that the commit author is the same as the signed-off-by. This
135-
# is a basic requirement of DCO. It is enforced by Gerrit (although
136-
# noting that in Gerrit the author name does not have to match, only
137-
# the email address), but _not_ by the DCO GitHub app:
138-
#
139-
# https://github.com/dcoapp/app/issues/201
140-
#
141-
# Provide a sanity check as part of GitHub workflows that should enforce
142-
# this, e.g. trybot workflows.
112+
# All authors, including co-authors, must have a signed-off trailer by email.
113+
# Note that trailers are in the form "Name <email>", so grab the email with sed.
114+
# For now, we require the sorted lists of author and signer emails to match.
115+
# Note that this also fails if a commit isn't signed-off at all.
143116
#
144-
# We do so by comparing the commit author and "Signed-off-by" trailer for
145-
# strict equality. Whilst this is more strict than Gerrit, it should
146-
# generally be the case, and we can always relax this when presented with
147-
# specific situations where it is is a problem.
148-
149-
# commit author email address
150-
commitauthor="$(git log -1 --pretty="%ae")"
151-
152-
# signed-off-by trailer email address. There is no way to parse just the
153-
# email address from the trailer in the same way as git log, so instead
154-
# grab the relevant trailer and then take the last whitespace-delimited
155-
# part as the "<>" contained email address.
156-
# Getting the Signed-off-by trailer in this way causes blank
157-
# lines for some reason. Use awk to remove them.
158-
commitsigner="$(git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p')"
159-
160-
if [[ "$commitauthor" != "$commitsigner" ]]; then
161-
echo "commit author email address does not match signed-off-by trailer"
117+
# In Gerrit we already enable a form of this via https://gerrit-review.googlesource.com/Documentation/project-configuration.html#require-signed-off-by,
118+
# but it does not support co-authors nor can it be used when testing GitHub PRs.
119+
commit_authors="$(
120+
{
121+
git log -1 --pretty='%ae'
122+
git log -1 --pretty='%(trailers:key=Co-authored-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
123+
} | sort -u
124+
)"
125+
commit_signers="$(
126+
{
127+
git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p'
128+
} | sort -u
129+
)"
130+
if [[ "${commit_authors}" != "${commit_signers}" ]]; then
131+
echo "Error: commit author email addresses do not match signed-off-by trailers"
132+
echo
133+
echo "Authors:"
134+
echo "${commit_authors}"
135+
echo
136+
echo "Signers:"
137+
echo "${commit_signers}"
162138
exit 1
163139
fi
164140
"""#
@@ -239,7 +215,7 @@ setupGoActionsCaches: {
239215
if !#readonly {
240216
cacheStep & {
241217
if: readWriteCacheExpr
242-
uses: "actions/cache@v3"
218+
uses: "actions/cache@v4"
243219
}
244220
},
245221

@@ -252,7 +228,7 @@ setupGoActionsCaches: {
252228
if: "! \(readWriteCacheExpr)"
253229
}
254230

255-
uses: "actions/cache/restore@v3"
231+
uses: "actions/cache/restore@v4"
256232
},
257233

258234
if #cleanTestCache {
@@ -278,7 +254,7 @@ setupGoActionsCaches: {
278254
// but array literals are not yet supported in expressions.
279255
isProtectedBranch: {
280256
#trailers: [...string]
281-
"((" + strings.Join([ for branch in protectedBranchPatterns {
257+
"((" + strings.Join([for branch in protectedBranchPatterns {
282258
(_matchPattern & {variable: "github.ref", pattern: "refs/heads/\(branch)"}).expr
283259
}], " || ") + ") && (! \(containsDispatchTrailer)))"
284260
}
@@ -296,6 +272,7 @@ isReleaseTag: {
296272

297273
checkGitClean: json.#step & {
298274
name: "Check that git is clean at the end of the job"
275+
if: "always()"
299276
run: "test -z \"$(git status --porcelain)\" || (git status; git diff; false)"
300277
}
301278

@@ -308,7 +285,7 @@ repositoryDispatch: json.#step & {
308285

309286
name: string
310287
run: #"""
311-
\#(_curlGitHubAPI) -f --request POST --data-binary \#(strconv.Quote(encjson.Marshal(#arg))) https://api.github.com/repos/\#(#githubRepositoryPath)/dispatches
288+
\#(_curlGitHubAPI) --fail --request POST --data-binary \#(strconv.Quote(encjson.Marshal(#arg))) https://api.github.com/repos/\#(#githubRepositoryPath)/dispatches
312289
"""#
313290
}
314291

@@ -354,7 +331,7 @@ containsDispatchTrailer: {
354331
//
355332
// Dispatch-Trailer: {"type:}
356333
//
357-
let _typeCheck = [ if #type != _|_ {#type + "\""}, ""][0]
334+
let _typeCheck = [if #type != _|_ {#type + "\""}, ""][0]
358335
"""
359336
(contains(\(_dispatchTrailerVariable), '\n\(dispatchTrailer): {"type":"\(_typeCheck)'))
360337
"""

0 commit comments

Comments
 (0)