-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Determine API Changes and comment on PR
Signed-off-by: Thomas Farr <[email protected]>
- Loading branch information
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Comment on PR | ||
description: Creates or updates a comment on a PR | ||
inputs: | ||
pr-number: | ||
description: The number of the PR to comment on | ||
required: true | ||
comment-search-string: | ||
description: String to use to locate a previous comment to update | ||
required: true | ||
body: | ||
description: String to use as the body for the created comment | ||
default: '' | ||
body-path: | ||
description: Path to a file containing the body to use for the created comment | ||
default: '' | ||
outputs: {} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Find Existing Comment | ||
uses: peter-evans/find-comment@v3 | ||
id: fc | ||
with: | ||
issue-number: ${{ inputs.pr-number }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: ${{ inputs.comment-search-string }} | ||
|
||
- name: Create or Update Comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ inputs.pr-number }} | ||
body: ${{ inputs.body }} | ||
body-path: ${{ inputs.body-path }} | ||
edit-mode: replace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Comment with API Changes Summary | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Determine API Changes"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
comment: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
.github | ||
- name: Download Changes Summary | ||
uses: actions/download-artifact@v4 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
name: changes-summary | ||
run-id: ${{ github.event.workflow_run.id }} | ||
|
||
- name: 'Comment on PR' | ||
uses: ./.github/actions/comment-on-pr | ||
with: | ||
pr-number: ${{ github.event.workflow_run.pull_requests[0].number }} | ||
comment-search-string: '## API Changes Summary' | ||
body-path: changes-summary.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: Determine API Changes | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
determine-changes: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Determine Branch Point | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
{ | ||
echo "BRANCH_POINT_SHA=$(git merge-base "$BASE_SHA" "$HEAD_SHA")" | ||
echo "HEAD_SHA=${HEAD_SHA}" | ||
} | tee "$GITHUB_ENV" | ||
env: | ||
HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
|
||
- name: Checkout Original Spec | ||
shell: bash -eo pipefail {0} | ||
run: git checkout $BRANCH_POINT_SHA | ||
|
||
- name: Build Original Spec | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
npm install | ||
npm run merge -- --source ./spec --output /tmp/opensearch-openapi-ORIGINAL.yaml | ||
- name: Checkout Changed Spec | ||
shell: bash -eo pipefail {0} | ||
run: git checkout $HEAD_SHA | ||
|
||
- name: Build Changed Spec | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
npm install | ||
npm run merge -- --source ./spec --output /tmp/opensearch-openapi-CHANGED.yaml | ||
- name: Install openapi-changes | ||
shell: bash -eo pipefail {0} | ||
run: npm install --global @pb33f/openapi-changes | ||
|
||
- name: Generate Report | ||
shell: bash -eo pipefail {0} | ||
run: openapi-changes html-report --no-logo --no-color /tmp/opensearch-openapi-ORIGINAL.yaml /tmp/opensearch-openapi-CHANGED.yaml | ||
|
||
- name: Upload Report | ||
id: upload-report | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: changes-report | ||
path: | | ||
report.html | ||
/tmp/opensearch-openapi-ORIGINAL.yaml | ||
/tmp/opensearch-openapi-CHANGED.yaml | ||
- name: Generate Summary | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
if ! openapi-changes summary --no-logo --no-color --markdown /tmp/opensearch-openapi-ORIGINAL.yaml /tmp/opensearch-openapi-CHANGED.yaml >output.md ; then | ||
if ! grep -q 'breaking changes discovered' output.md ; then | ||
cat output.md >/dev/stderr | ||
exit 1 | ||
fi | ||
fi | ||
gawk -v HEAD_SHA="${HEAD_SHA}" -v REPORT_URL="${REPORT_URL}" ' | ||
BEGIN { | ||
print "## API Changes Summary" | ||
RS = "(\r|\n|\r\n)" | ||
WAS_BLANK = 0 | ||
HAD_CHANGES = 0 | ||
} | ||
/^starting work/ || /^Building original model/ || /^SPEC: extracted/ || /^ERROR: breaking/ || /^DONE: completed/ { | ||
next | ||
} | ||
/^[[:space:]]*$/ { | ||
WAS_BLANK = 1 | ||
next | ||
} | ||
WAS_BLANK { | ||
WAS_BLANK = 0 | ||
print "" | ||
} | ||
{ | ||
HAD_CHANGES = 1 | ||
sub(/Commit: New:/, "Commit: " HEAD_SHA ", New:") | ||
} | ||
END { | ||
if (!HAD_CHANGES) { | ||
print "Commit: " HEAD_SHA ", **NO CHANGES**\n" | ||
} | ||
print "\nFull Report: " REPORT_URL | ||
} | ||
' output.md | tee changes-summary.md | ||
env: | ||
REPORT_URL: ${{ steps.upload-report.outputs.artifact-url }} | ||
|
||
- name: Upload Summary | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: changes-summary | ||
path: changes-summary.md |