From fb66c184cbe82e4c062adc7c6d383b09af33cd14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Tue, 23 Jul 2024 16:27:18 +0200 Subject: [PATCH 1/2] refactor: Revising the registry concept Simplification of the registry source of the extension. Adding a processing step to the concept: the source of the registry is optimized for humans, customized JSONs should be generated from the source of the registry for applications. --- .github/dependabot.yml | 14 ++ .github/workflows/lint.yml | 36 +++++ .github/workflows/release.yml | 41 ++++++ .github/workflows/test.yml | 49 +++++++ .gitignore | 2 + .golangci.yml | 133 +++++++++++++++++ .goreleaser.yaml | 39 +++++ CODE_OF_CONDUCT.md | 133 +++++++++++++++++ CONTRIBUTING.md | 134 +++++++++++++++++ README.md | 99 ++++++------- cmd/cmd.go | 29 ++++ cmd/help.md | 3 + cmd/k6registry/error.go | 41 ++++++ cmd/k6registry/main.go | 33 +++++ docs/example.yaml | 23 +++ docs/registry.md | 135 ++++++++++++++++++ docs/registry.schema.json | 130 +++++++++++++++++ .../registry.schema.yaml | 93 ++++++++++-- example.json | 24 ---- go.mod | 12 ++ go.sum | 16 +++ registry.go | 4 - registry.schema.json | 75 ---------- registry_gen.go | 88 +++++++++++- releases/v0.1.1.md | 3 + tools/gendoc/main.go | 12 ++ 26 files changed, 1238 insertions(+), 163 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 .goreleaser.yaml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 cmd/cmd.go create mode 100644 cmd/help.md create mode 100644 cmd/k6registry/error.go create mode 100644 cmd/k6registry/main.go create mode 100644 docs/example.yaml create mode 100644 docs/registry.md create mode 100644 docs/registry.schema.json rename registry.schema.yaml => docs/registry.schema.yaml (50%) delete mode 100644 example.json create mode 100644 go.sum delete mode 100644 registry.schema.json create mode 100644 releases/v0.1.1.md create mode 100644 tools/gendoc/main.go diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..62af309 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + time: "16:00" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + time: "16:00" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..0e7f4e7 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,36 @@ +name: lint + +on: + pull_request: + branches: + - main + workflow_dispatch: + push: + branches: + - main + paths-ignore: + - "docs/**" + - README.md + - "releases/**" + +permissions: + contents: read + +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: "1.22.2" + cache: false + - name: Go linter + uses: golangci/golangci-lint-action@v3 + with: + version: v1.57.2 + args: --timeout=30m + install-mode: binary diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..37c28de --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: release +on: + push: + tags: + - "v*" +permissions: + contents: write + packages: write + +jobs: + release: + runs-on: ubuntu-latest + env: + REGISTRY: ghcr.io + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.22.2" + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: "amd64,arm64" + - name: Login to GitHub packages + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "2.0.1" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..23d3ee2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,49 @@ +name: test + +on: + pull_request: + branches: + - main + workflow_dispatch: + push: + branches: + - main + paths-ignore: + - "docs/**" + - README.md + - "releases/**" + +jobs: + test: + name: Test + strategy: + matrix: + platform: + - ubuntu-latest + - macos-latest + - windows-latest + runs-on: ${{matrix.platform}} + steps: + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: "1.22.2" + - name: Checkout code + uses: actions/checkout@v4 + + - name: Test + run: go test -race -count 1 ./... + + - name: Coverage Test + if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'main' }} + run: go test -count 1 -coverprofile=coverage.txt ./... + - name: Upload Coverage + if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'main' }} + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: grafana/k6exec + + - name: Generate Go Report Card + if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'main' }} + uses: creekorful/goreportcard-action@v1.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8f0730 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/build +/coverage.txt diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b8b20f5 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,133 @@ +# v1.57.2 +# Please don't remove the first line. It uses in CI to determine the golangci version +run: + timeout: 5m + +issues: + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + + # We want to try and improve the comments in the k6 codebase, so individual + # non-golint items from the default exclusion list will gradually be added + # to the exclude-rules below + exclude-use-default: false + + exclude-rules: + # Exclude duplicate code and function length and complexity checking in test + # files (due to common repeats and long functions in test code) + - path: _(test|gen)\.go + linters: + - cyclop + - dupl + - gocognit + - funlen + - lll + - forcetypeassert + - path: js\/modules\/k6\/html\/.*\.go + text: "exported: exported " + linters: + - revive + - path: js\/modules\/k6\/http\/.*_test\.go + linters: + # k6/http module's tests are quite complex because they often have several nested levels. + # The module is in maintainance mode, so we don't intend to port the tests to a parallel version. + - paralleltest + - tparallel + - linters: + - staticcheck # Tracked in https://github.com/grafana/xk6-grpc/issues/14 + text: "The entire proto file grpc/reflection/v1alpha/reflection.proto is marked as deprecated." + - linters: + - forbidigo + text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden' + +linters-settings: + exhaustive: + default-signifies-exhaustive: true + cyclop: + max-complexity: 25 + dupl: + threshold: 150 + goconst: + min-len: 10 + min-occurrences: 4 + funlen: + lines: 80 + statements: 60 + forbidigo: + forbid: + - '^(fmt\\.Print(|f|ln)|print|println)$' + # Forbid everything in os, except os.Signal and os.SyscalError + - '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?' + # Forbid everything in syscall except the uppercase constants + - '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?' + - '^logrus\.Logger$' + +linters: + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - contextcheck + - cyclop + - dogsled + - dupl + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint + - exhaustive + - exportloopref + - forbidigo + - forcetypeassert + - funlen + - gocheckcompilerdirectives + - gochecknoglobals + - gocognit + - goconst + - gocritic + - gofmt + - gofumpt + - goimports + - gomoddirectives + - goprintffuncname + - gosec + - gosimple + - govet + - importas + - ineffassign + - interfacebloat + - lll + - makezero + - misspell + - nakedret + - nestif + - nilerr + - nilnil + - noctx + - nolintlint + - nosprintfhostport + - paralleltest + - prealloc + - predeclared + - promlinter + - revive + - reassign + - rowserrcheck + - sqlclosecheck + - staticcheck + - stylecheck + - tenv + - tparallel + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + fast: false diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..1481bb3 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,39 @@ +project_name: k6registry +version: 2 +before: + hooks: + - go mod tidy +dist: build/dist +builds: + - env: + - CGO_ENABLED=0 + goos: ["darwin", "linux", "windows"] + goarch: ["amd64", "arm64"] + ldflags: + - "-s -w -X main.version={{.Version}} -X main.appname={{.ProjectName}}" + dir: cmd/k6registry +source: + enabled: true + name_template: "{{ .ProjectName }}_{{ .Version }}_source" + +archives: + - id: bundle + format: tar.gz + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt" + +snapshot: + name_template: "{{ incpatch .Version }}-next+{{.ShortCommit}}{{if .IsGitDirty}}.dirty{{else}}{{end}}" + +changelog: + sort: asc + abbrev: -1 + filters: + exclude: + - "^chore:" + - "^docs:" + - "^test:" diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..45d257b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,133 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..62d3200 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,134 @@ +# How to contribute to k6registry + +Thank you for your interest in contributing to **k6registry**! + +Before you begin, make sure to familiarize yourself with the [Code of Conduct](CODE_OF_CONDUCT.md). If you've previously contributed to other open source project, you may recognize it as the classic [Contributor Covenant](https://contributor-covenant.org/). + + +## Prerequisites + +If you have a golang development environment installed, a `go generate` command must be issued after modifying the source files. + +The other option is to install the [cdo] tool and perform the tasks described here. The [cdo] tool can most conveniently be installed using the [eget] tool. + +```bash +eget szkiba/cdo +``` + +The [cdo] tool can then be used to perform the tasks described in the following sections. + +Help about tasks: + +``` +cdo +``` + +[cdo]: (https://github.com/szkiba/cdo) +[eget]: https://github.com/zyedidia/eget + +## tools - Install the required tools + +Contributing will require the use of some tools, which can be installed most easily with a well-configured [eget] tool. + +```bash +eget mikefarah/yq +eget atombender/go-jsonschema +eget szkiba/mdcode +eget golangci/golangci-lint +eget goreleaser/goreleaser +``` + +## schema - Contribute to the JSON schema + +The JSON schema of the registry can be found in the [registry.schema.yaml] file, after modification of which the schema in JSON format ([registry.schema.json]) and the golang data model ([registry_gen.go]) must be regenerated. + +```bash +yq -o=json -P docs/registry.schema.yaml > docs/registry.schema.json +go-jsonschema -p k6registry --only-models -o registry_gen.go docs/registry.schema.yaml +``` + +[registry.schema.json]: docs/registry.schema.json +[registry_gen.go]: registry_gen.go + +## example - Contribute to the example + +The example registry can be found in [example.yaml] file, the documentation ([registry.md], [README.md]) must be updated after modification. + +```bash +mdcode update docs/registry.md +mdcode update README.md +``` + +[example.yaml]: docs/example.yaml +[registry.schema.yaml]: docs/example.schema.yaml +[registry.md]: docs/registry.md +[README.md]: README.md + +## readme - Update README.md + +After changing the CLI tool or example registry, the documentation must be updated in README.md. + +```bash +go run ./tools/gendoc README.md +mdcode update README.md +``` + +### lint - Run the linter + +The `golangci-lint` tool is used for static analysis of the source code. +It is advisable to run it before committing the changes. + +```bash +golangci-lint run +``` + +### test - Run the tests + +```bash +go test -count 1 -race -coverprofile=coverage.txt ./... +``` + +[test]: <#test---run-the-tests> + +### coverage - View the test coverage report + +Requires +: [test] + +```bash +go tool cover -html=coverage.txt +``` + +### build - Build the executable binary + +This is the easiest way to create an executable binary (although the release process uses the `goreleaser` tool to create release versions). + +```bash +go build -ldflags="-w -s" -o build/k6registry ./cmd/k6registry +``` + +[build]: <#build---build-the-executable-binary> + +### snapshot - Creating an executable binary with a snapshot version + +The goreleaser command-line tool is used during the release process. During development, it is advisable to create binaries with the same tool from time to time. + +```bash +rm -f build/k6registry +goreleaser build --snapshot --clean --single-target -o build/k6registry +``` + +[snapshot]: <#snapshot---creating-an-executable-binary-with-a-snapshot-version> + +### clean - Delete the build directory + +```bash +rm -rf build +``` + +## all - Update everything + +The most robust thing is to update everything (both the schema and the example) after modifying the source. + +Requires +: schema, example, readme diff --git a/README.md b/README.md index cebaba6..99e94c5 100644 --- a/README.md +++ b/README.md @@ -1,74 +1,75 @@ -# k6registry +

k6registry

-**Data model for the k6 extension registry** +**Data model and tooling for the k6 extension registry** -This repository contains the [JSON schema](registry.schema.json) of the k6 extension registry and the golang data model generated from it. +This repository contains the [JSON schema](docs/registry.schema.json) of the k6 extension registry and the [`k6registry`](#k6registry) command line tool for registry processing. -## Concept +Check [k6 Extension Registry Concept](docs/registry.md) for information on design considerations. -The k6 extension registry is a JSON file that contains the most important properties of extensions. +**Example registry** -### Registered Properties +```yaml file=docs/example.yaml +- module: github.com/grafana/xk6-dashboard + description: Web-based metrics dashboard for k6 + outputs: + - dashboard + official: true -Only those properties of the extensions are registered, which either cannot be detected automatically, or delegation to the extension is not allowed. +- module: github.com/grafana/xk6-sql + description: Load test SQL Servers + imports: + - k6/x/sql + cloud: true + official: true -Properties that are available using the repository manager API are intentionally not registered. +- module: github.com/grafana/xk6-distruptor + description: Inject faults to test + imports: + - k6/x/distruptor + official: true -The string like properties that are included in the generated Grafana documentation are intentionally not accessed via the API of the repository manager. It is not allowed to inject arbitrary text into the Grafana documentation site without approval. Therefore, these properties are registered (eg `description`) +- module: github.com/szkiba/xk6-faker + description: Generate random fake data + imports: + - k6/x/faker +``` -### Extension Identification +## Install -The primary identifier of an extension is the extension's [go module path](https://go.dev/ref/mod#module-path). +Precompiled binaries can be downloaded and installed from the [Releases](https://github.com/grafana/k6registry/releases) page. -The extension has no `name` property, the module path or part of it can be used as the extension name. For example, using the first two elements of the module path after the host name, the name `grafana/xk6-dashboard` can be formed from the module path `github.com/grafana/xk6-dashboard`. This is typically the repository owner name (`grafana`) and the repository name in the repository manager (`xk6-dashboard`). +If you have a go development environment, the installation can also be done with the following command: -The extension has no URL property, a URL can be created from the module path that refers to the extension within the repository manager. +``` +go install github.com/grafana/k6registry/cmd/k6registry@latest +``` -### JavaScript Modules +## Usage -The JavaScript module names implemented by the extension can be specified in the `imports` property. An extension can register multiple JavaScript module names, so this is an array property. + +## k6registry -### Output Names +k6 extension registry processor -The output names implemented by the extension can be specified in the `outputs` property. An extension can register multiple output names, so this is an array property. +### Synopsis -### Cloud Enabled +Command line k6 extension registry processor. -The `true` value of the `cloud` flag indicates that the extension is also available in the Grafana k6 cloud. +`k6registry` is a command line tool that enables k6 extension registry processing and the generation of customized JSON output for different applications. Processing is based on popular `jq` expressions using an embedded `jq` implementation. -### Officially Supported -The `true` value of the `official` flag indicates that the extension is officially supported by Grafana. +``` +k6registry [flags] +``` -## Example +### Flags -```json file=example.json -{ - "extensions": [ - { - "module": "github.com/grafana/xk6-dashboard", - "description": "Web-based metrics dashboard for k6", - "outputs": ["dashboard"] - }, - { - "module": "github.com/grafana/xk6-sql", - "description": "Load test SQL Servers", - "imports": ["k6/x/sql"] - }, - { - "module": "github.com/grafana/xk6-distruptor", - "description": "Inject faults to test", - "imports": ["k6/x/distruptor"] - }, - { - "module": "github.com/szkiba/xk6-faker", - "description": "Generate random fake data", - "imports": ["k6/x/faker"] - } - ] -} ``` + -h, --help help for k6registry +``` + + -## Development +## Contribure -The source of the schema is contained in the [registry.schema.yaml](registry.schema.yaml) file. This file must be edited if required. The `go generate` command generates the [registry_gen.go](registry_gen.go) and [registry.schema.json](registry.schema.json) files and updates the example code block in the README.md from the [example.json](example.json) file. \ No newline at end of file +If you want to contribute, start by reading [CONTRIBUTING.md](CONTRIBUTING.md). diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100644 index 0000000..8fe9054 --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,29 @@ +// Package cmd contains run cobra command factory function. +package cmd + +import ( + _ "embed" + + "github.com/spf13/cobra" +) + +//go:embed help.md +var help string + +// New creates new cobra command for exec command. +func New() *cobra.Command { + root := &cobra.Command{ + Use: "k6registry", + Short: "k6 extension registry processor", + Long: help, + SilenceUsage: true, + SilenceErrors: true, + DisableAutoGenTag: true, + CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, + RunE: func(cmd *cobra.Command, args []string) error { + return nil + }, + } + + return root +} diff --git a/cmd/help.md b/cmd/help.md new file mode 100644 index 0000000..7743953 --- /dev/null +++ b/cmd/help.md @@ -0,0 +1,3 @@ +Command line k6 extension registry processor. + +`k6registry` is a command line tool that enables k6 extension registry processing and the generation of customized JSON output for different applications. Processing is based on popular `jq` expressions using an embedded `jq` implementation. diff --git a/cmd/k6registry/error.go b/cmd/k6registry/error.go new file mode 100644 index 0000000..00dac75 --- /dev/null +++ b/cmd/k6registry/error.go @@ -0,0 +1,41 @@ +package main + +import ( + "errors" + "os" + + "golang.org/x/term" +) + +type formatableError = interface { + error + Format(width int, color bool) string +} + +func formatError(err error) string { + width, color := formatOptions(int(os.Stderr.Fd())) //nolint:forbidigo + + var perr formatableError + if errors.As(err, &perr) { + return perr.Format(width, color) + } + + return err.Error() +} + +func formatOptions(fd int) (int, bool) { + color := false + width := 0 + + if term.IsTerminal(fd) { + if os.Getenv("NO_COLOR") != "true" { //nolint:forbidigo + color = true + } + + if w, _, err := term.GetSize(fd); err == nil { + width = w + } + } + + return width, color +} diff --git a/cmd/k6registry/main.go b/cmd/k6registry/main.go new file mode 100644 index 0000000..0079bac --- /dev/null +++ b/cmd/k6registry/main.go @@ -0,0 +1,33 @@ +// Package main contains the main function for k6registry CLI tool. +package main + +import ( + "log" + "os" + + "github.com/grafana/k6registry/cmd" + "github.com/spf13/cobra" +) + +var version = "dev" + +func main() { + runCmd(newCmd(os.Args[1:])) //nolint:forbidigo +} + +func newCmd(args []string) *cobra.Command { + cmd := cmd.New() + cmd.Version = version + cmd.SetArgs(args) + + return cmd +} + +func runCmd(cmd *cobra.Command) { + log.SetFlags(0) + log.Writer() + + if err := cmd.Execute(); err != nil { + log.Fatal(formatError(err)) + } +} diff --git a/docs/example.yaml b/docs/example.yaml new file mode 100644 index 0000000..810175c --- /dev/null +++ b/docs/example.yaml @@ -0,0 +1,23 @@ +- module: github.com/grafana/xk6-dashboard + description: Web-based metrics dashboard for k6 + outputs: + - dashboard + official: true + +- module: github.com/grafana/xk6-sql + description: Load test SQL Servers + imports: + - k6/x/sql + cloud: true + official: true + +- module: github.com/grafana/xk6-distruptor + description: Inject faults to test + imports: + - k6/x/distruptor + official: true + +- module: github.com/szkiba/xk6-faker + description: Generate random fake data + imports: + - k6/x/faker diff --git a/docs/registry.md b/docs/registry.md new file mode 100644 index 0000000..fae9afe --- /dev/null +++ b/docs/registry.md @@ -0,0 +1,135 @@ +# k6 Extension Registry Concept + +## Registry Source + +The k6 extension registry source is a YAML file that contains the most important properties of extensions. + +### File format + +The k6 extension registry format is YAML, because the registry is edited by humans and the YAML format is more human-friendly than JSON. The files generated from the registry are typically in JSON format, because they are processed by programs and JSON is more widely supported than YAML. A JSON format is also generated from the entire registry, so that it can also be processed by programs. + +### Registered Properties + +Only those properties of the extensions are registered, which either cannot be detected automatically, or delegation to the extension is not allowed. + +Properties that are available using the repository manager API (GitHub API, GitLab API, etc) are intentionally not registered. For example, the number of stars can be queried via the repository manager API, so this property is not registered. + +Exceptions are the string-like properties that are embedded in the Grafana documentation. These properties are registered because it is not allowed to inject arbitrary text into the Grafana documentation site without approval. Therefore, these properties are registered (eg `description`) + +The properties provided by the repository managers ([Repository Metadata]) are queried during registry processing and can be used to produce the output properties. + +### Extension Identification + +The primary identifier of an extension is the extension's [go module path]. + +The extension does not have a `name` property, the [repository metadata] can be used to construct a `name` property. Using the repository owner and the repository name, for example, `grafana/xk6-dashboard` can be generated for the `github.com/grafana/xk6-dashboard` extension. + +The extension does not have a `url` property, but there is a `url` property in the [repository metadata]. + +[go module path]: https://go.dev/ref/mod#module-path +[Repository Metadata]: #repository-metadata + +### JavaScript Modules + +The JavaScript module names implemented by the extension can be specified in the `imports` property. An extension can register multiple JavaScript module names, so this is an array property. + +### Output Names + +The output names implemented by the extension can be specified in the `outputs` property. An extension can register multiple output names, so this is an array property. + +### Cloud + +The `true` value of the `cloud` flag indicates that the extension is also available in the Grafana k6 cloud. The use of certain extensions is not supported in a cloud environment. There may be a technological reason for this, or the extension's functionality is meaningless in the cloud. + +### Official + +The `true` value of the `official` flag indicates that the extension is officially supported by Grafana. Extensions owned by the `grafana` GitHub organization are not officially supported by Grafana by default. There are several k6 extensions owned by the `grafana` GitHub organization, which were created for experimental or example purposes only. The `official` flag is needed so that officially supported extensions can be distinguished from them. + +### Example registry + +```yaml file=example.yaml +- module: github.com/grafana/xk6-dashboard + description: Web-based metrics dashboard for k6 + outputs: + - dashboard + official: true + +- module: github.com/grafana/xk6-sql + description: Load test SQL Servers + imports: + - k6/x/sql + cloud: true + official: true + +- module: github.com/grafana/xk6-distruptor + description: Inject faults to test + imports: + - k6/x/distruptor + official: true + +- module: github.com/szkiba/xk6-faker + description: Generate random fake data + imports: + - k6/x/faker +``` + +### Repository Metadata + +Repository metadata provided by the extension's git repository manager. Repository metadata are not registered, they are queried at processing time using the repository manager API. + +#### URL + +The `url` property contains the URL of the repository. The `url` is provided by the repository manager and can be displayed in a browser. + +#### Homepage + +The `homepage` property contains the the project homepage URL. If no homepage is set, the value is the same as the `url` property. + +#### Stars + +The `stars` property contains the number of stars in the extension's repository. The extension's popularity is indicated by how many users have starred the extension's repository. + +#### Topics + +The `topics` property contains the repository topics. Topics make it easier to find the repository. It is recommended to set the `xk6` topic to the extensions repository. + +#### Tags + +The `tags` property contains the repository's git tags. States of the git repository marked with tags can be reproduced. Versions are also tags, they must meet certain format requirements. + +#### Versions + +The `versions` property contains the list of supported versions. Versions are tags whose format meets the requirements of semantic versioning. Version tags often start with the letter `v`, which is not part of the semantic version. + +## Registry Processing + +The source of the registry is a YAML file optimized for human use. For programs that use the registry, it is advisable to generate an output in JSON format optimized for the given application (for example, an extension catalog for the k6build service). + +```mermaid +--- +title: registry processing +--- +erDiagram + "registry processor" ||--|| "extension registry" : input + "registry processor" ||--|{ "repository manager" : metadata + "registry processor" ||--|| "jq expression" : filter + "registry processor" ||--|| "custom JSON" : output + "custom JSON" }|--|{ "application" : uses +``` + +The registry is processed based on the popular `jq` expressions. Predefined `jq` filters should be included for common uses (for example, extension catalog generation). + +The input of the processing is the extension registry supplemented with repository metadata (for example, available versions, number of stars, etc). The output of the processing is defined by the `jq` filter. + +### Registry Validation + +The registry is validated using [JSON schema](https://grafana.github.io/k6registry/registry.schema.json). Requirements that cannot be validated using the JSON schema are validated using custom logic. + +Custom validation logic checks the following for each extension: + + - is the go module path valid? + - is there at least one versioned release? + +Validation is always done before processing. The noop filter ('.') can be used for validation only by ignoring the output. + +It is strongly recommended to validate the extension registry after each modification, but at least before approving the change. diff --git a/docs/registry.schema.json b/docs/registry.schema.json new file mode 100644 index 0000000..a3c5701 --- /dev/null +++ b/docs/registry.schema.json @@ -0,0 +1,130 @@ +{ + "$id": "https://grafana.github.io/k6registry/registry.schema.json", + "$ref": "#/$defs/registry", + "$defs": { + "registry": { + "description": "k6 Extension Registry.\n\nThe k6 extension registry contains the most important properties of registered extensions.\n", + "type": "array", + "items": { + "$ref": "#/$defs/extension" + }, + "additionalProperties": false + }, + "extension": { + "type": "object", + "description": "Properties of the registered k6 extension.\n\nOnly those properties of the extensions are registered, which either cannot be detected automatically, or delegation to the extension is not allowed.\n\nProperties that are available using the repository manager API are intentionally not registered.\n\nThe string like properties that are included in the generated Grafana documentation are intentionally not accessed via the API of the repository manager. It is not allowed to inject arbitrary text into the Grafana documentation site without approval. Therefore, these properties are registered (eg `description`)\n", + "properties": { + "module": { + "type": "string", + "description": "The extension's go module path.\n\nThis is the unique identifier of the extension.\nMore info about module paths: https://go.dev/ref/mod#module-path\n\nThe extension has no name property, the module path or part of it can be used as the extension name. For example, using the first two elements of the module path after the host name, the name `grafana/xk6-dashboard` can be formed from the module path `github.com/grafana/xk6-dashboard`. This is typically the repository owner name and the repository name in the repository manager.\n\nThe extension has no URL property, a URL can be created from the module path that refers to the extension within the repository manager.\n", + "examples": [ + "github.com/grafana/xk6-dashboard", + "github.com/szkiba/xk6-top" + ] + }, + "imports": { + "type": "array", + "items": { + "type": "string" + }, + "description": "List of JavaScript import paths registered by the extension.\n\nCurrently, paths must start with the prefix `k6/x/`.\n\nThe extensions used by k6 scripts are automatically detected based on the values specified here, therefore it is important that the values used here are consistent with the values registered by the extension at runtime.\n", + "examples": [ + [ + "k6/x/csv", + "k6/x/csv/stream" + ], + [ + "k6/x/toml" + ] + ] + }, + "outputs": { + "type": "array", + "items": { + "type": "string" + }, + "example": null, + "description": "List of output names registered by the extension.\n\nThe extensions used by k6 scripts are automatically detected based on the values specified here, therefore it is important that the values used here are consistent with the values registered by the extension at runtime.\n", + "examples": [ + [ + "dashboard" + ], + [ + "plugin" + ] + ] + }, + "description": { + "type": "string", + "description": "Brief description of the extension.\n" + }, + "repo": { + "$ref": "#/$defs/repository", + "description": "Repository metadata.\n\nMetadata provided by the extension's git repository manager. Repository metadata are not registered, they are queried at runtime using the repository manager API.\n" + }, + "official": { + "type": "boolean", + "default": "false", + "description": "Officially supported extension flag.\n\nThe `true` value of the `official` flag indicates that the extension is officially supported by Grafana.\n\nExtensions owned by the `grafana` GitHub organization are not officially supported by Grafana by default. There are several k6 extensions owned by the `grafana` GitHub organization, which were created for experimental or example purposes only. The `official` flag is needed so that officially supported extensions can be distinguished from them.\n" + }, + "cloud": { + "type": "boolean", + "default": "false", + "description": "Cloud-enabled extension flag.\n\nThe `true` value of the `cloud` flag indicates that the extension is also available in the Grafana k6 cloud.\n\nThe use of certain extensions is not supported in a cloud environment. There may be a technological reason for this, or the extension's functionality is meaningless in the cloud.\n" + } + }, + "required": [ + "module", + "description" + ], + "additionalProperties": false + }, + "repository": { + "type": "object", + "description": "Repository metadata.\n\nMetadata provided by the extension's git repository manager. Repository metadata are not registered, they are queried at runtime using the repository manager API.\n", + "properties": { + "url": { + "type": "string", + "default": "", + "description": "URL of the repository.\n\nThe URL is provided by the repository manager and can be displayed in a browser.\n" + }, + "homepage": { + "type": "string", + "default": "", + "description": "The URL to the project homepage.\n\nIf no homepage is set, the value is the same as the url property.\n" + }, + "description": { + "type": "string", + "default": "", + "description": "Repository description.\n" + }, + "stars": { + "type": "integer", + "default": "0", + "description": "The number of stars in the extension's repository.\n\nThe extension's popularity is indicated by how many users have starred the extension's repository.\n" + }, + "topics": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Repository topics.\n\nTopics make it easier to find the repository. It is recommended to set the xk6 topic to the extensions repository.\n" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + }, + "description": "The repository's git tags.\n\nStates of the git repository marked with tags can be reproduced. Versions are also tags, they must meet certain format requirements.\n" + }, + "versions": { + "type": "array", + "items": { + "type": "string" + }, + "description": "List of supported versions.\n\nVersions are tags whose format meets the requirements of semantic versioning. Version tags often start with the letter `v`, which is not part of the semantic version.\n" + } + } + } + } +} diff --git a/registry.schema.yaml b/docs/registry.schema.yaml similarity index 50% rename from registry.schema.yaml rename to docs/registry.schema.yaml index e7033ca..5c1b82f 100644 --- a/registry.schema.yaml +++ b/docs/registry.schema.yaml @@ -6,14 +6,9 @@ $defs: k6 Extension Registry. The k6 extension registry contains the most important properties of registered extensions. - type: object - properties: - extensions: - description: | - An array containing the registration data of the k6 golang extensions. - type: array - items: - $ref: "#/$defs/extension" + type: array + items: + $ref: "#/$defs/extension" additionalProperties: false extension: type: object @@ -48,6 +43,7 @@ $defs: List of JavaScript import paths registered by the extension. Currently, paths must start with the prefix `k6/x/`. + The extensions used by k6 scripts are automatically detected based on the values specified here, therefore it is important that the values used here are consistent with the values registered by the extension at runtime. examples: - ["k6/x/csv", "k6/x/csv/stream"] @@ -68,7 +64,88 @@ $defs: type: string description: | Brief description of the extension. + repo: + $ref: "#/$defs/repository" + description: | + Repository metadata. + + Metadata provided by the extension's git repository manager. Repository metadata are not registered, they are queried at runtime using the repository manager API. + official: + type: boolean + default: "false" + description: | + Officially supported extension flag. + + The `true` value of the `official` flag indicates that the extension is officially supported by Grafana. + + Extensions owned by the `grafana` GitHub organization are not officially supported by Grafana by default. There are several k6 extensions owned by the `grafana` GitHub organization, which were created for experimental or example purposes only. The `official` flag is needed so that officially supported extensions can be distinguished from them. + cloud: + type: boolean + default: "false" + description: | + Cloud-enabled extension flag. + + The `true` value of the `cloud` flag indicates that the extension is also available in the Grafana k6 cloud. + + The use of certain extensions is not supported in a cloud environment. There may be a technological reason for this, or the extension's functionality is meaningless in the cloud. required: - module - description additionalProperties: false + repository: + type: object + description: | + Repository metadata. + + Metadata provided by the extension's git repository manager. Repository metadata are not registered, they are queried at runtime using the repository manager API. + properties: + url: + type: string + default: "" + description: | + URL of the repository. + + The URL is provided by the repository manager and can be displayed in a browser. + homepage: + type: string + default: "" + description: | + The URL to the project homepage. + + If no homepage is set, the value is the same as the url property. + description: + type: string + default: "" + description: | + Repository description. + stars: + type: integer + default: "0" + description: | + The number of stars in the extension's repository. + + The extension's popularity is indicated by how many users have starred the extension's repository. + topics: + type: array + items: + type: string + description: | + Repository topics. + + Topics make it easier to find the repository. It is recommended to set the xk6 topic to the extensions repository. + tags: + type: array + items: + type: string + description: | + The repository's git tags. + + States of the git repository marked with tags can be reproduced. Versions are also tags, they must meet certain format requirements. + versions: + type: array + items: + type: string + description: | + List of supported versions. + + Versions are tags whose format meets the requirements of semantic versioning. Version tags often start with the letter `v`, which is not part of the semantic version. diff --git a/example.json b/example.json deleted file mode 100644 index 1a700e1..0000000 --- a/example.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "extensions": [ - { - "module": "github.com/grafana/xk6-dashboard", - "description": "Web-based metrics dashboard for k6", - "outputs": ["dashboard"] - }, - { - "module": "github.com/grafana/xk6-sql", - "description": "Load test SQL Servers", - "imports": ["k6/x/sql"] - }, - { - "module": "github.com/grafana/xk6-distruptor", - "description": "Inject faults to test", - "imports": ["k6/x/distruptor"] - }, - { - "module": "github.com/szkiba/xk6-faker", - "description": "Generate random fake data", - "imports": ["k6/x/faker"] - } - ] -} diff --git a/go.mod b/go.mod index 06c8f38..b646df0 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,15 @@ module github.com/grafana/k6registry go 1.22 + +require ( + github.com/grafana/clireadme v0.1.0 + github.com/spf13/cobra v1.8.1 + golang.org/x/term v0.22.0 +) + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/sys v0.22.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..14d605b --- /dev/null +++ b/go.sum @@ -0,0 +1,16 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/grafana/clireadme v0.1.0 h1:KYEYSnYdSzmHf3bufaK6fQZ5j4dzvM/T+G6Ba+qNnAM= +github.com/grafana/clireadme v0.1.0/go.mod h1:Wy4KIG2ZBGMYAYyF9l7qAy+yoJVasqk/txsRgoRI3gc= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/registry.go b/registry.go index bd55e05..67eb0b3 100644 --- a/registry.go +++ b/registry.go @@ -1,6 +1,2 @@ // Package k6registry contains the data model of the k6 extensions registry. package k6registry - -//go:generate sh -c "go run github.com/mikefarah/yq/v4@v4.44.2 -o=json -P registry.schema.yaml > registry.schema.json" -//go:generate go run github.com/atombender/go-jsonschema@v0.16.0 -p k6registry --only-models -o registry_gen.go registry.schema.yaml -//go:generate go run github.com/szkiba/mdcode@v0.2.0 update diff --git a/registry.schema.json b/registry.schema.json deleted file mode 100644 index b0e946b..0000000 --- a/registry.schema.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "$id": "https://grafana.github.io/k6registry/registry.schema.json", - "$ref": "#/$defs/registry", - "$defs": { - "registry": { - "description": "k6 Extension Registry.\n\nThe k6 extension registry contains the most important properties of registered extensions.\n", - "type": "object", - "properties": { - "extensions": { - "description": "An array containing the registration data of the k6 golang extensions.\n", - "type": "array", - "items": { - "$ref": "#/$defs/extension" - } - } - }, - "additionalProperties": false - }, - "extension": { - "type": "object", - "description": "Properties of the registered k6 extension.\n\nOnly those properties of the extensions are registered, which either cannot be detected automatically, or delegation to the extension is not allowed.\n\nProperties that are available using the repository manager API are intentionally not registered.\n\nThe string like properties that are included in the generated Grafana documentation are intentionally not accessed via the API of the repository manager. It is not allowed to inject arbitrary text into the Grafana documentation site without approval. Therefore, these properties are registered (eg `description`)\n", - "properties": { - "module": { - "type": "string", - "description": "The extension's go module path.\n\nThis is the unique identifier of the extension.\nMore info about module paths: https://go.dev/ref/mod#module-path\n\nThe extension has no name property, the module path or part of it can be used as the extension name. For example, using the first two elements of the module path after the host name, the name `grafana/xk6-dashboard` can be formed from the module path `github.com/grafana/xk6-dashboard`. This is typically the repository owner name and the repository name in the repository manager.\n\nThe extension has no URL property, a URL can be created from the module path that refers to the extension within the repository manager.\n", - "examples": [ - "github.com/grafana/xk6-dashboard", - "github.com/szkiba/xk6-top" - ] - }, - "imports": { - "type": "array", - "items": { - "type": "string" - }, - "description": "List of JavaScript import paths registered by the extension.\n\nCurrently, paths must start with the prefix `k6/x/`.\nThe extensions used by k6 scripts are automatically detected based on the values specified here, therefore it is important that the values used here are consistent with the values registered by the extension at runtime.\n", - "examples": [ - [ - "k6/x/csv", - "k6/x/csv/stream" - ], - [ - "k6/x/toml" - ] - ] - }, - "outputs": { - "type": "array", - "items": { - "type": "string" - }, - "example": null, - "description": "List of output names registered by the extension.\n\nThe extensions used by k6 scripts are automatically detected based on the values specified here, therefore it is important that the values used here are consistent with the values registered by the extension at runtime.\n", - "examples": [ - [ - "dashboard" - ], - [ - "plugin" - ] - ] - }, - "description": { - "type": "string", - "description": "Brief description of the extension.\n" - } - }, - "required": [ - "module", - "description" - ], - "additionalProperties": false - } - } -} diff --git a/registry_gen.go b/registry_gen.go index 828f3f0..1dc52e7 100644 --- a/registry_gen.go +++ b/registry_gen.go @@ -16,6 +16,17 @@ package k6registry // documentation site without approval. Therefore, these properties are registered // (eg `description`) type Extension struct { + // Cloud-enabled extension flag. + // + // The `true` value of the `cloud` flag indicates that the extension is also + // available in the Grafana k6 cloud. + // + // The use of certain extensions is not supported in a cloud environment. There + // may be a technological reason for this, or the extension's functionality is + // meaningless in the cloud. + // + Cloud bool `json:"cloud,omitempty" yaml:"cloud,omitempty" mapstructure:"cloud,omitempty"` + // Brief description of the extension. // Description string `json:"description" yaml:"description" mapstructure:"description"` @@ -23,6 +34,7 @@ type Extension struct { // List of JavaScript import paths registered by the extension. // // Currently, paths must start with the prefix `k6/x/`. + // // The extensions used by k6 scripts are automatically detected based on the // values specified here, therefore it is important that the values used here are // consistent with the values registered by the extension at runtime. @@ -45,6 +57,19 @@ type Extension struct { // Module string `json:"module" yaml:"module" mapstructure:"module"` + // Officially supported extension flag. + // + // The `true` value of the `official` flag indicates that the extension is + // officially supported by Grafana. + // + // Extensions owned by the `grafana` GitHub organization are not officially + // supported by Grafana by default. There are several k6 extensions owned by the + // `grafana` GitHub organization, which were created for experimental or example + // purposes only. The `official` flag is needed so that officially supported + // extensions can be distinguished from them. + // + Official bool `json:"official,omitempty" yaml:"official,omitempty" mapstructure:"official,omitempty"` + // List of output names registered by the extension. // // The extensions used by k6 scripts are automatically detected based on the @@ -52,14 +77,71 @@ type Extension struct { // consistent with the values registered by the extension at runtime. // Outputs []string `json:"outputs,omitempty" yaml:"outputs,omitempty" mapstructure:"outputs,omitempty"` + + // Repository metadata. + // + // Metadata provided by the extension's git repository manager. Repository + // metadata are not registered, they are queried at runtime using the repository + // manager API. + // + Repo *Repository `json:"repo,omitempty" yaml:"repo,omitempty" mapstructure:"repo,omitempty"` } // k6 Extension Registry. // // The k6 extension registry contains the most important properties of registered // extensions. -type Registry struct { - // An array containing the registration data of the k6 golang extensions. +type Registry []Extension + +// Repository metadata. +// +// Metadata provided by the extension's git repository manager. Repository metadata +// are not registered, they are queried at runtime using the repository manager +// API. +type Repository struct { + // Repository description. + // + Description string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"` + + // The URL to the project homepage. + // + // If no homepage is set, the value is the same as the url property. + // + Homepage string `json:"homepage,omitempty" yaml:"homepage,omitempty" mapstructure:"homepage,omitempty"` + + // The number of stars in the extension's repository. + // + // The extension's popularity is indicated by how many users have starred the + // extension's repository. + // + Stars int `json:"stars,omitempty" yaml:"stars,omitempty" mapstructure:"stars,omitempty"` + + // The repository's git tags. + // + // States of the git repository marked with tags can be reproduced. Versions are + // also tags, they must meet certain format requirements. + // + Tags []string `json:"tags,omitempty" yaml:"tags,omitempty" mapstructure:"tags,omitempty"` + + // Repository topics. + // + // Topics make it easier to find the repository. It is recommended to set the xk6 + // topic to the extensions repository. + // + Topics []string `json:"topics,omitempty" yaml:"topics,omitempty" mapstructure:"topics,omitempty"` + + // URL of the repository. + // + // The URL is provided by the repository manager and can be displayed in a + // browser. + // + Url string `json:"url,omitempty" yaml:"url,omitempty" mapstructure:"url,omitempty"` + + // List of supported versions. + // + // Versions are tags whose format meets the requirements of semantic versioning. + // Version tags often start with the letter `v`, which is not part of the semantic + // version. // - Extensions []Extension `json:"extensions,omitempty" yaml:"extensions,omitempty" mapstructure:"extensions,omitempty"` + Versions []string `json:"versions,omitempty" yaml:"versions,omitempty" mapstructure:"versions,omitempty"` } diff --git a/releases/v0.1.1.md b/releases/v0.1.1.md new file mode 100644 index 0000000..9a50147 --- /dev/null +++ b/releases/v0.1.1.md @@ -0,0 +1,3 @@ +k6registry `v0.1.1` is here 🎉! + +This is an internal maintenance release that introduces CLI functionality. diff --git a/tools/gendoc/main.go b/tools/gendoc/main.go new file mode 100644 index 0000000..3d373a0 --- /dev/null +++ b/tools/gendoc/main.go @@ -0,0 +1,12 @@ +// Package main contains CLI documentation generator tool. +package main + +import ( + "github.com/grafana/clireadme" + "github.com/grafana/k6registry/cmd" +) + +func main() { + root := cmd.New() + clireadme.Main(root, 1) +} From a411ac5dd4130116cbe64eb0d8f2f22e071ea38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Tue, 23 Jul 2024 16:31:30 +0200 Subject: [PATCH 2/2] fix: linter issue --- cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 8fe9054..2318ee8 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -20,7 +20,7 @@ func New() *cobra.Command { SilenceErrors: true, DisableAutoGenTag: true, CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { return nil }, }