Skip to content

ramonvermeulen/pre-commit-bump

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

pre-commit-bump

Go Report Card Go Reference

Dev tool to automatically bump the pre-commit hook versions in your .pre-commit-config.yaml file. Mainly build for learning purposes, but can be useful for automating the process of updating pre-commit hooks.

Installation

You can install pre-commit-bump using go install:

go install github.com/ramonvermeulen/pre-commit-bump@latest

Basic Usage

pre-commit-bump is a command-line tool designed to help you manage and update pre-commit hooks in your projects.

Usage:
  pre-commit-bump [command]

Available Commands:
  check       Check for available updates without modifying the ".pre-commit-config.yaml" file
  help        Help about any command
  update      Check for available updates and modify the ".pre-commit-config.yaml" file

Flags:
  -a, --allow string    Version bump type to allow (major, minor, patch) (default "major")
  -c, --config string   Path to the pre-commit configuration file (default ".pre-commit-config.yaml")
  -h, --help            help for pre-commit-bump
  -v, --verbose         Enable verbose logging output

Use "pre-commit-bump [command] --help" for more information about a command.

pre-commit

Ironically you can use pre-commit-bump as a pre-commit hook itself to always keep your pre-commit hooks up to date. Add the following to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/ramonvermeulen/pre-commit-bump
    rev: v1.0.2
    hooks:
      - id: pre-commit-bump

By default, it runs with pre-commit-bump update --no-summary --verbose. You can override this by adding args to the hook configuration.

GitHub Actions

There are two ways to use pre-commit-bump in your GitHub Actions workflow:

1) pre-commit-bump PR action

This action combines the ramonvermeulen/pre-commit-bump action with the peter-evans/create-pull-request action to automatically create a pull request with the updated pre-commit hook versions. Unfortunately, this will not work for private repositories on the GitHub free plan.

"Draft pull requests are available in public repositories with GitHub Free and GitHub Free for organizations, GitHub Pro, and legacy per-repository billing plans, and in public and private repositories with GitHub Team and GitHub Enterprise Cloud."

Also ensure the following setting is enabled in your repository settings -> actions -> general:

setting.png

name: Bump pre-commit hooks

on:
  schedule:
    - cron: '0 0 * * *' # Every day at midnight
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write
  
jobs:
  pre-commit-bump:
    name: Run pre-commit-bump
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Update pre-commit hooks
        uses: ramonvermeulen/pre-commit-bump/gha/bot@v1
        with:
          command: update
          allow: major
          verbose: true

Example of a pull request created by the action: example_1.png

example_2.png

2) pre-commit-bump standalone action

The standalone action is mostly used for checking the pre-commit hooks without creating a pull request. This is useful for CI/CD pipelines to ensure that the pre-commit hooks are up-to-date, the action will fail if there are updates available. The potential updates will be logged in the GitHub actions log.

name: Check pre-commit hooks

on:
  schedule:
    - cron: '0 0 * * *' # Every day at midnight
  workflow_dispatch:
  
jobs:
  lint:
    name: Pre-Commit Bump
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Pre-Commit Bump
        uses: ramonvermeulen/pre-commit-bump@v1
        with:
          command: check
          allow: major
          verbose: true

Action inputs

All inputs are optional. If not set, sensible defaults will be used.

Name Description Default
command Command to run, can be either update or check. update
allow Specific semantic versioning range to allow updates for (major, minor, or patch). major
verbose Whether to run in verbose mode. false
config Path to the pre-commit configuration file, uses .pre-commit-config.yaml if not specified. pre-commit-config.yaml
no-summary Whether to skip the summary output (generation of summary.md which is used as PR body). false
dry-run Whether to perform a dry run without making changes to the pre-commit yaml configuration file. false

Contributing

Contributions are welcome! Please create an issue or a pull request if you have any suggestions or improvements.

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

About

Dev tool written in Go to bump the versions of your pre-commit hooks

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •  

Languages