| 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 ci |
| 16 |
|
| 17 |
import ( |
| 18 |
"path" |
| 19 |
"encoding/yaml" |
| 20 |
"tool/file" |
| 21 |
|
| 22 |
"cuelabs.dev/go/oci/internal/ci/repo" |
| 23 |
"cuelabs.dev/go/oci/internal/ci/github" |
| 24 |
) |
| 25 |
|
| 26 |
// For the commands below, note we use simple yet hacky path resolution, rather |
| 27 |
// than anything that might derive the module root using go list or similar, in |
| 28 |
// order that we have zero dependencies. This is important because this CUE |
| 29 |
// package is "vendored" to an external dependency so that that unity can |
| 30 |
// re-run and verify these steps as part of a the test suite that runs against |
| 31 |
// new CUE versions. |
| 32 |
|
| 33 |
_goos: string @tag(os,var=os) |
| 34 |
|
| 35 |
// gen.workflows regenerates the GitHub workflow Yaml definitions. |
| 36 |
// |
| 37 |
// See internal/ci/gen.go for details on how this step fits into the sequence |
| 38 |
// of generating our CI workflow definitions, and updating various txtar tests |
| 39 |
// with files from that process. |
| 40 |
command: gen: { |
| 41 |
_dir: path.FromSlash("../../.github/workflows", path.Unix) |
| 42 |
|
| 43 |
workflows: { |
| 44 |
remove: { |
| 45 |
glob: file.Glob & { |
| 46 |
glob: path.Join([_dir, "*.yml"], _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 github.workflows { |
| 56 |
let _filename = _workflowName + repo.workflowFileExtension |
| 57 |
"generate \(_filename)": file.Create & { |
| 58 |
$after: [ for v in remove {v}] |
| 59 |
filename: path.Join([_dir, _filename], _goos) |
| 60 |
let donotedit = repo.doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _} |
| 61 |
contents: "# \(donotedit)\n\n\(yaml.Marshal(_workflow))" |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
command: gen: codereviewcfg: file.Create & { |
| 68 |
_dir: path.FromSlash("../../", path.Unix) |
| 69 |
filename: path.Join([_dir, "codereview.cfg"], _goos) |
| 70 |
let res = repo.toCodeReviewCfg & {#input: repo.codeReview, _} |
| 71 |
let donotedit = repo.doNotEditMessage & {#generatedBy: "internal/ci/ci_tool.cue", _} |
| 72 |
contents: "# \(donotedit)\n\n\(res)\n" |
| 73 |
} |