Skip to content
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

🎨 Using github app for auto merge #194

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/workflows/template_automerge_dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: Dependabot Auto-Merge

on:
workflow_call:
secrets:
app_id:
required: false
private_key:
required: false

jobs:
dependabot:
Expand All @@ -11,12 +16,23 @@ jobs:
runs-on: ubuntu-22.04
if: github.actor == 'dependabot[bot]'

env:
USING_APP_CREDENTIALS: ${{ secrets.app_id != '' && secrets.private_key != '' }}

steps:
- name: Get App Token
if: ${{ env.USING_APP_CREDENTIALS == 'true' }}
uses: tibdex/[email protected]
id: get_token
with:
app_id: ${{ secrets.app_id }}
private_key: ${{ secrets.private_key }}

- name: Load dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ env.USING_APP_CREDENTIALS == 'true' && steps.get_token.outputs.token || secrets.GITHUB_TOKEN }}

- name: Enable auto-merge for Dependabot PRs
if: steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor'
Expand All @@ -25,4 +41,4 @@ jobs:
gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ env.USING_APP_CREDENTIALS == 'true' && steps.get_token.outputs.token || secrets.GITHUB_TOKEN }}
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ In this section you can find examples of how to use template workflows. For more
<details>
<summary>The action can be used to auto-merge a dependabot PR with minor and patch updates.</summary>

The action is called by creating a PR. Dependabot must have ownership of the corresponding dependency files in order to be able to merge the PRs.
The action is called by creating a PR. It is necessary that the repository is enabled for auto-merge.
There are two possibilities to enable the action.
First, you can use the general GitHub token but the actions does not run on the default branch.

```yml
name: Enable Dependabot Auto-Merge
Expand All @@ -43,6 +45,24 @@ jobs:
dependabot:
uses: Staffbase/gha-workflows/.github/workflows/[email protected]
```

Or you can use a specific GitHub app id and private key to generate a new token which can be used for the action.

```yml
name: Enable Dependabot Auto-Merge

on: pull_request

jobs:
dependabot:
uses: Staffbase/gha-workflows/.github/workflows/[email protected]
secrets:
# optional: identifier of the GitHub App for authentication
app_id: ${{ <your-app-id> }}
# optional: private key of the GitHub App
private_key: ${{ <your-private-key> }}
```

</details>

### AutoDev
Expand Down