Skip to content

Commit b7a4737

Browse files
committed
Automatic update of the extension list
Automatic update of the k6 extension list in the docs/sources/next/extensions/explore.md file in case of changes based on the https://registry.k6.io/registry.json extension registry. The change is pushed to the extension-registry-changed branch and a pull request is opened (or updated) about the change.
1 parent dd93b3a commit b7a4737

File tree

3 files changed

+95
-1129
lines changed

3 files changed

+95
-1129
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow keeps the list of extensions up to date
2+
# in the docs/sources/next/extensions/explore.md file.
3+
#
4+
# The workflow is activated by a workflow dispatch event
5+
# of the "extension-registry-changed" type.
6+
# This event is triggered by the grafana/k6-extension-registry
7+
# repository when the extension registry changes.
8+
#
9+
# The list of extensions is generated based on https://registry.k6.io/registry.json.
10+
# If the generated list differs from the previous one,
11+
# it is pushed to the "extension-registry-changed" branch and
12+
# a pull request is created with the change (or updated if it already existed).
13+
#
14+
# It is not a problem if the registry changes several times before merging the pull request,
15+
# the pull request will be updated. The "extension-registry-changed" branch can be deleted
16+
# after merging the pull request, it will be created again if necessary.
17+
18+
name: extension-registry-changed
19+
20+
on:
21+
workflow_dispatch:
22+
repository_dispatch:
23+
types: [extension-registry-changed]
24+
25+
jobs:
26+
update:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Generate Files
34+
run: ${{ github.workspace }}/scripts/extension-registry-changed
35+
36+
- name: Create Pull Request
37+
uses: peter-evans/create-pull-request@v6
38+
with:
39+
branch: extension-registry-changed
40+
commit-message: |
41+
Keep files generated from the k6 extension registry up to date
42+
title: |
43+
Update files generated from the k6 Extension Registry
44+
body: |
45+
The [k6 Extension Registry](https://registry.k6.io) has changed.
46+
This pull request contains the files generated from the k6 Extension Registry.
47+
add-paths: |
48+
docs/sources/next/extensions/explore.md

scripts/extension-registry-changed

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# This script keeps the list of extensions up to date
4+
# in the docs/sources/next/extensions/explore.md file.
5+
#
6+
# The script is run by the extension-registry.changed.yml
7+
# workflow when the extension registry changes.
8+
#
9+
# The list of extensions is generated based on https://registry.k6.io/registry.json.
10+
#
11+
# In the docs/sources/next/extensions/explore.md file
12+
# the content of the <div class="nav-cards"> HTML element
13+
# is replaced with the generated extension list.
14+
15+
generate_extension_list_partial() {
16+
curl -sL https://registry.k6.io/registry.json |
17+
jq -r '
18+
map(select(.module != "go.k6.io/k6") | { name:.repo.name, url: .repo.url, description: .description } ) |
19+
sort_by(.name) | map(
20+
" <a href=\"\(.url)\" target=\"_blank\" class=\"nav-cards__item nav-cards__item--guide\">
21+
<h4>\(.name)</h4>
22+
<p>\(.description)</p>
23+
</a>"
24+
) | .[]
25+
'
26+
}
27+
28+
replace_extension_list_partial() {
29+
ed -s $1 <<EOF
30+
/<div class=.nav-cards.>/+,/<.div>/-d
31+
/<div class=.nav-cards.>/ r $2
32+
w
33+
q
34+
EOF
35+
}
36+
37+
scriptdir=$(dirname $(readlink -f "$0"))
38+
docfile=$scriptdir/../docs/sources/next/extensions/explore.md
39+
40+
tmpfile=/tmp/explore.$$
41+
42+
generate_extension_list_partial > $tmpfile
43+
replace_extension_list_partial $docfile $tmpfile
44+
45+
rm -f $tmpfile

0 commit comments

Comments
 (0)