Skip to content

Commit 910383d

Browse files
committed
feat: automated plugin index generation
1 parent 60616f9 commit 910383d

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

.github/workflows/update-index.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Update Plugin Index
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Publish Plugin"]
6+
types:
7+
- completed
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: update-index
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
update-index:
19+
runs-on: ubuntu-latest
20+
if: >-
21+
github.event_name == 'workflow_dispatch' ||
22+
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
fetch-tags: true
29+
30+
- name: Generate index.json
31+
run: bash scripts/generate-index.sh
32+
33+
- name: Check for changes
34+
id: diff
35+
run: |
36+
if git diff --quiet index.json; then
37+
echo "changed=false" >> "$GITHUB_OUTPUT"
38+
else
39+
echo "changed=true" >> "$GITHUB_OUTPUT"
40+
fi
41+
42+
- name: Commit and push
43+
if: steps.diff.outputs.changed == 'true'
44+
run: |
45+
git config user.name "github-actions[bot]"
46+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
47+
git add index.json
48+
git commit -m "Update plugin index"
49+
git push

scripts/generate-index.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Collect plugin metadata from each plugin.json,
5+
# merged with latest git tag version.
6+
7+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
repo_root="$(dirname "$script_dir")"
9+
10+
registry="ghcr.io/reglet-dev/plugins"
11+
repo_url="https://github.com/reglet-dev/reglet-plugins"
12+
13+
plugins_json="[]"
14+
15+
# ensure we affect the correct path.
16+
17+
for plugin_json in "$repo_root"/plugins/*/plugin.json; do
18+
# check if file exists to handle empty case
19+
[ -e "$plugin_json" ] || continue
20+
21+
plugin_dir="$(dirname "$plugin_json")"
22+
plugin_name="$(jq -r '.name' "$plugin_json")"
23+
24+
# Find latest tag for this plugin (e.g. dns/v1.2.0 -> 1.2.0)
25+
latest=$(git tag -l "${plugin_name}/v*" --sort=-v:refname | head -1 | sed "s|${plugin_name}/v||" || echo "unreleased")
26+
if [ -z "$latest" ]; then
27+
latest="unreleased"
28+
fi
29+
30+
entry=$(jq --arg v "$latest" '. + {latest: $v}' "$plugin_json")
31+
plugins_json=$(echo "$plugins_json" | jq --argjson e "$entry" '. + [$e]')
32+
done
33+
34+
jq -n \
35+
--arg repo "$repo_url" \
36+
--arg registry "$registry" \
37+
--arg updated "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
38+
--argjson plugins "$plugins_json" \
39+
'{repository: $repo, registry: $registry, updated: $updated, plugins: $plugins}' \
40+
> "$repo_root/index.json"
41+
42+
echo "Generated index.json with $(echo "$plugins_json" | jq length) plugins"

0 commit comments

Comments
 (0)