diff --git a/.github/workflows/change.yaml b/.github/workflows/change.yaml index acc25733a..53a20d314 100644 --- a/.github/workflows/change.yaml +++ b/.github/workflows/change.yaml @@ -16,6 +16,8 @@ jobs: with: fetch-depth: 0 + - run: git fetch --depth=1 --tags + - uses: actions/setup-python@v5 with: python-version: "3.12" @@ -25,17 +27,52 @@ jobs: id: check run: | pip install griffe - griffe check "openfe" --verbose + griffe check "openfe" --verbose -a origin/main + griffe check "openfecli" --verbose -a origin/main - - name: Post Comment on Failure - if: steps.check.outcome == 'failure' + - name: Manage PR Comments uses: actions/github-script@v7 with: script: | const prNumber = context.payload.pull_request.number; - github.rest.issues.createComment({ + const identifier = ''; + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const stepUrl = `${runUrl}#step:check`; + + // Determine the outcome of the check step + const checkStepOutcome = '${{ steps.check.outcome }}'; + + // List existing comments + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, - body: '🚨 API breaking changes detected! 🚨' }); + + // Delete previous comments from this action + for (const comment of comments) { + if (comment.body.includes(identifier)) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + }); + } + } + + // Post a new comment only if the check step failed + if (checkStepOutcome === 'failure') { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: `${identifier}\n🚨 API breaking changes detected! 🚨\n[View logs for this step](${stepUrl})` + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: `${identifier}\nNo API break detected ✅` + }); + }