mirror of
https://github.com/ivuorinen/actions.git
synced 2026-01-26 11:34:00 +00:00
63 lines
1.8 KiB
YAML
63 lines
1.8 KiB
YAML
---
|
|
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
|
|
name: pre-commit
|
|
description: 'Runs pre-commit on the repository and pushes the fixes back to the repository'
|
|
author: 'Ismo Vuorinen'
|
|
|
|
branding:
|
|
icon: check-square
|
|
color: green
|
|
|
|
inputs:
|
|
pre-commit-config:
|
|
description: 'pre-commit configuration file'
|
|
required: false
|
|
default: '.pre-commit-config.yaml'
|
|
base-branch:
|
|
description: 'Base branch to compare against'
|
|
required: false
|
|
token:
|
|
description: 'GitHub Token'
|
|
required: false
|
|
default: ${{ github.token }}
|
|
commit_user:
|
|
description: 'Commit user'
|
|
required: false
|
|
default: 'GitHub Actions'
|
|
commit_email:
|
|
description: 'Commit email'
|
|
required: false
|
|
default: 'github-actions@github.com'
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Set Git Config
|
|
uses: ivuorinen/actions/set-git-config@main
|
|
with:
|
|
token: ${{ inputs.token }}
|
|
username: ${{ inputs.commit_user }}
|
|
email: ${{ inputs.commit_email }}
|
|
|
|
- name: Set option
|
|
id: set-option
|
|
run: |
|
|
if [ -z "${{ inputs.base-branch }}" ]; then
|
|
echo "option=--all-files" >> $GITHUB_OUTPUT
|
|
exit 0
|
|
fi
|
|
echo "option=--from-ref ${{ inputs.base-branch }} --to-ref HEAD" >> $GITHUB_OUTPUT
|
|
shell: bash
|
|
|
|
- name: Run pre-commit
|
|
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
|
|
with:
|
|
extra_args: --config ${{ inputs.pre-commit-config }} ${{ steps.set-option.outputs.option }}
|
|
|
|
- name: Push pre-commit fixes
|
|
if: always() # Push changes even when pre-commit fails
|
|
uses: stefanzweifel/git-auto-commit-action@e348103e9026cc0eee72ae06630dbe30c8bf7a79 # v5.1.0
|
|
with:
|
|
commit_message: 'style(pre-commit): autofix'
|
|
add_options: -u
|