| 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 vendor |
| 16 |
|
| 17 |
import ( |
| 18 |
"path" |
| 19 |
|
| 20 |
"tool/exec" |
| 21 |
"tool/http" |
| 22 |
) |
| 23 |
|
| 24 |
// _cueCmd defines the command that is run to run cmd/cue. |
| 25 |
// This is factored out in order that the cue-github-actions |
| 26 |
// project which "vendors" the various workflow-related |
| 27 |
// packages can specify "cue" as the value so that unity |
| 28 |
// tests can specify the cmd/cue binary to use. |
| 29 |
_cueCmd: string | *"go run cuelang.org/go/cmd/[email protected]" @tag(cue_cmd) |
| 30 |
|
| 31 |
// For the commands below, note we use simple yet hacky path resolution, rather |
| 32 |
// than anything that might derive the module root using go list or similar, in |
| 33 |
// order that we have zero dependencies. |
| 34 |
|
| 35 |
// importjsonschema vendors a CUE-imported version of the JSONSchema that |
| 36 |
// defines GitHub workflows into the main module's cue.mod/pkg. |
| 37 |
command: importjsonschema: { |
| 38 |
getJSONSchema: http.Get & { |
| 39 |
request: body: "" |
| 40 |
|
| 41 |
// Tip link for humans: |
| 42 |
// https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json |
| 43 |
url: "https://raw.githubusercontent.com/SchemaStore/schemastore/88d26ad0d451cbd5ebc70218062850aa905bdf18/src/schemas/json/github-workflow.json" |
| 44 |
} |
| 45 |
import: exec.Run & { |
| 46 |
_outpath: path.FromSlash("./cue.mod/pkg/github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue", "unix") |
| 47 |
stdin: getJSONSchema.response.body |
| 48 |
cmd: "\(_cueCmd) import -f -p json -l #Workflow: -o \(_outpath) jsonschema: -" |
| 49 |
} |
| 50 |
} |