From 67ba9958f3cc8f9b952b1282ea147cd012508025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Tue, 26 Nov 2024 08:09:14 +0100 Subject: [PATCH 1/3] docs: removed GitHub Action section --- README.md | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index d7d5d7b..d9ec81a 100644 --- a/README.md +++ b/README.md @@ -464,31 +464,9 @@ If you have a go development environment, the installation can also be done with go install github.com/grafana/k6registry/cmd/k6registry@latest ``` -## GitHub Action +## GitHub Workflows -`grafana/k6registry` is a GitHub Action that enables k6 Extension Registry and Catalog generation. - -**Inputs** - -name | reqired | default | description --------|---------|---------|------------- -in | yes | | input file name -out | no | stdout | output file name -api | no | | output directory name -test | no | | api path(s) to test after generation -quiet | no | `false` | no output, only validation -loose | no | `false` | skip JSON schema validation -lint | no | `false` | enable built-in linter -compact| no | `false` | compact instead of pretty-printed output -catalog| no | | generate catalog to the specified file -ref | no | | reference output URL for change detection -origin | no | | external registry URL for default values - -In GitHub action mode, the change can be indicated by comparing the output to a reference output. The reference output URL can be passed in the `ref` action parameter. The `changed` output variable will be `true` or `false` depending on whether the output has changed or not compared to the reference output. - -The `api` parameter can be used to specify a directory into which the outputs are written. The `registry.json` file is placed in the root directory. The `extension.json` file and the `badge.svg` file are placed in a directory with the same name as the go module path of the extension (if the `lint` parameter is `true`). - -The `test` parameter can be used to test registry and catalog files generated with the `api` parameter. The test is successful if the file is not empty, contains `k6` and at least one extension, and if all extensions meet the minimum requirements (e.g. it has versions). +When used in GitHub Workflows, the change can be indicated by comparing the output to a reference output. The reference output URL can be passed in the `--ref` flag. The `changed` output variable will be `true` or `false` depending on whether the output has changed or not compared to the reference output. **Outputs** @@ -496,17 +474,6 @@ name | description --------|------------ changed | `true` if the output has changed compared to `ref`, otherwise `false` -**Example usage** - -```yaml -- name: Generate extension registry - uses: grafana/k6registry@v0.1.18 - with: - in: "registry.yaml" - out: "registry.json" - lint: "true" -``` - ## CLI @@ -541,6 +508,7 @@ k6registry [flags] [source-file] -o, --out string write output to file instead of stdout --api string write outputs to directory instead of stdout --origin string external registry URL for default values + --ref string reference output URL for change detection --test strings test api path(s) (example: /registry.json,/catalog.json) -q, --quiet no output, only validation --loose skip JSON schema validation From a59bac19e6aa851e2929d08e98a4302d7c94d6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Tue, 26 Nov 2024 08:10:17 +0100 Subject: [PATCH 2/3] fix: change detection now called when either --out or --api flag present --- cmd/cmd.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index de9b892..992037b 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -148,10 +148,25 @@ func run(ctx context.Context, args []string, opts *options) (result error) { return err } - return postRun(ctx, registry, output, opts) + if err := postRun(registry, output, opts); err != nil { + return err + } + + if isGitHubAction() { + fname := opts.out + if len(fname) == 0 && len(opts.api) != 0 { + fname = filepath.Join(opts.api, "registry.json") + } + + if len(fname) > 0 && len(opts.ref) > 0 { + return emitOutput(ctx, fname, opts.ref) + } + } + + return nil } -func postRun(ctx context.Context, registry k6registry.Registry, output io.Writer, opts *options) error { +func postRun(registry k6registry.Registry, output io.Writer, opts *options) error { if len(opts.api) != 0 { if err := writeAPI(registry, opts.api); err != nil { return err @@ -166,17 +181,11 @@ func postRun(ctx context.Context, registry k6registry.Registry, output io.Writer } } - if !opts.quiet { - if err := writeOutput(registry, output, opts.compact, false); err != nil { - return err - } + if opts.quiet { + return nil } - if isGitHubAction() && len(opts.out) > 0 && len(opts.ref) > 0 { - return emitOutput(ctx, opts.out, opts.ref) - } - - return nil + return writeOutput(registry, output, opts.compact, false) } //nolint:forbidigo From 42f95110ded56395ac63122bdd306db2e97ac7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Tue, 26 Nov 2024 08:14:10 +0100 Subject: [PATCH 3/3] docs: release notes --- releases/v0.2.1.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releases/v0.2.1.md diff --git a/releases/v0.2.1.md b/releases/v0.2.1.md new file mode 100644 index 0000000..b679e88 --- /dev/null +++ b/releases/v0.2.1.md @@ -0,0 +1,4 @@ +k6registry `v0.2.1` is here 🎉! + +This is a bugfix release. +- There was a bug in the change detection, which made it only work when using the `--out` flag. This has been fixed and now the change detection also works when using the `--api` flag.