Skip to content

Publish API Breaking Change Check Results #3

Publish API Breaking Change Check Results

Publish API Breaking Change Check Results #3

---
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@v3.1.4
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 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) {
console.error('No PRs found')
return
}
const pullRequestNumber = items[0].number
console.info("Pull request number is", pullRequestNumber)
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