Files
actions/pre-commit/action.yml
Ismo Vuorinen 5cc7373a22 chore: update action references for release v2025.11.23
This commit updates all internal action references to point to the current
commit SHA in preparation for release v2025.11.23.
2025-11-23 19:09:40 +02:00

92 lines
2.8 KiB
YAML

# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
# permissions:
# - contents: write # Required for pushing fixes back to repository
---
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 for authentication'
required: false
default: ''
commit_user:
description: 'Commit user'
required: false
default: 'GitHub Actions'
commit_email:
description: 'Commit email'
required: false
default: 'github-actions@github.com'
outputs:
hooks_passed:
description: 'Whether all pre-commit hooks passed (true/false)'
value: ${{ steps.pre-commit.outcome == 'success' }}
files_changed:
description: 'Whether any files were changed by pre-commit hooks'
value: ${{ steps.push-fixes.outputs.changes_detected }}
runs:
using: composite
steps:
- name: Checkout Repository
uses: actions/checkout@71cf2267d89c5cb81562390fa70a37fa40b1305e # v6-beta
with:
token: ${{ inputs.token || github.token }}
- name: Validate Inputs
id: validate
uses: ivuorinen/actions/validate-inputs@8fb52522ab00fe73cf181ef299e56066f0b2c8d8
with:
action-type: 'pre-commit'
token: ${{ inputs.token }}
pre-commit-config: ${{ inputs.pre-commit-config }}
base-branch: ${{ inputs.base-branch }}
email: ${{ inputs.commit_email }}
username: ${{ inputs.commit_user }}
- name: Set option
id: set-option
shell: sh
env:
BASE_BRANCH: ${{ inputs.base-branch }}
run: |
set -eu
if [ -z "$BASE_BRANCH" ]; then
printf '%s\n' "option=--all-files" >> "$GITHUB_OUTPUT"
exit 0
fi
printf '%s\n' "option=--from-ref $BASE_BRANCH --to-ref HEAD" >> "$GITHUB_OUTPUT"
- name: Run pre-commit
id: pre-commit
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
env:
PRE_COMMIT_USE_UV: '1'
with:
extra_args: --config ${{ inputs.pre-commit-config }} ${{ steps.set-option.outputs.option }}
- name: Push pre-commit fixes
id: push-fixes
if: always() # Push changes even when pre-commit fails
uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0
with:
commit_message: 'style(pre-commit): autofix'
commit_user_name: ${{ inputs.commit_user }}
commit_user_email: ${{ inputs.commit_email }}
add_options: -u