From db4f7c6a0c5b1539ca9700ee475601ac9f7ad2c5 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 7 Jul 2026 22:37:23 +0800 Subject: [PATCH] feat: separate workflow for posting test bot comments --- .github/workflows/post-test-bot-comment.yml | 48 +++++++++++++++++++++ .github/workflows/tests.yml | 27 +++++------- 2 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/post-test-bot-comment.yml diff --git a/.github/workflows/post-test-bot-comment.yml b/.github/workflows/post-test-bot-comment.yml new file mode 100644 index 00000000..2da0878f --- /dev/null +++ b/.github/workflows/post-test-bot-comment.yml @@ -0,0 +1,48 @@ +name: Post Test Bot Comment + +on: + workflow_run: + workflows: ["v3 Tests"] + types: [completed] + +permissions: + pull-requests: write + actions: read + +jobs: + post-comment: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Download bot output + id: download + uses: actions/download-artifact@v4 + continue-on-error: true + with: + name: bot-output + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Post/Update comment + if: steps.download.outcome == 'success' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + COMMENT_BODY=$(jq -r '.comment_body' bot-output.json) + PR_NUMBER=$(jq -r '.pr_number' bot-output.json) + MARKER="" + + # Find existing bot comment id + EXISTING_ID=$(gh api \ + "repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" \ + --jq "[.[] | select(.body | startswith(\"${MARKER}\")) | .id] | first // empty") + + if [ -n "$EXISTING_ID" ]; then + gh api --method PATCH \ + "repos/${{ github.repository }}/issues/comments/${EXISTING_ID}" \ + -f body="$COMMENT_BODY" + else + gh pr comment "$PR_NUMBER" \ + --repo "${{ github.repository }}" \ + --body "$COMMENT_BODY" + fi diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a62fcc0a..34dbf959 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -131,7 +131,6 @@ jobs: if: needs.check-gate.outputs.enabled == 'true' runs-on: ubuntu-latest permissions: - pull-requests: write contents: read outputs: need_test: ${{ steps.bot.outputs.need_test }} @@ -168,23 +167,17 @@ jobs: echo "php_versions=$(echo "$BOT_JSON" | jq -c '.php_versions')" >> "$GITHUB_OUTPUT" echo "tier2=$(echo "$BOT_JSON" | jq -r '.tier2')" >> "$GITHUB_OUTPUT" - COMMENT_BODY=$(echo "$BOT_JSON" | jq -r '.comment_body') - MARKER="" + # Save JSON for the comment-posting workflow + jq -n --argjson bot "$BOT_JSON" \ + --arg pr '${{ github.event.pull_request.number }}' \ + '$bot + {pr_number: $pr}' > bot-output.json - # Find existing bot comment id - EXISTING_ID=$(gh api \ - repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \ - --jq "[.[] | select(.body | startswith(\"$MARKER\")) | .id] | first // empty") - - if [ -n "$EXISTING_ID" ]; then - gh api --method PATCH \ - repos/${{ github.repository }}/issues/comments/"$EXISTING_ID" \ - -f body="$COMMENT_BODY" - else - gh pr comment ${{ github.event.pull_request.number }} \ - --repo ${{ github.repository }} \ - --body "$COMMENT_BODY" - fi + - name: Upload bot output + uses: actions/upload-artifact@v4 + with: + name: bot-output + path: bot-output.json + retention-days: 1 gen-matrix: name: "Generate test matrix"