mirror of
https://github.com/agent0ai/a0-plugins.git
synced 2026-12-04 03:18:07 +00:00
Deletion PRs require the plugin to be present in index.json, but the workflow never downloaded it (index.json is a Release asset, not in git). Add the download step so deletion validation can succeed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
122 lines
4.5 KiB
YAML
122 lines
4.5 KiB
YAML
name: Validate Plugin PR
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [opened, synchronize, reopened, ready_for_review, labeled]
|
|
|
|
permissions:
|
|
contents: read
|
|
issues: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
validate:
|
|
if: ${{ github.event_name == 'pull_request_target' && (github.event.action != 'labeled' || github.event.label.name == 'recheck') }}
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Create bot app token
|
|
id: bot-app-token
|
|
uses: actions/create-github-app-token@v1
|
|
with:
|
|
app-id: ${{ secrets.A0_BOT_APP_ID }}
|
|
owner: ${{ github.repository_owner }}
|
|
repositories: |
|
|
a0-plugins
|
|
private-key: ${{ secrets.A0_BOT_PRIVATE_KEY }}
|
|
|
|
- name: Resolve PR metadata
|
|
id: pr_meta
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ steps.bot-app-token.outputs.token }}
|
|
script: |
|
|
const pr = context.payload.pull_request;
|
|
const shouldRun = !pr.draft;
|
|
core.setOutput('should_run', shouldRun ? 'true' : 'false');
|
|
core.setOutput('number', String(pr.number));
|
|
core.setOutput('base_sha', pr.base.sha);
|
|
core.setOutput('head_sha', pr.head.sha);
|
|
core.setOutput('head_repo', pr.head.repo.full_name);
|
|
core.setOutput('pr_author', pr.user.login);
|
|
core.setOutput('is_draft', pr.draft ? 'true' : 'false');
|
|
|
|
- name: Fetch PR head commit
|
|
if: ${{ steps.pr_meta.outputs.should_run == 'true' }}
|
|
env:
|
|
HEAD_REPO: ${{ steps.pr_meta.outputs.head_repo }}
|
|
HEAD_SHA: ${{ steps.pr_meta.outputs.head_sha }}
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
git fetch --no-tags --depth=1 "https://x-access-token:${GH_TOKEN}@github.com/${HEAD_REPO}.git" ${HEAD_SHA}
|
|
|
|
- name: Set up Python
|
|
if: ${{ steps.pr_meta.outputs.should_run == 'true' }}
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: Install dependencies
|
|
if: ${{ steps.pr_meta.outputs.should_run == 'true' }}
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
python -m pip install pyyaml pillow
|
|
|
|
- name: Download current index.json (best effort)
|
|
if: ${{ steps.pr_meta.outputs.should_run == 'true' }}
|
|
continue-on-error: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ steps.bot-app-token.outputs.token }}
|
|
INDEX_RELEASE_TAG: generated-index
|
|
run: |
|
|
python scripts/download_index_release.py
|
|
|
|
- name: Validate plugin submission
|
|
id: validate_submission
|
|
if: ${{ steps.pr_meta.outputs.should_run == 'true' }}
|
|
continue-on-error: true
|
|
env:
|
|
BASE_SHA: ${{ steps.pr_meta.outputs.base_sha }}
|
|
HEAD_SHA: ${{ steps.pr_meta.outputs.head_sha }}
|
|
PR_AUTHOR: ${{ steps.pr_meta.outputs.pr_author }}
|
|
GITHUB_TOKEN: ${{ github.token }}
|
|
run: |
|
|
set +e
|
|
python scripts/validate_plugin_submission.py 2>&1 | tee validate_output.txt
|
|
status=${PIPESTATUS[0]}
|
|
reason=$(python -c 'from pathlib import Path; text = Path("validate_output.txt").read_text(encoding="utf-8", errors="replace"); reason = next((line.strip() for line in reversed(text.splitlines()) if line.strip().startswith("ERROR: ")), "Plugin submission validation failed."); print(reason)')
|
|
{
|
|
echo 'comment_body<<EOF'
|
|
echo '## Plugin submission validation failed'
|
|
echo
|
|
echo "$reason"
|
|
echo 'EOF'
|
|
} >> "$GITHUB_OUTPUT"
|
|
exit $status
|
|
|
|
- name: Comment validation failure on PR
|
|
if: ${{ steps.validate_submission.outcome == 'failure' && steps.validate_submission.outputs.comment_body != '' }}
|
|
uses: actions/github-script@v7
|
|
env:
|
|
COMMENT_BODY: ${{ steps.validate_submission.outputs.comment_body }}
|
|
with:
|
|
github-token: ${{ steps.bot-app-token.outputs.token }}
|
|
script: |
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: Number('${{ steps.pr_meta.outputs.number }}'),
|
|
body: process.env.COMMENT_BODY,
|
|
});
|
|
|
|
- name: Fail workflow if validation failed
|
|
if: ${{ steps.validate_submission.outcome == 'failure' }}
|
|
run: |
|
|
echo "Plugin submission validation failed"
|
|
exit 1
|