cuelang.org/go@v0.13.0/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  	"encoding/yaml"
    20  	"tool/file"
    21  
    22  	"cuelang.org/go/internal/ci/base"
    23  	"cuelang.org/go/internal/ci/repo"
    24  	"cuelang.org/go/internal/ci/github"
    25  )
    26  
    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  //
    38  // See internal/ci/gen.go for details on how this step fits into the sequence
    39  // of generating our CI workflow definitions, and updating various txtar tests
    40  // with files from that process.
    41  command: gen: {
    42  	_dir: path.FromSlash("../../.github/workflows", path.Unix)
    43  
    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  }
    67  
    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"
    74  }