Skip to content

Assist automerge of Renovate pull requests in GitHub Actions

License

Notifications You must be signed in to change notification settings

int128/renovate-merge-bot

Repository files navigation

renovate-merge-bot ts

This is an action for auto-merge of Renovate pull requests.

Purpose

Problem to solve

Renovate supports the great feature of automerge, but we need to consider the following edge cases:

If any commit is added to a pull request, Renovate does not merge it.

image

If the commit status is unknown, Renovate does not merge it. For example, a workflow adds a commit using GITHUB_TOKEN which does not trigger GitHub Actions.

image

How to solve

If the following conditions are satisfied, this action adds an empty commit to trigger GitHub Actions.

  • The pull request is open
  • The pull request is created by Renovate
  • The pull request is mergeable
  • The commit status is unknown
  • The last committer is GITHUB_TOKEN

If the following conditions are satisfied, this action merges it.

  • The pull request is open
  • The pull request is created by Renovate
  • The pull request is mergeable
  • The commit status is success
  • The last commit was created at least 1 hour ago

Finally, a pull request is automatically merged even if a commit was added using GITHUB_TOKEN.

Here is the example of #5.

image

Getting Started

Create GitHub App

Create your GitHub App from this link. Here are the required permissions:

  • Contents: read and write
  • Pull Requests: read and write
  • Workflows: read and write

Install the GitHub App to your repositories.

Create repository and workflow

Create a new repository. Add the following secrets:

  • BOT_APP_ID = App ID of the GitHub App
  • BOT_APP_PRIVATE_KEY = Private key of the GitHub App

Create a workflow.

name: run

on:
  workflow_dispatch:
  schedule:
    - cron: '0 * * * *'

jobs:
  renovate-merge-bot:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: int128/renovate-merge-bot@v1
        with:
          github-app-id: ${{ secrets.BOT_APP_ID }}
          github-app-private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}

Confirm the behavior

When the workflow runs, this action finds open pull requests from repositories which the GitHub App is installed. It executes either of the following actions:

  • Add an empty commit to trigger GitHub Actions
  • Merge the pull request
  • Leave (it will be merged by user)

Specification

Inputs

Name Default Description
github-app-id (required) GitHub App ID
github-app-private-key (required) GitHub App private key
dry-run false Dry-run

Outputs

None.