| // Copyright 2021 The CUE Authors |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package ci |
| |
| import ( |
| "encoding/yaml" |
| "path" |
| |
| "tool/exec" |
| "tool/file" |
| "tool/os" |
| ) |
| |
| // _#modroot is a common helper to get the module root |
| // |
| // TODO: use once we have a solution to cuelang.org/issue/704. |
| // This will then allow us to remove the use of .. below. |
| _#modroot: exec.Run & { |
| cmd: "go list -m -f {{.Dir}}" |
| stdout: string |
| } |
| |
| // Until we have the ability to inject contextual information |
| // we need to pass in GOOS explicitly. Either by environment |
| // variable (which we get for free when this is used via go generate) |
| // or via a tag in the case you want to manually run the CUE |
| // command. |
| _#goos: os.Getenv & { |
| GOOS: *"unix" | string @tag(os) |
| } |
| |
| // genworkflows regenerates the GitHub workflow Yaml definitions |
| // |
| // Until we have a resolution for cuelang.org/issue/704 this must be |
| // run from the internal/ci package. At which point we can switch to using |
| // _#modroot and move the associated go:generate directive into |
| // internal/ci alongside this command definition. |
| command: genworkflows: task: { |
| goos: _#goos |
| for w in workflows { |
| "\(w.file)": file.Create & { |
| _dir: path.FromSlash("../../.github/workflows", "unix") |
| filename: path.Join([_dir, w.file], goos.GOOS) |
| contents: """ |
| # Generated by internal/ci/ci_tool.cue; do not edit |
| |
| \(yaml.Marshal(w.schema)) |
| """ |
| } |
| } |
| } |