github.com/solo-io/cue@v0.4.7/internal/ci/ci_tool.cue (about) 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 20 "encoding/yaml" 21 22 "tool/exec" 23 "tool/file" 24 "tool/os" 25 ) 26 27 // genworkflows regenerates the GitHub workflow Yaml definitions. 28 // 29 // See internal/ci/gen.go for details on how this step fits into the sequence 30 // of generating our CI workflow definitions, and updating various txtar tests 31 // with files from that process. 32 // 33 // Until we have a resolution for cuelang.org/issue/704 and 34 // cuelang.org/issue/708 this must be run from the internal/ci package. At 35 // which point we can switch to using _#modroot. 36 // 37 // This also explains why the ../../ relative path specification below appear 38 // wrong in the context of the containing directory internal/ci/vendor. 39 command: genworkflows: { 40 goos: _#goos 41 42 for w in workflows { 43 "\(w.file)": file.Create & { 44 _dir: path.FromSlash("../../.github/workflows", path.Unix) 45 filename: path.Join([_dir, w.file], goos.GOOS) 46 contents: """ 47 # Generated by internal/ci/ci_tool.cue; do not edit 48 49 \(yaml.Marshal(w.schema)) 50 """ 51 } 52 } 53 } 54 55 // updateTxtarTests ensures certain txtar tests are updated with the 56 // relevant files that make up the process of generating our CI 57 // workflows. 58 // 59 // See internal/ci/gen.go for details on how this step fits into the sequence 60 // of generating our CI workflow definitions, and updating various txtar tests 61 // with files from that process. 62 // 63 // Until we have a resolution for cuelang.org/issue/704 and 64 // cuelang.org/issue/708 this must be run from the internal/ci package. At 65 // which point we can switch to using _#modroot. 66 // 67 // This also explains why the ../../ relative path specification below appear 68 // wrong in the context of the containing directory internal/ci/vendor. 69 command: updateTxtarTests: { 70 goos: _#goos 71 72 readJSONSchema: file.Read & { 73 _path: path.FromSlash("../../cue.mod/pkg/github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue", path.Unix) 74 filename: path.Join([_path], goos.GOOS) 75 contents: string 76 } 77 cueDefInternalCI: exec.Run & { 78 cmd: "go run cuelang.org/go/cmd/cue def cuelang.org/go/internal/ci" 79 stdout: string 80 } 81 // updateEvalTxtarTest updates the cue/testdata/eval testscript which exercises 82 // the evaluation of the workflows defined in internal/ci (which by definition 83 // means resolving and using the vendored GitHub Workflow schema) 84 updateEvalTxtarTest: { 85 _relpath: path.FromSlash("../../cue/testdata/eval/github.txtar", path.Unix) 86 _path: path.Join([_relpath], goos.GOOS) 87 88 githubSchema: exec.Run & { 89 stdin: readJSONSchema.contents 90 cmd: "go run cuelang.org/go/internal/ci/updatetxtar - \(_path) cue.mod/pkg/github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue" 91 } 92 defWorkflows: exec.Run & { 93 $after: githubSchema 94 stdin: cueDefInternalCI.stdout 95 cmd: "go run cuelang.org/go/internal/ci/updatetxtar - \(_path) workflows.cue" 96 } 97 } 98 // When we have a solution for cuelang.org/issue/709 we can make this a 99 // file.Glob. Ultimately it would be better to be able to do a cue def 100 // on the tool "package" 101 readToolsFile: file.Read & { 102 filename: "ci_tool.cue" 103 contents: string 104 } 105 updateCmdCueCmdTxtarTest: { 106 _relpath: path.FromSlash("../../cmd/cue/cmd/testdata/script/cmd_github.txt", path.Unix) 107 _path: path.Join([_relpath], goos.GOOS) 108 109 githubSchema: exec.Run & { 110 stdin: readJSONSchema.contents 111 cmd: "go run cuelang.org/go/internal/ci/updatetxtar - \(_path) cue.mod/pkg/github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue" 112 } 113 defWorkflows: exec.Run & { 114 $after: githubSchema 115 stdin: cueDefInternalCI.stdout 116 cmd: "go run cuelang.org/go/internal/ci/updatetxtar - \(_path) internal/ci/workflows.cue" 117 } 118 toolsFile: exec.Run & { 119 stdin: readToolsFile.contents 120 cmd: "go run cuelang.org/go/internal/ci/updatetxtar - \(_path) internal/ci/\(readToolsFile.filename)" 121 } 122 } 123 } 124 125 // _#modroot is a common helper to get the module root 126 // 127 // TODO: use once we have a solution to cuelang.org/issue/704. 128 // This will then allow us to remove the use of .. below. 129 _#modroot: exec.Run & { 130 cmd: "go list -m -f {{.Dir}}" 131 stdout: string 132 } 133 134 // Until we have the ability to inject contextual information 135 // we need to pass in GOOS explicitly. Either by environment 136 // variable (which we get for free when this is used via go generate) 137 // or via a tag in the case you want to manually run the CUE 138 // command. 139 _#goos: os.Getenv & { 140 GOOS: *path.Unix | string @tag(os) 141 }