1+ name : Update Plugin Hash
2+
3+ on :
4+ repository_dispatch :
5+ types : [plugin_updated]
6+
7+ # Ensure the workflow has permissions to manage PRs and update contents
8+ permissions :
9+ contents : write
10+ pull-requests : write
11+
12+ jobs :
13+ update-store :
14+ runs-on : ubuntu-latest
15+ steps :
16+ - name : Checkout Store Repo
17+ uses : actions/checkout@v4
18+
19+ - name : Update Plugins.json
20+ env :
21+ REPO_URL : ${{ github.event.client_payload.repo_url }}
22+ VERSION : ${{ github.event.client_payload.version }}
23+ COMMIT_SHA : ${{ github.event.client_payload.commit_sha }}
24+ run : |
25+ # Uses jq to map over the array. Finds the object where "url" matches,
26+ # and adds/updates the commit hash under the specified version key.
27+ jq --arg url "$REPO_URL" --arg ver "$VERSION" --arg sha "$COMMIT_SHA" \
28+ 'map(if .url == $url then .commits[$ver] = $sha else . end)' \
29+ Plugins.json > temp.json && mv temp.json Plugins.json
30+
31+ - name : Extract Plugin Name
32+ id : plugin_info
33+ run : |
34+ # Extracts the repository name (e.g., "MediaPlugin") from the full URL
35+ PLUGIN_NAME=$(echo "${{ github.event.client_payload.repo_url }}" | awk -F'/' '{print $5}')
36+ echo "name=$PLUGIN_NAME" >> $GITHUB_OUTPUT
37+
38+ - name : Close Old Pull Requests for this Plugin
39+ env :
40+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
41+ PLUGIN_NAME : ${{ steps.plugin_info.outputs.name }}
42+ run : |
43+ # Search for any open PRs originating from a branch that belongs to this specific plugin
44+ prs=$(gh pr list --state open --json headRefName,number --jq ".[] | select(.headRefName | startswith(\"update-plugin-$PLUGIN_NAME-\")) | .number")
45+
46+ for pr in $prs; do
47+ echo "Closing older unmerged PR #$pr"
48+ gh pr close "$pr" --comment "Superseded by a newer push to the plugin repository."
49+ done
50+
51+ - name : Create New Pull Request
52+ uses : peter-evans/create-pull-request@v6
53+ with :
54+ token : ${{ secrets.GITHUB_TOKEN }}
55+ commit-message : " update(${{ steps.plugin_info.outputs.name }}): update hash for ${{ github.event.client_payload.version }}"
56+ title : " Update ${{ steps.plugin_info.outputs.name }} to ${{ github.event.client_payload.version }}"
57+ body : |
58+ Automated update of commit hash for plugin: ${{ steps.plugin_info.outputs.name }}
59+ - **Version/Branch:** ${{ github.event.client_payload.version }}
60+ - **Commit SHA:** ${{ github.event.client_payload.commit_sha }}
61+ # Appending the SHA makes the branch name unique, ensuring a brand-new PR is opened
62+ # rather than updating the previous one (which we closed in the step above).
63+ branch : " update-plugin-${{ steps.plugin_info.outputs.name }}-${{ github.event.client_payload.commit_sha }}"
64+ base : main
0 commit comments