Generate Plugins JSON File #4528
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate Plugins JSON File | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 * * * *' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| jobs: | |
| process-json: | |
| name: Generate Plugins JSON File | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get latest tag | |
| id: get_tag | |
| run: | | |
| git fetch --tags # Fetch all tags from the remote | |
| latest_tag=$(git describe --tags --abbrev=0) | |
| if [[ $latest_tag == v* ]]; then | |
| latest_tag=${latest_tag:1} | |
| fi | |
| echo "latest_tag=$latest_tag" >> $GITHUB_ENV | |
| - name: Process JSON | |
| run: | | |
| core_input="core_plugins/plugins.json" | |
| community_input="community_plugins.json" | |
| output_file="plugins.json" | |
| community_data=$(cat "$community_input") | |
| community_urls=$(echo "$community_data" | jq -r 'to_entries | .[].value.url') | |
| query="query {" | |
| index=0 | |
| for url in $community_urls; do | |
| repo_name=$(echo $url | sed 's/https:\/\/github.com\///' | sed 's/\.git$//') | |
| IFS='/' read -r owner name <<< "$repo_name" | |
| query="$query | |
| repo$index: repository(owner: \"$owner\", name: \"$name\") { | |
| name | |
| tags: refs(refPrefix: \"refs/tags/\", first: 1, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) { | |
| edges { | |
| node { | |
| name | |
| } | |
| } | |
| } | |
| }" | |
| index=$((index + 1)) | |
| done | |
| query="$query | |
| }" | |
| response=$(gh api graphql -f query="$query") | |
| latest_tags="{}"; | |
| index=0 | |
| while read -r url; do | |
| tag=$(echo "$response" | jq -r ".data.repo$index.tags.edges[0].node.name") | |
| if [[ "$tag" != "null" ]]; then | |
| if [[ $tag == v* ]]; then | |
| tag=${tag:1} | |
| fi | |
| id=$(echo "$community_data" | jq -r "keys[$index]") | |
| latest_tags=$(echo $latest_tags | jq --arg id "$id" --arg tag "$tag" '. + {($id): {version: $tag}}') | |
| fi | |
| index=$((index + 1)) | |
| done <<< $community_urls | |
| if [ -f "$core_input" ]; then | |
| core_data=$(cat "$core_input") | |
| else | |
| echo "Core plugins file not found: $core_input" && exit 1 | |
| fi | |
| if [ -f "$community_input" ]; then | |
| community_data=$(cat "$community_input") | |
| else | |
| community_data="{}" | |
| fi | |
| updated_community_data=$(echo $community_data $latest_tags | jq --slurp 'reduce .[] as $item ({}; . * $item)') | |
| echo "$core_data" | jq -c --arg core_version "$latest_tag" --argjson community "$updated_community_data" \ | |
| '{core_version: $core_version, core: ., community: $community}' | jq . > "$output_file" | |
| - name: Commit and Push Changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add plugins.json | |
| git diff --cached --exit-code || (git commit -m "Generated plugins.json" && git push) | |