Skip to content

Commit 649bb67

Browse files
committed
internal/ci: make the writing of files reusable
This moves the code around, so that ci_tool.cue becomes a thin wrapper. We will add more useful reusable bits to write.cue soon. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I18df6a99c483fbd3f8877770b0ffd8a7aeab853b Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1219413 Reviewed-by: Paul Jolly <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 92d4bab commit 649bb67

File tree

9 files changed

+82
-54
lines changed

9 files changed

+82
-54
lines changed

.github/workflows/push_tip_to_trybot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
1+
# Code generated internal/ci/base/write.cue; DO NOT EDIT.
22

33
concurrency: push_tip_to_trybot
44
jobs:

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
1+
# Code generated internal/ci/base/write.cue; DO NOT EDIT.
22

33
name: Release
44
concurrency: release

.github/workflows/tip_triggers.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
1+
# Code generated internal/ci/base/write.cue; DO NOT EDIT.
22

33
name: Triggers on push to tip
44
"on":

.github/workflows/trybot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
1+
# Code generated internal/ci/base/write.cue; DO NOT EDIT.
22

33
name: TryBot
44
"on":

.github/workflows/trybot_dispatch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
1+
# Code generated internal/ci/base/write.cue; DO NOT EDIT.
22

33
name: Dispatch trybot
44
"on":

codereview.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
1+
# Code generated internal/ci/base/write.cue; DO NOT EDIT.
22

33
cue-unity: https://github.com/cue-unity/unity-private
44
github: https://github.com/cue-lang/cue

internal/ci/base/base.cue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ codeReview: #codeReview & {
107107
// crucial. As such, we assert specific values for the keys here rather than
108108
// just deriving values from the human-readable names.
109109
//
110-
// trybot.name is by the trybot GitHub workflow and by gerritstatusupdater as
110+
// trybot.name is used by the trybot GitHub workflow and by gerritstatusupdater as
111111
// an identifier in the status updates that are posted as reviews for this
112112
// workflows, but also as the result label key, e.g. "TryBot-Result" would be
113113
// the result label key for the "TryBot" workflow. This name also shows up in

internal/ci/base/write.cue

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2021 The CUE Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package base
16+
17+
import (
18+
"path"
19+
"encoding/yaml"
20+
"tool/file"
21+
22+
"cue.dev/x/githubactions"
23+
)
24+
25+
// For the commands below, note we use simple yet hacky path resolution, rather
26+
// than anything that might derive the module root using go list or similar, in
27+
// order that we have zero dependencies. This is important because this CUE
28+
// package is "vendored" to an external dependency so that that unity can
29+
// re-run and verify these steps as part of the test suite that runs against
30+
// new CUE versions.
31+
32+
// TODO(mvdan): without the default, this doesn't seem to be filled by
33+
// `cue cmd gen` in internal/ci, even though the command defaults --inject-vars to true.
34+
// Perhaps it doesn't work for imported packages? It seems to me like it should.
35+
_goos: string | *path.Unix @tag(os,var=os)
36+
37+
// writeWorkflows regenerates the GitHub workflow YAML definitions.
38+
writeWorkflows: {
39+
#in: {
40+
workflows: [string]: githubactions.#Workflow
41+
}
42+
_dir: path.FromSlash("../../.github/workflows", path.Unix)
43+
44+
remove: {
45+
glob: file.Glob & {
46+
glob: path.Join([_dir, "*" + workflowFileExtension], _goos)
47+
files: [...string]
48+
}
49+
for _, _filename in glob.files {
50+
"delete \(_filename)": file.RemoveAll & {
51+
path: _filename
52+
}
53+
}
54+
}
55+
for _workflowName, _workflow in #in.workflows {
56+
let _filename = _workflowName + workflowFileExtension
57+
"generate \(_filename)": file.Create & {
58+
$after: [for v in remove {v}]
59+
filename: path.Join([_dir, _filename], _goos)
60+
let donotedit = doNotEditMessage & {#generatedBy: "internal/ci/base/write.cue", _}
61+
contents: "# \(donotedit)\n\n\(yaml.Marshal(_workflow))"
62+
}
63+
}
64+
}
65+
66+
writeCodereviewCfg: file.Create & {
67+
_dir: path.FromSlash("../../", path.Unix)
68+
filename: path.Join([_dir, "codereview.cfg"], _goos)
69+
let res = toCodeReviewCfg & {#input: codeReview, _}
70+
let donotedit = doNotEditMessage & {#generatedBy: "internal/ci/base/write.cue", _}
71+
contents: "# \(donotedit)\n\n\(res)\n"
72+
}

internal/ci/ci_tool.cue

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,16 @@
1515
package ci
1616

1717
import (
18-
"path"
19-
"encoding/yaml"
20-
"tool/file"
21-
22-
"github.com/cue-lang/tmp/internal/ci/base"
2318
"github.com/cue-lang/tmp/internal/ci/repo"
2419
"github.com/cue-lang/tmp/internal/ci/github"
2520
)
2621

27-
// For the commands below, note we use simple yet hacky path resolution, rather
28-
// than anything that might derive the module root using go list or similar, in
29-
// order that we have zero dependencies. This is important because this CUE
30-
// package is "vendored" to an external dependency so that that unity can
31-
// re-run and verify these steps as part of the test suite that runs against
32-
// new CUE versions.
33-
34-
_goos: string @tag(os,var=os)
35-
36-
// gen.workflows regenerates the GitHub workflow Yaml definitions.
37-
//
3822
// See internal/ci/gen.go for details on how this step fits into the sequence
3923
// of generating our CI workflow definitions, and updating various txtar tests
4024
// with files from that process.
41-
command: gen: {
42-
_dir: path.FromSlash("../../.github/workflows", path.Unix)
4325

44-
workflows: {
45-
remove: {
46-
glob: file.Glob & {
47-
glob: path.Join([_dir, "*" + base.workflowFileExtension], _goos)
48-
files: [...string]
49-
}
50-
for _, _filename in glob.files {
51-
"delete \(_filename)": file.RemoveAll & {
52-
path: _filename
53-
}
54-
}
55-
}
56-
for _workflowName, _workflow in github.workflows {
57-
let _filename = _workflowName + repo.workflowFileExtension
58-
"generate \(_filename)": file.Create & {
59-
$after: [for v in remove {v}]
60-
filename: path.Join([_dir, _filename], _goos)
61-
let donotedit = repo.doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _}
62-
contents: "# \(donotedit)\n\n\(yaml.Marshal(_workflow))"
63-
}
64-
}
65-
}
66-
}
26+
command: gen: {
27+
workflows: repo.writeWorkflows & {#in: workflows: github.workflows}
6728

68-
command: gen: codereviewcfg: file.Create & {
69-
_dir: path.FromSlash("../../", path.Unix)
70-
filename: path.Join([_dir, "codereview.cfg"], _goos)
71-
let res = repo.toCodeReviewCfg & {#input: repo.codeReview, _}
72-
let donotedit = repo.doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _}
73-
contents: "# \(donotedit)\n\n\(res)\n"
29+
codereviewCfg: repo.writeCodereviewCfg
7430
}

0 commit comments

Comments
 (0)