Skip to content

Publish API Breaking Change Check Results #138

Publish API Breaking Change Check Results

Publish API Breaking Change Check Results #138

---
name: Publish API Breaking Change Check Results
on:
workflow_run:
workflows: [Check Public API for Breaking Changes]
types: [completed]
workflow_call:
jobs:
publish-test-results:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && !contains(fromJSON('["skipped", "cancelled", "failed"]'), github.event.workflow_run.conclusion) }}
permissions:
checks: write
pull-requests: write
steps:
- name: Download and Extract Artifacts
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
name: breaking_changes
path: artifacts
- name: Check for breaking changes
run: |
if grep -Pzl '\n```\n```' artifacts/breaking_changes.md; then
echo "BREAKING_CHANGES=false" >> $GITHUB_ENV
else
echo "BREAKING_CHANGES=true" >> $GITHUB_ENV
fi
- name: Fetch PR number
id: pr
uses: actions/github-script@v7
with:
script: |
const maxAttempts = 5;
let attempt = 0;
let pullRequestNumber;
while (attempt < maxAttempts) {
try {
const response = await github.rest.search.issuesAndPullRequests({
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',
per_page: 1,
});
const items = response.data.items;
if (items.length < 1) {
throw new Error('No PRs found');
}
pullRequestNumber = items[0].number;
console.info("Pull request number is", pullRequestNumber);
break; // Exit loop on success
} catch (error) {
console.error(`Attempt ${attempt + 1} failed:`, error.message);
if (attempt < maxAttempts - 1) { // Check if not last attempt
console.log(`Waiting for 2 minutes before retrying...`);
await new Promise(resolve => setTimeout(resolve, 120000)); // Wait for 2 minutes
}
}
attempt++;
}
if (!pullRequestNumber) {
core.setFailed("Failed to fetch PR number after 5 attempts");
}
return pullRequestNumber;
- name: Publish API Breaking Changes Check Results
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ env.BREAKING_CHANGES == 'true' }}
with:
header: breaking-api-changes
number: ${{ steps.pr.outputs.result }}
recreate: true
path: artifacts/breaking_changes.md
- name: Add workflow link to comment
if: ${{ env.BREAKING_CHANGES == 'true' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: breaking-api-changes
number: ${{ steps.pr.outputs.result }}
append: true
message: |-
<p><a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}">Link to workflow run</a></p>
- name: Delete comment if no breaking changes are found
if: ${{ env.BREAKING_CHANGES == 'false' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: breaking-api-changes
number: ${{ steps.pr.outputs.result }}
delete: true