-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add reusable renovate-auto-approve workflow #25
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
cbrgm
wants to merge
2
commits into
main
Choose a base branch
from
feat/renovate-auto-approve
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.
+112
−0
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,85 @@ | ||
| name: renovate-auto-approve | ||
|
|
||
| # Reusable workflow. A consuming repo triggers it on pull_request and calls it: | ||
| # | ||
| # jobs: | ||
| # approve: | ||
| # uses: opendefensecloud/dev-kit/.github/workflows/renovate-auto-approve.yml@<sha-or-tag> | ||
| # permissions: | ||
| # pull-requests: write | ||
| # | ||
| # It approves a Renovate PR that carries the automerge label and not the block | ||
| # label (security). If a PR later gains the block label, it revokes its own | ||
| # earlier approval so a human is required again. The merge itself always stays | ||
| # gated on the repo's required status checks. | ||
| # | ||
| # Which update types are eligible (the automerge label) is decided by the | ||
| # renovate-config presets, not here: github>opendefensecloud/renovate-config. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| automerge-label: | ||
| description: Label that marks a Renovate PR as safe to auto-approve. | ||
| type: string | ||
| default: automerge | ||
| block-label: | ||
| description: Label that blocks auto-approval, and revokes an earlier one. | ||
| type: string | ||
| default: security | ||
| renovate-actor: | ||
| description: Login of the Renovate app that authors the pull requests. | ||
| type: string | ||
| default: renovate[bot] | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: renovate-auto-approve-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| auto-approve: | ||
| runs-on: ubuntu-latest | ||
| if: >- | ||
| github.event_name == 'pull_request' && | ||
| github.event.pull_request.user.login == inputs.renovate-actor && | ||
| (contains(github.event.pull_request.labels.*.name, inputs.automerge-label) || | ||
| contains(github.event.pull_request.labels.*.name, inputs.block-label)) | ||
| steps: | ||
| - name: Approve, or revoke a prior approval if the block label appears | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| LABEL: ${{ inputs.automerge-label }} | ||
| BLOCK_LABEL: ${{ inputs.block-label }} | ||
| HAS_BLOCK: ${{ contains(github.event.pull_request.labels.*.name, inputs.block-label) }} | ||
| run: | | ||
| set -euo pipefail | ||
| # Latest review state left by this workflow's identity (github-actions[bot]). | ||
| latest_state=$(gh api "repos/$GH_REPO/pulls/$PR_NUMBER/reviews" \ | ||
| --jq 'map(select((.user.login // "" | ascii_downcase) | startswith("github-actions"))) | last | .state // empty') | ||
| if [ "$HAS_BLOCK" = "true" ]; then | ||
| if [ "$latest_state" = "APPROVED" ]; then | ||
| echo "PR now carries the $BLOCK_LABEL label; revoking the earlier automated approval." | ||
| gh pr review "$PR_NUMBER" --request-changes \ | ||
| --body "Revoked: this PR is now labeled \`$BLOCK_LABEL\` and needs a human review." | ||
| else | ||
| echo "PR carries the $BLOCK_LABEL label; no automated approval to revoke." | ||
| fi | ||
| exit 0 | ||
| fi | ||
| if [ "$latest_state" = "APPROVED" ]; then | ||
| echo "Already approved by github-actions; nothing to do." | ||
| exit 0 | ||
| fi | ||
| # Re-read labels right before approving: the block label may have been | ||
| # added after this run started, concurrently with this approval. | ||
| if gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name' | grep -qxF "$BLOCK_LABEL"; then | ||
| echo "PR now carries the $BLOCK_LABEL label; not approving." | ||
| exit 0 | ||
| fi | ||
| gh pr review "$PR_NUMBER" --approve \ | ||
| --body "Auto-approved: Renovate \`$LABEL\` update. Merge remains gated on required status checks." | ||
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
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,15 @@ | ||
| # Auto-approve Renovate digest/patch/minor PRs so they can automerge. | ||
| # Calls the reusable workflow in opendefensecloud/dev-kit. The automerge policy | ||
| # (which update types are eligible) comes from the renovate-config presets. | ||
| name: renovate-auto-approve | ||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize, labeled, unlabeled] | ||
| permissions: | ||
| pull-requests: write | ||
| jobs: | ||
| approve: | ||
| # Pin @<sha-or-tag> to a dev-kit release tag or commit SHA before using this. | ||
| uses: opendefensecloud/dev-kit/.github/workflows/renovate-auto-approve.yml@<sha-or-tag> | ||
| permissions: | ||
| pull-requests: write |
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.