-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: add tests for the GitHub workflow process
Re-running go generate is a step that invariably happens _after_ having verified that tests pass. This is unfortunate in the case of the GitHub workflow schema that is vendored at: github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue because it has been the cause of a number of bugs in the past (in a good way). This change adds the updateTxtarTests command to the internal/ci CUE tool to update three txtar-based tests: * encoding/jsonschema - checking the we can imported the source JSONSchema * internal/core/adt (the eval part) - checking that we can evaluate the workflows defined in internal/ci against the imported schema * cmd/cue/cmd - verifying that we can run the step of generating the yaml workflow definitions from a cue cmd flow definition It's still the case that if you: * change the workflow definitions in internal/ci, or * pin to a later version of the GitHub workflow schema you must run: go generate ./internal/ci to update the generated workflow definitions, but now this will also update the source files in various txtar test archives. If a GitHub-related txtar test fails in such a way that you need to update the golden files in that archive, this indicates you will also need to re-run the go generate ./internal/ci to re-generate the yaml workflow definitions. Change-Id: I310c4f58cfd91965766279d7ad06fee54b7842cb Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8112 Reviewed-by: CUE cueckoo <cueckoo@gmail.com> Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
- Loading branch information
Showing
8 changed files
with
6,043 additions
and
54 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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 main | ||
|
||
import ( | ||
"flag" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/rogpeppe/go-internal/txtar" | ||
) | ||
|
||
// Usage: | ||
// updateTxtar source target filename | ||
// | ||
// updateTxtar writes the contents of source (could be - for stdin) to a file | ||
// (identified by filename) within the txtar archive at target. | ||
|
||
func main() { | ||
log.SetFlags(0) | ||
flag.Parse() | ||
if flag.NArg() != 3 { | ||
log.Fatal("Usage:\n\tupdateTxtar source target filename") | ||
} | ||
source := flag.Arg(0) | ||
target := flag.Arg(1) | ||
fn := flag.Arg(2) | ||
a, err := txtar.ParseFile(target) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
var file *txtar.File | ||
for i, f := range a.Files { | ||
if f.Name == fn { | ||
file = &a.Files[i] | ||
break | ||
} | ||
} | ||
if file == nil { | ||
a.Files = append(a.Files, txtar.File{Name: fn}) | ||
file = &a.Files[len(a.Files)-1] | ||
} | ||
var sourceReader io.Reader | ||
if source == "-" { | ||
sourceReader = os.Stdin | ||
} else { | ||
sourceReader, err = os.Open(source) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
contents, err := ioutil.ReadAll(sourceReader) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
file.Data = contents | ||
if err := ioutil.WriteFile(target, txtar.Format(a), 0666); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters