Skip to content

Commit d3f6d2a

Browse files
authored
Merge pull request #1731 from grafana/automatic-update-of-the-extension-list
Automatic update of the extension list
2 parents 643a39d + 6d3915a commit d3f6d2a

File tree

3 files changed

+101
-1116
lines changed

3 files changed

+101
-1116
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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env 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+
local -r outfile="$1"
30+
local -r infile="$2"
31+
32+
ed -s "$outfile" <<EOF
33+
/<div class=.nav-cards.>/+,/<.div>/-d
34+
/<div class=.nav-cards.>/ r "$infile"
35+
w
36+
q
37+
EOF
38+
}
39+
40+
scriptdir="$(dirname "$(readlink -f "$0")")"
41+
docfile="$scriptdir/../docs/sources/next/extensions/explore.md"
42+
43+
tmpfile="$(mktemp)"
44+
45+
generate_extension_list_partial > "$tmpfile"
46+
replace_extension_list_partial "$docfile" "$tmpfile"
47+
48+
rm -f "$tmpfile"

0 commit comments

Comments
 (0)