-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
522 additions
and
19 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,176 @@ | ||
name: Analyze PR Changes | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
analyze: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Environment Variables | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
{ | ||
echo "BEFORE_SHA=$(git merge-base "$BASE_SHA" "$HEAD_SHA")" | ||
echo "AFTER_SHA=${HEAD_SHA}" | ||
echo "CLUSTER_SPEC=/tmp/opensearch-openapi-CLUSTER.yaml" | ||
echo "BEFORE_SPEC=/tmp/opensearch-openapi-${BEFORE_SHA}.yaml" | ||
echo "AFTER_SPEC=/tmp/opensearch-openapi-${AFTER_SHA}.yaml" | ||
} | tee "$GITHUB_ENV" | ||
env: | ||
HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
|
||
- name: Dump OpenSearch Cluster's API | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
docker build coverage --tag opensearch-with-api-plugin | ||
docker run \ | ||
--name opensearch \ | ||
--rm -d \ | ||
-p 9200:9200 -p 9600:9600 \ | ||
-e "discovery.type=single-node" \ | ||
-e OPENSEARCH_INITIAL_ADMIN_PASSWORD="$OPENSEARCH_PASSWORD" \ | ||
opensearch-with-api-plugin | ||
npm install | ||
npm run dump-cluster-spec -- --insecure --output $CLUSTER_SPEC | ||
docker stop opensearch | ||
env: | ||
OPENSEARCH_PASSWORD: BobgG7YrtsdKf9M | ||
|
||
- name: Checkout BEFORE Spec | ||
shell: bash -eo pipefail {0} | ||
run: git checkout $BEFORE_SHA | ||
|
||
- name: Build BEFORE Spec | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
npm install | ||
npm run merge -- --source ./spec --output $BEFORE_SPEC | ||
- name: Checkout AFTER Spec | ||
shell: bash -eo pipefail {0} | ||
run: git checkout $AFTER_SHA | ||
|
||
- name: Build AFTER Spec | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
npm install | ||
npm run merge -- --source ./spec --output $AFTER_SPEC | ||
- name: Calculate Coverage | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
for sha in ${BEFORE_SHA} ${AFTER_SHA} ; do | ||
echo "Calculating coverage of ${sha}" | ||
npm run coverage:spec -- \ | ||
--cluster $CLUSTER_SPEC \ | ||
--specification /tmp/opensearch-openapi-${sha}.yaml \ | ||
--output /tmp/coverage-api-${sha}.json | ||
done | ||
jq . /tmp/coverage-api-${AFTER_SHA}.json | ||
jq -r --slurp ' | ||
[ .[].counts ] | ||
| { | ||
covered_before: .[0].covered, | ||
covered_before_pct: .[0].covered_pct, | ||
covered_after: .[1].covered, | ||
covered_after_pct: .[1].covered_pct, | ||
total_to_cover: .[1].covered + .[1].uncovered, | ||
covered_delta: .[1].covered - .[0].covered, | ||
covered_pct_delta: (.[1].covered_pct - .[0].covered_pct) * 100 | round / 100 | ||
} | ||
' \ | ||
/tmp/coverage-api-${BEFORE_SHA}.json \ | ||
/tmp/coverage-api-${AFTER_SHA}.json \ | ||
| tee ./coverage-api-${BEFORE_SHA}-${AFTER_SHA}-DIFF.json | ||
- name: Upload Coverage Data | ||
id: upload-coverage | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-api | ||
path: | | ||
/tmp/coverage-api-*.json | ||
- name: Install openapi-changes | ||
shell: bash -eo pipefail {0} | ||
run: npm install --global @pb33f/openapi-changes | ||
|
||
- name: Generate HTML Report | ||
shell: bash -eo pipefail {0} | ||
run: openapi-changes html-report --no-logo --no-color $BEFORE_SPEC $AFTER_SPEC | ||
|
||
- name: Upload HTML Report | ||
id: upload-report | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: changes-report | ||
path: | | ||
report.html | ||
/tmp/opensearch-openapi-*.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 AFTER_SHA="${AFTER_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: " AFTER_SHA ", New:") | ||
} | ||
END { | ||
if (!HAD_CHANGES) { | ||
print "Commit: " AFTER_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 |
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 |
Oops, something went wrong.