Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix registry change detection #119

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 3 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,49 +464,16 @@ 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**

name | description
--------|------------
changed | `true` if the output has changed compared to `ref`, otherwise `false`

**Example usage**

```yaml
- name: Generate extension registry
uses: grafana/[email protected]
with:
in: "registry.yaml"
out: "registry.json"
lint: "true"
```

## CLI

<!-- #region cli -->
Expand Down Expand Up @@ -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
Expand Down
31 changes: 20 additions & 11 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions releases/v0.2.1.md
Original file line number Diff line number Diff line change
@@ -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.
Loading