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

Automatic update of the extension list #1731

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
48 changes: 48 additions & 0 deletions .github/workflows/extension-registry-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow keeps the list of extensions up to date
# in the docs/sources/next/extensions/explore.md file.
#
# The workflow is activated by a workflow dispatch event
# of the "extension-registry-changed" type.
# This event is triggered by the grafana/k6-extension-registry
# repository when the extension registry changes.
#
# The list of extensions is generated based on https://registry.k6.io/registry.json.
# If the generated list differs from the previous one,
# it is pushed to the "extension-registry-changed" branch and
# a pull request is created with the change (or updated if it already existed).
#
# It is not a problem if the registry changes several times before merging the pull request,
# the pull request will be updated. The "extension-registry-changed" branch can be deleted
# after merging the pull request, it will be created again if necessary.

name: extension-registry-changed

on:
workflow_dispatch:
repository_dispatch:
types: [extension-registry-changed]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Generate Files
run: ${{ github.workspace }}/scripts/extension-registry-changed

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
branch: extension-registry-changed
commit-message: |
Keep files generated from the k6 extension registry up to date
title: |
Update files generated from the k6 Extension Registry
body: |
The [k6 Extension Registry](https://registry.k6.io) has changed.
This pull request contains the files generated from the k6 Extension Registry.
add-paths: |
docs/sources/next/extensions/explore.md
45 changes: 45 additions & 0 deletions scripts/extension-registry-changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
szkiba marked this conversation as resolved.
Show resolved Hide resolved

# This script keeps the list of extensions up to date
# in the docs/sources/next/extensions/explore.md file.
#
# The script is run by the extension-registry.changed.yml
# workflow when the extension registry changes.
#
# The list of extensions is generated based on https://registry.k6.io/registry.json.
#
# In the docs/sources/next/extensions/explore.md file
# the content of the <div class="nav-cards"> HTML element
# is replaced with the generated extension list.

generate_extension_list_partial() {
curl -sL https://registry.k6.io/registry.json |
jq -r '
map(select(.module != "go.k6.io/k6") | { name:.repo.name, url: .repo.url, description: .description } ) |
sort_by(.name) | map(
" <a href=\"\(.url)\" target=\"_blank\" class=\"nav-cards__item nav-cards__item--guide\">
<h4>\(.name)</h4>
<p>\(.description)</p>
</a>"
) | .[]
'
}

replace_extension_list_partial() {
ed -s $1 <<EOF
/<div class=.nav-cards.>/+,/<.div>/-d
/<div class=.nav-cards.>/ r $2
w
q
EOF
}
szkiba marked this conversation as resolved.
Show resolved Hide resolved

scriptdir=$(dirname $(readlink -f "$0"))
docfile=$scriptdir/../docs/sources/next/extensions/explore.md
szkiba marked this conversation as resolved.
Show resolved Hide resolved

tmpfile=/tmp/explore.$$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally use mktemp because it respects the TMPDIR environment variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I'll fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


generate_extension_list_partial > $tmpfile
replace_extension_list_partial $docfile $tmpfile
szkiba marked this conversation as resolved.
Show resolved Hide resolved

rm -f $tmpfile
Loading
Loading