Repository navigation
feat(plugins): show prerequisites in plugin descriptions and add PR-only sync workflow #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| name: Sync Upstream Plugins | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| only: | ||
| description: Comma-separated plugin names or dirs (leave blank for all) | ||
| required: false | ||
| default: "" | ||
| type: string | ||
| upload_zips: | ||
| description: Upload dist/*.zip artifacts even when no sync PR is created or updated | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| repository_dispatch: | ||
| types: [upstream-release] | ||
| schedule: | ||
| - cron: "17 */6 * * *" | ||
|
|
||
| concurrency: | ||
| group: sync-upstream-plugins | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| sync: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| token: ${{ secrets.PLUGINS_SYNC_TOKEN || github.token }} | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
|
|
||
| - name: Check existing open sync PR state | ||
| id: pr_state | ||
| env: | ||
| GH_TOKEN: ${{ secrets.PLUGINS_SYNC_TOKEN || github.token }} | ||
| ONLY_PLUGINS: ${{ inputs.only || '' }} | ||
| run: | | ||
| set -euo pipefail | ||
| EXISTING="$(gh pr list --repo "$GITHUB_REPOSITORY" --head chore/sync-upstream-plugins --base main --state open --limit 100 --json number,isCrossRepository --jq '[.[] | select(.isCrossRepository | not)][0].number // empty')" | ||
| echo "existing_pr=$EXISTING" >> "$GITHUB_OUTPUT" | ||
| if [ -n "$EXISTING" ] && [ -n "$ONLY_PLUGINS" ]; then | ||
| echo "::error::An open sync PR (#$EXISTING) already exists on chore/sync-upstream-plugins; merge or close it, or re-run with 'only' blank for a full sync." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Rebuild plugins from upstream | ||
| env: | ||
| ONLY_PLUGINS: ${{ inputs.only || '' }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [ -n "$ONLY_PLUGINS" ]; then | ||
| python3 -B release.py --only "$ONLY_PLUGINS" | ||
| else | ||
| python3 -B release.py | ||
| fi | ||
|
|
||
| - name: Validate unit tests, manifests, and portal archives | ||
| run: | | ||
| set -euo pipefail | ||
| python3 -B -m unittest -v test_release.py | ||
| python3 -B release.py --validate | ||
| python3 -B release.py --zip-existing | ||
|
|
||
| - name: Check for new changes vs main and any open sync PR | ||
| id: diff | ||
| env: | ||
| GH_TOKEN: ${{ secrets.PLUGINS_SYNC_TOKEN || github.token }} | ||
| EXISTING_PR: ${{ steps.pr_state.outputs.existing_pr }} | ||
| run: | | ||
| set -euo pipefail | ||
| if git status --porcelain | grep -E '(^| )(dist/|__pycache__/)'; then | ||
| echo "error: dist/ or __pycache__/ appeared in git status" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ -n "$(find plugins -name '__pycache__')" ]; then | ||
| echo "error: __pycache__ created inside plugins/" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$(git status --porcelain)" ]; then | ||
| echo "needs_push=false" >> "$GITHUB_OUTPUT" | ||
| echo "needs_pr=false" >> "$GITHUB_OUTPUT" | ||
| if [ -n "$EXISTING_PR" ]; then | ||
| echo "close_stale_pr=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "close_stale_pr=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "close_stale_pr=false" >> "$GITHUB_OUTPUT" | ||
|
|
||
| TMP_IDX="$(mktemp)" | ||
| trap 'rm -f "$TMP_IDX"' EXIT | ||
| cp .git/index "$TMP_IDX" | ||
| GIT_INDEX_FILE="$TMP_IDX" git add -A | ||
| TREE_SHA="$(GIT_INDEX_FILE="$TMP_IDX" git write-tree)" | ||
| echo "tree_sha=$TREE_SHA" >> "$GITHUB_OUTPUT" | ||
|
|
||
| NEEDS_PUSH=true | ||
| if git rev-parse --verify -q refs/remotes/origin/chore/sync-upstream-plugins >/dev/null; then | ||
| REMOTE_TREE="$(git rev-parse 'refs/remotes/origin/chore/sync-upstream-plugins^{tree}')" | ||
| if [ "$REMOTE_TREE" = "$TREE_SHA" ] && git merge-base --is-ancestor HEAD refs/remotes/origin/chore/sync-upstream-plugins; then | ||
| NEEDS_PUSH=false | ||
| fi | ||
| fi | ||
| echo "needs_push=$NEEDS_PUSH" >> "$GITHUB_OUTPUT" | ||
|
|
||
| if [ "$NEEDS_PUSH" = "true" ] || [ -z "$EXISTING_PR" ]; then | ||
| echo "needs_pr=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| PR_BODY="$(gh pr view "$EXISTING_PR" --repo "$GITHUB_REPOSITORY" --json body --jq '.body // ""')" | ||
| if printf '%s\n' "$PR_BODY" | grep -Fq -- "<!-- sync-tree:${TREE_SHA} -->"; then | ||
| echo "needs_pr=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "needs_pr=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Close obsolete sync pull request | ||
| if: steps.diff.outputs.close_stale_pr == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.PLUGINS_SYNC_TOKEN || github.token }} | ||
| EXISTING_PR: ${{ steps.pr_state.outputs.existing_pr }} | ||
| run: | | ||
| set -euo pipefail | ||
| gh pr close "$EXISTING_PR" --repo "$GITHUB_REPOSITORY" \ | ||
| --comment "Closing automatically: rebuilt plugins from upstream now match \`main\`." | ||
| RC=0 | ||
| git ls-remote --exit-code --heads origin chore/sync-upstream-plugins >/dev/null || RC=$? | ||
| if [ "$RC" -eq 0 ]; then | ||
| git push origin --delete chore/sync-upstream-plugins | ||
| elif [ "$RC" -ne 2 ]; then | ||
| echo "::warning::git ls-remote failed with exit code $RC while checking chore/sync-upstream-plugins" >&2 | ||
| exit "$RC" | ||
| fi | ||
|
|
||
| - name: Upload OpenAI/Codex portal .zip artifacts | ||
| id: upload_zips | ||
| if: steps.diff.outputs.needs_pr == 'true' || (github.event_name == 'workflow_dispatch' && inputs.upload_zips) | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: bmad-plugins-zips | ||
| path: dist/*.zip | ||
| retention-days: 14 | ||
| if-no-files-found: error | ||
|
|
||
| - name: Open or update sync pull request | ||
| if: steps.diff.outputs.needs_pr == 'true' | ||
|
bmadcode marked this conversation as resolved.
Resolved
|
||
| env: | ||
| GH_TOKEN: ${{ secrets.PLUGINS_SYNC_TOKEN || github.token }} | ||
| USING_SYNC_TOKEN: ${{ secrets.PLUGINS_SYNC_TOKEN != '' }} | ||
| EXISTING_PR: ${{ steps.pr_state.outputs.existing_pr }} | ||
| NEEDS_PUSH: ${{ steps.diff.outputs.needs_push }} | ||
| TREE_SHA: ${{ steps.diff.outputs.tree_sha }} | ||
| UPLOAD_OUTCOME: ${{ steps.upload_zips.outcome }} | ||
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [ "$NEEDS_PUSH" = "true" ]; then | ||
| git switch -C chore/sync-upstream-plugins | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git add -A | ||
| git commit -m "chore(release): sync plugins from upstream" | ||
| git push --force origin chore/sync-upstream-plugins | ||
| fi | ||
|
|
||
| BODY_FILE="$(mktemp)" | ||
| trap 'rm -f "$BODY_FILE"' EXIT | ||
| python3 -B - "$BODY_FILE" "$RUN_URL" "$USING_SYNC_TOKEN" "$TREE_SHA" "$UPLOAD_OUTCOME" <<'PY' | ||
| import json | ||
| import sys | ||
| import tomllib | ||
| from pathlib import Path | ||
|
|
||
| out_path = Path(sys.argv[1]) | ||
| run_url = sys.argv[2] | ||
| using_sync_token = sys.argv[3].lower() == "true" | ||
| tree_sha = sys.argv[4] | ||
| upload_outcome = sys.argv[5] | ||
|
|
||
| mp = json.loads(Path(".claude-plugin/marketplace.json").read_text(encoding="utf-8")) | ||
| catalog = tomllib.loads(Path("catalog.toml").read_text(encoding="utf-8")) | ||
| rows = [f"| `{p['name']}` | `{p['version']}` |" for p in mp.get("plugins", [])] | ||
| for bundle in catalog.get("portal_bundles", []): | ||
| manifest = json.loads(Path(f"plugins/{bundle['dir_name']}/.claude-plugin/plugin.json").read_text(encoding="utf-8")) | ||
| rows.append(f"| `{bundle['name']}` (portal bundle) | `{manifest['version']}` |") | ||
|
|
||
| lines = [ | ||
| "Automated plugin sync from upstream default branches.", | ||
| "", | ||
| "| Plugin | Version |", | ||
| "| --- | --- |", | ||
| *rows, | ||
| ] | ||
| if upload_outcome == "success": | ||
| lines.extend([ | ||
| "", | ||
| f"Downloadable OpenAI/Codex portal `.zip` archives are attached to [this workflow run]({run_url}) (`bmad-plugins-zips`).", | ||
| ]) | ||
| if not using_sync_token: | ||
| lines.extend([ | ||
| "", | ||
| "> Note: Built and validated inside the sync workflow above. Because `PLUGINS_SYNC_TOKEN` is unset, `pull_request` checks triggered by `GITHUB_TOKEN` require a maintainer with write access to approve workflows before running.", | ||
| ]) | ||
| lines.extend(["", f"<!-- sync-tree:{tree_sha} -->"]) | ||
| out_path.write_text("\n".join(lines) + "\n", encoding="utf-8") | ||
| PY | ||
|
|
||
| if [ -n "$EXISTING_PR" ]; then | ||
| gh pr edit "$EXISTING_PR" --repo "$GITHUB_REPOSITORY" --body-file "$BODY_FILE" | ||
| else | ||
| gh pr create --repo "$GITHUB_REPOSITORY" --base main --head chore/sync-upstream-plugins \ | ||
| --title "chore(release): sync plugins from upstream" \ | ||
| --body-file "$BODY_FILE" | ||
| fi | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.