|
| 1 | +name: Plugin Submission Review |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened, edited] |
| 6 | + issue_comment: |
| 7 | + types: [created, edited] |
| 8 | + |
| 9 | +jobs: |
| 10 | + metadata-validation: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: contains(toJson(github.event.issue.labels.*.name), 'plugin-add') |
| 13 | + outputs: |
| 14 | + needs_repo_check: ${{ steps.validate.outputs.needs_repo_check }} |
| 15 | + repo_url: ${{ steps.extract-repo.outputs.repo_url }} |
| 16 | + repo_branch: ${{ steps.extract-repo.outputs.repo_branch }} |
| 17 | + is_commit: ${{ steps.action.outputs.is_commit }} |
| 18 | + is_revalidate: ${{ steps.action.outputs.is_revalidate }} |
| 19 | + commit_requested: ${{ steps.check-commit.outputs.commit_requested }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + |
| 27 | + - name: Setup Python & uv |
| 28 | + uses: astral-sh/setup-uv@v7 |
| 29 | + with: |
| 30 | + python-version: 3.11 |
| 31 | + activate-environment: true |
| 32 | + |
| 33 | + - name: Cache Python dependencies |
| 34 | + uses: actions/cache@v4 |
| 35 | + with: |
| 36 | + path: | |
| 37 | + ~/.cache/uv |
| 38 | + ~\AppData\Local\uv |
| 39 | + key: ${{ runner.os }}-uv-cache-${{ hashFiles('uv.lock') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-uv-cache- |
| 42 | +
|
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + uv pip install pydantic requests |
| 46 | +
|
| 47 | + - name: Determine action type |
| 48 | + id: action |
| 49 | + run: | |
| 50 | + if [[ "${{ github.event.comment.body }}" == *"执行提交"* ]] || [[ "${{ github.event.issue.body }}" == *"[x] 执行提交"* ]]; then |
| 51 | + echo "is_commit=true" >> $GITHUB_OUTPUT |
| 52 | + else |
| 53 | + echo "is_commit=false" >> $GITHUB_OUTPUT |
| 54 | + fi |
| 55 | + if [[ "${{ github.event.comment.body }}" == *"重新验证"* ]] || [[ "${{ github.event.issue.body }}" == *"[x] 重新验证"* ]]; then |
| 56 | + echo "is_revalidate=true" >> $GITHUB_OUTPUT |
| 57 | + else |
| 58 | + echo "is_revalidate=false" >> $GITHUB_OUTPUT |
| 59 | + fi |
| 60 | +
|
| 61 | + - name: Run validation |
| 62 | + id: validate |
| 63 | + env: |
| 64 | + ISSUE_BODY: ${{ github.event.issue.body }} |
| 65 | + COMMENT_BODY: ${{ github.event.comment.body }} |
| 66 | + IS_COMMIT: ${{ steps.action.outputs.is_commit }} |
| 67 | + IS_REVALIDATE: ${{ steps.action.outputs.is_revalidate }} |
| 68 | + run: uv run scripts/plugin_validation.py |
| 69 | + |
| 70 | + - name: Check commit flag |
| 71 | + id: check-commit |
| 72 | + run: | |
| 73 | + if [ -f artifacts/commit.flag ]; then |
| 74 | + echo "commit_requested=true" >> $GITHUB_OUTPUT |
| 75 | + else |
| 76 | + echo "commit_requested=false" >> $GITHUB_OUTPUT |
| 77 | + fi |
| 78 | +
|
| 79 | + - name: Extract repository info |
| 80 | + id: extract-repo |
| 81 | + if: steps.validate.outputs.needs_repo_check == 'true' |
| 82 | + run: | |
| 83 | + if [ -f artifacts/validation_result.json ]; then |
| 84 | + repo_url=$(uv run python -c "import json; data=json.load(open('artifacts/validation_result.json')); print(data['registry_item']['url'])") |
| 85 | + repo_branch=$(uv run python -c "import json; data=json.load(open('artifacts/validation_result.json')); print(data['registry_item']['branch'])") |
| 86 | + repo_path=$(echo "$repo_url" | sed 's|https://github.com/||' | sed 's|/$||') |
| 87 | + echo "repo_url=$repo_path" >> $GITHUB_OUTPUT |
| 88 | + echo "repo_branch=$repo_branch" >> $GITHUB_OUTPUT |
| 89 | + fi |
| 90 | +
|
| 91 | + - name: Upload validation artifacts |
| 92 | + uses: actions/upload-artifact@v4 |
| 93 | + with: |
| 94 | + name: validation-results |
| 95 | + path: artifacts/ |
| 96 | + retention-days: 1 |
| 97 | + |
| 98 | + repository-check: |
| 99 | + runs-on: ubuntu-latest |
| 100 | + needs: metadata-validation |
| 101 | + if: needs.metadata-validation.outputs.needs_repo_check == 'true' |
| 102 | + outputs: |
| 103 | + repo_check_success: ${{ steps.repo-check.outputs.repo_check_success }} |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Checkout main repository |
| 107 | + uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + |
| 111 | + - name: Setup Python & uv |
| 112 | + uses: astral-sh/setup-uv@v7 |
| 113 | + with: |
| 114 | + python-version: 3.11 |
| 115 | + activate-environment: true |
| 116 | + |
| 117 | + - name: Cache Python dependencies |
| 118 | + uses: actions/cache@v4 |
| 119 | + with: |
| 120 | + path: | |
| 121 | + ~/.cache/uv |
| 122 | + ~\AppData\Local\uv |
| 123 | + key: ${{ runner.os }}-uv-cache-${{ hashFiles('uv.lock') }} |
| 124 | + restore-keys: | |
| 125 | + ${{ runner.os }}-uv-cache- |
| 126 | +
|
| 127 | + - name: Install dependencies |
| 128 | + run: | |
| 129 | + uv pip install pydantic requests |
| 130 | +
|
| 131 | + - name: Checkout plugin repository |
| 132 | + uses: actions/checkout@v4 |
| 133 | + with: |
| 134 | + repository: ${{ needs.metadata-validation.outputs.repo_url }} |
| 135 | + ref: ${{ needs.metadata-validation.outputs.repo_branch }} |
| 136 | + path: plugin-repo |
| 137 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + |
| 139 | + - name: Run repository check |
| 140 | + id: repo-check |
| 141 | + continue-on-error: true |
| 142 | + env: |
| 143 | + REPO_DIR: plugin-repo |
| 144 | + run: | |
| 145 | + uv run scripts/repo_check.py |
| 146 | + if [ -f artifacts/repo_check_result.json ]; then |
| 147 | + repo_success=$(uv run python -c "import json; print(json.load(open('artifacts/repo_check_result.json'))['success'])") |
| 148 | + echo "repo_check_success=$repo_success" >> $GITHUB_OUTPUT |
| 149 | + else |
| 150 | + echo "repo_check_success=false" >> $GITHUB_OUTPUT |
| 151 | + fi |
| 152 | +
|
| 153 | + - name: Upload repository check artifacts |
| 154 | + uses: actions/upload-artifact@v4 |
| 155 | + with: |
| 156 | + name: repo-check-results |
| 157 | + path: artifacts/ |
| 158 | + retention-days: 1 |
| 159 | + |
| 160 | + integration: |
| 161 | + runs-on: ubuntu-latest |
| 162 | + needs: [metadata-validation, repository-check] |
| 163 | + if: always() && needs.metadata-validation.result == 'success' |
| 164 | + |
| 165 | + steps: |
| 166 | + - name: Checkout repository |
| 167 | + uses: actions/checkout@v4 |
| 168 | + with: |
| 169 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 170 | + |
| 171 | + - name: Setup Python & uv |
| 172 | + uses: astral-sh/setup-uv@v7 |
| 173 | + with: |
| 174 | + python-version: 3.11 |
| 175 | + activate-environment: true |
| 176 | + |
| 177 | + - name: Cache Python dependencies |
| 178 | + uses: actions/cache@v4 |
| 179 | + with: |
| 180 | + path: | |
| 181 | + ~/.cache/uv |
| 182 | + ~\AppData\Local\uv |
| 183 | + key: ${{ runner.os }}-uv-cache-${{ hashFiles('uv.lock') }} |
| 184 | + restore-keys: | |
| 185 | + ${{ runner.os }}-uv-cache- |
| 186 | +
|
| 187 | + - name: Install dependencies |
| 188 | + run: | |
| 189 | + uv pip install pydantic requests |
| 190 | +
|
| 191 | + - name: Download validation artifacts |
| 192 | + uses: actions/download-artifact@v4 |
| 193 | + with: |
| 194 | + name: validation-results |
| 195 | + path: validation-artifacts/ |
| 196 | + |
| 197 | + - name: Download repository check artifacts |
| 198 | + if: needs.metadata-validation.outputs.needs_repo_check == 'true' |
| 199 | + uses: actions/download-artifact@v4 |
| 200 | + with: |
| 201 | + name: repo-check-results |
| 202 | + path: repo-check-artifacts/ |
| 203 | + continue-on-error: true |
| 204 | + |
| 205 | + - name: Combine results and prepare final comment |
| 206 | + run: | |
| 207 | + mkdir -p final-artifacts |
| 208 | + if [ -f validation-artifacts/comment.md ]; then |
| 209 | + cp validation-artifacts/comment.md final-artifacts/comment.md |
| 210 | + else |
| 211 | + echo "<!-- plugin-review -->" > final-artifacts/comment.md |
| 212 | + echo "❌ **处理过程中出现错误**" >> final-artifacts/comment.md |
| 213 | + echo "" >> final-artifacts/comment.md |
| 214 | + fi |
| 215 | + if [ -f repo-check-artifacts/repo_check_result.json ]; then |
| 216 | + repo_success=$(uv run python -c "import json; print(json.load(open('repo-check-artifacts/repo_check_result.json'))['success'])" 2>/dev/null || echo "false") |
| 217 | + # if [ -f repo-check-artifacts/repo_check_comment.md ]; then |
| 218 | + # echo "" >> final-artifacts/comment.md |
| 219 | + # echo "---" >> final-artifacts/comment.md |
| 220 | + # echo "" >> final-artifacts/comment.md |
| 221 | + # sed '1s/<!-- plugin-review -->//' repo-check-artifacts/repo_check_comment.md >> final-artifacts/comment.md |
| 222 | + # fi |
| 223 | + fi |
| 224 | +
|
| 225 | + - name: Find bot comment |
| 226 | + id: find-comment |
| 227 | + uses: peter-evans/find-comment@v3 |
| 228 | + with: |
| 229 | + issue-number: ${{ github.event.issue.number }} |
| 230 | + comment-author: "github-actions[bot]" |
| 231 | + body-includes: "<!-- plugin-review -->" |
| 232 | + |
| 233 | + - name: Create or update comment |
| 234 | + uses: peter-evans/create-or-update-comment@v3 |
| 235 | + with: |
| 236 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 237 | + issue-number: ${{ github.event.issue.number }} |
| 238 | + body-path: final-artifacts/comment.md |
| 239 | + edit-mode: replace |
| 240 | + |
| 241 | + - name: Update Issue body if revalidate |
| 242 | + if: needs.metadata-validation.outputs.is_revalidate == 'true' |
| 243 | + run: | |
| 244 | + if [ -f validation-artifacts/updated_issue_body.txt ]; then |
| 245 | + gh issue edit ${{ github.event.issue.number }} --body-file validation-artifacts/updated_issue_body.txt |
| 246 | + fi |
| 247 | + env: |
| 248 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 249 | + |
| 250 | + - name: Fixes for changes |
| 251 | + id: pre-commit |
| 252 | + uses: j178/prek-action@v1 |
| 253 | + if: needs.metadata-validation.outputs.is_commit == 'true' && (needs.metadata-validation.outputs.needs_repo_check == 'false' || needs.repository-check.outputs.repo_check_success == 'True' || needs.repository-check.outputs.repo_check_success == 'true') |
| 254 | + continue-on-error: true |
| 255 | + |
| 256 | + - name: Import GPG key |
| 257 | + id: import-gpg-compile |
| 258 | + uses: crazy-max/ghaction-import-gpg@v6 |
| 259 | + if: needs.metadata-validation.outputs.is_commit == 'true' && (needs.metadata-validation.outputs.needs_repo_check == 'false' || needs.repository-check.outputs.repo_check_success == 'True' || needs.repository-check.outputs.repo_check_success == 'true') |
| 260 | + continue-on-error: true |
| 261 | + with: |
| 262 | + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 263 | + passphrase: ${{ secrets.GPG_PASSPHRASE }} |
| 264 | + git_user_signingkey: true |
| 265 | + git_commit_gpgsign: true |
| 266 | + |
| 267 | + - name: Commit plugin to registry |
| 268 | + uses: stefanzweifel/git-auto-commit-action@v7 |
| 269 | + id: commit-file |
| 270 | + if: needs.metadata-validation.outputs.is_commit == 'true' && (needs.metadata-validation.outputs.needs_repo_check == 'false' || needs.repository-check.outputs.repo_check_success == 'True' || needs.repository-check.outputs.repo_check_success == 'true') |
| 271 | + continue-on-error: true |
| 272 | + with: |
| 273 | + commit_message: | |
| 274 | + chore: Add plugin from issue #${{ github.event.issue.number }} |
| 275 | + - 提交触发者: ${{ github.actor }} |
| 276 | + - 工作流运行: ${{ github.run_id }} (${{ github.event_name }}) |
| 277 | +
|
| 278 | + Co-authored-by: "ChimeYao-bot <ChimeYao@outlook.jp>" |
| 279 | + commit_options: "--no-verify --signoff" |
| 280 | + file_pattern: "Plugins/plugin_list.json" |
| 281 | + commit_user_name: "ChimeYao-bot" |
| 282 | + commit_user_email: "ChimeYao@outlook.jp" |
| 283 | + commit_author: "${{ github.event.issue.user.login }} <${{ github.event.issue.user.id }}+${{ github.event.issue.user.login }}@users.noreply.github.com>" |
| 284 | + |
| 285 | + - name: Update comment with commit status |
| 286 | + if: steps.commit-file.outcome == 'success' |
| 287 | + uses: peter-evans/create-or-update-comment@v3 |
| 288 | + with: |
| 289 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 290 | + issue-number: ${{ github.event.issue.number }} |
| 291 | + body-path: final-artifacts/comment.md |
| 292 | + edit-mode: replace |
| 293 | + |
| 294 | + - name: Close issue after successful commit |
| 295 | + if: steps.commit-file.outcome == 'success' |
| 296 | + run: | |
| 297 | + gh issue close ${{ github.event.issue.number }} |
| 298 | + env: |
| 299 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 300 | + |
| 301 | + - name: Add revalidate checkbox to issue |
| 302 | + if: needs.metadata-validation.outputs.commit_requested == 'false' |
| 303 | + run: | |
| 304 | + current_body=$(gh issue view ${{ github.event.issue.number }} --json body -q .body) |
| 305 | + if ! echo "$current_body" | grep -q "重新验证"; then |
| 306 | + echo "$current_body" > temp_body.txt |
| 307 | + echo "" >> temp_body.txt |
| 308 | + echo "---" >> temp_body.txt |
| 309 | + echo "**操作选项:**" >> temp_body.txt |
| 310 | + echo "- [ ] 重新验证" >> temp_body.txt |
| 311 | +
|
| 312 | + gh issue edit ${{ github.event.issue.number }} --body-file temp_body.txt |
| 313 | + fi |
| 314 | + env: |
| 315 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments