From 9ac0cb16d40d1fc4e13177d30c5d146f0e04caf0 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Thu, 28 May 2026 19:05:51 +0800 Subject: [PATCH] ci: dedupe profile-validation PR comments, clean up on success --- .github/workflows/check_profiles.yml | 14 +++++---- .github/workflows/check_profiles_comment.yml | 30 ++++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/check_profiles.yml b/.github/workflows/check_profiles.yml index d24e27ac89..806470b18b 100644 --- a/.github/workflows/check_profiles.yml +++ b/.github/workflows/check_profiles.yml @@ -101,12 +101,18 @@ jobs: ./OrcaSlicer_profile_validator -p ${{ github.workspace }}/resources/profiles -l 2 2>&1 | tee ${{ runner.temp }}/validate_custom.log exit ${PIPESTATUS[0]} + - name: Prepare PR number for comment workflow + if: ${{ always() && github.event_name == 'pull_request' }} + run: | + mkdir -p ${{ runner.temp }}/profile-check-results + echo "${{ github.event.pull_request.number }}" > ${{ runner.temp }}/profile-check-results/pr_number.txt + - name: Prepare comment artifact if: ${{ always() && github.event_name == 'pull_request' && (steps.extra_json_check.outcome == 'failure' || steps.indentation_check.outcome == 'failure' || steps.validate_system.outcome == 'failure' || steps.validate_custom.outcome == 'failure') }} run: | - mkdir -p ${{ runner.temp }}/profile-check-results - { + # Marker matched by check_profiles_comment.yml to delete prior comments. + echo "" echo "## :x: Profile Validation Errors" echo "" @@ -150,10 +156,8 @@ jobs: echo "*Please fix the above errors and push a new commit.*" } > ${{ runner.temp }}/profile-check-results/pr_comment.md - echo "${{ github.event.pull_request.number }}" > ${{ runner.temp }}/profile-check-results/pr_number.txt - - name: Upload comment artifact - if: ${{ always() && github.event_name == 'pull_request' && (steps.extra_json_check.outcome == 'failure' || steps.indentation_check.outcome == 'failure' || steps.validate_system.outcome == 'failure' || steps.validate_custom.outcome == 'failure') }} + if: ${{ always() && github.event_name == 'pull_request' }} uses: actions/upload-artifact@v7 with: name: profile-check-results diff --git a/.github/workflows/check_profiles_comment.yml b/.github/workflows/check_profiles_comment.yml index 784f99b24a..21098cc467 100644 --- a/.github/workflows/check_profiles_comment.yml +++ b/.github/workflows/check_profiles_comment.yml @@ -10,12 +10,19 @@ on: permissions: pull-requests: write + # Needed to delete outdated bot comments via the issues/comments endpoint. + issues: write + +# Serialize handlers per source branch so parallel runs don't race delete-and-post. +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }} + cancel-in-progress: false jobs: post_comment: name: Post PR comment runs-on: ubuntu-24.04 - if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }} + if: ${{ github.event.workflow_run.event == 'pull_request' && (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure') }} steps: - name: Download artifact id: download @@ -26,14 +33,14 @@ jobs: run-id: ${{ github.event.workflow_run.id }} github-token: ${{ github.token }} - - name: Post comment on PR + - name: Update PR comment if: ${{ steps.download.outcome == 'success' }} env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} run: | - if [ ! -f pr_number.txt ] || [ ! -f pr_comment.md ]; then - echo "No comment artifact found, skipping." + if [ ! -f pr_number.txt ]; then + echo "No pr_number.txt in artifact, skipping." exit 0 fi @@ -43,4 +50,17 @@ jobs: exit 1 fi - gh pr comment "$PR_NUMBER" --body-file pr_comment.md + # Delete prior comments matching the marker (from check_profiles.yml) or the legacy heading. + OLD_IDS=$(gh api --paginate "repos/${GH_REPO}/issues/${PR_NUMBER}/comments" \ + --jq '.[] | select(.user.login == "github-actions[bot]") | select((.body | startswith("")) or (.body | startswith("## :x: Profile Validation Errors"))) | .id') + for comment_id in $OLD_IDS; do + echo "Deleting outdated profile-validation comment ${comment_id}" + gh api -X DELETE "repos/${GH_REPO}/issues/comments/${comment_id}" || true + done + + # Post a new comment only when validation failed (pr_comment.md present). + if [ -f pr_comment.md ]; then + gh pr comment "$PR_NUMBER" --body-file pr_comment.md + else + echo "Validation succeeded; cleaned up prior comments without posting." + fi