-
Notifications
You must be signed in to change notification settings - Fork 960
Add workflow to add PR comment flagging maintainers when API changes are made #8274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jack-berg
wants to merge
2
commits into
open-telemetry:main
Choose a base branch
from
jack-berg:detect-api-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,90 @@ | ||
| name: Detect API Changes | ||
|
|
||
| on: | ||
| # pull_request_target is used instead of pull_request so that the workflow has write access | ||
| # (to post comments and apply labels) even when triggered by fork PRs. | ||
| # | ||
| # SECURITY: this workflow must never checkout or execute any code from the PR branch. | ||
| # Doing so would allow malicious PRs to exfiltrate secrets. All we use from the PR | ||
| # is github.event.pull_request.number (an integer), which is safe. | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| detect-api-changes: | ||
| name: Detect API surface area changes | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 | ||
| id: otelbot-token | ||
| with: | ||
| app-id: ${{ vars.OTELBOT_APP_ID }} | ||
| private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }} | ||
|
|
||
| - name: Check for API changes and update PR | ||
| env: | ||
| GH_TOKEN: ${{ steps.otelbot-token.outputs.token }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| MARKER="<!-- api-change-detector -->" | ||
|
|
||
| # Get list of apidiff files changed in this PR | ||
| api_files=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}/files" --paginate \ | ||
| --jq '.[] | select(.filename | startswith("docs/apidiffs/current_vs_latest/")) | .filename') | ||
|
|
||
| # Find existing bot comment (if any) | ||
| comment_id=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" --paginate \ | ||
| --jq ".[] | select(.body | startswith(\"${MARKER}\")) | .id" | head -1) | ||
|
|
||
| if [[ -z "$api_files" ]]; then | ||
| echo "No API diff files changed." | ||
|
|
||
| # Remove label if present (ok to fail if label doesn't exist on PR) | ||
| gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "api-change" 2>/dev/null || true | ||
|
|
||
| # Delete existing comment if present | ||
| if [[ -n "$comment_id" ]]; then | ||
| gh api --method DELETE "repos/${REPO}/issues/comments/${comment_id}" | ||
| echo "Removed stale API change comment." | ||
| fi | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "API diff files changed:" | ||
| echo "$api_files" | ||
|
|
||
| # Add label | ||
| gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "api-change" | ||
|
|
||
| # Build bulleted module list | ||
| modules=$(echo "$api_files" \ | ||
| | sed 's|docs/apidiffs/current_vs_latest/||' \ | ||
| | sed 's|\.txt$||' \ | ||
| | sort \ | ||
| | sed 's/^/- /') | ||
|
|
||
| BODY=$(cat <<EOF | ||
| ${MARKER} | ||
| ## :warning: API changes detected — additional maintainer review required | ||
|
|
||
| @jack-berg @jkwatson | ||
|
|
||
| This PR modifies the public API surface area of the following module(s): | ||
|
|
||
| ${modules} | ||
|
|
||
| Please review the changes in \`docs/apidiffs/current_vs_latest/\` carefully before approving. | ||
| EOF | ||
| ) | ||
|
|
||
| if [[ -n "$comment_id" ]]; then | ||
| echo "Updating existing comment ${comment_id}" | ||
| gh api --method PATCH "repos/${REPO}/issues/comments/${comment_id}" \ | ||
| --field body="$BODY" | ||
| else | ||
| echo "Creating new comment" | ||
| gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$BODY" | ||
| fi | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| name: Survey on Merged PR by Non-Member | ||
|
|
||
| on: | ||
| # pull_request_target is used instead of pull_request so that the workflow has write access | ||
| # (to post comments) even when triggered by fork PRs. | ||
| # | ||
| # SECURITY: this workflow must never checkout or execute any code from the PR branch. | ||
| # Doing so would allow malicious PRs to exfiltrate secrets. All we use from the PR | ||
| # is github.event.pull_request.number (an integer) and author metadata, which are safe. | ||
| pull_request_target: | ||
| types: [closed] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unused. The |
||
| permissions: {} | ||
|
|
||
| env: | ||
| PR_NUM: ${{ github.event.pull_request.number }} | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.