2024-06-17 01:26:36 +02:00
|
|
|
name: Pre-commit consistency check
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
pull_request:
|
|
|
|
types: [labeled, opened, reopened, synchronize]
|
|
|
|
push:
|
|
|
|
branches: [spigot, re-recode]
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
group: ${{ github.head_ref }}-precommit
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
pre-commit-check:
|
|
|
|
if: github.event.action != 'labeled' || github.event.label.name == 'pre-commit ci run'
|
|
|
|
name: Run pre-commit checks
|
|
|
|
runs-on: ubuntu-20.04
|
|
|
|
steps:
|
2024-08-31 03:47:36 +02:00
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
- run: gh pr edit ${{ github.event.number }} --remove-label 'pre-commit ci run'
|
|
|
|
if: github.event.action == 'labeled' && github.event.label.name == 'pre-commit ci run'
|
|
|
|
env:
|
|
|
|
GH_TOKEN: ${{ github.token }}
|
|
|
|
- uses: dorny/paths-filter@v2
|
|
|
|
id: filter
|
|
|
|
with:
|
|
|
|
list-files: shell
|
|
|
|
filters: |
|
|
|
|
addedOrModified:
|
|
|
|
- added|modified: '**'
|
2024-06-17 01:26:36 +02:00
|
|
|
|
2024-06-17 13:10:40 +02:00
|
|
|
# run only if changed files were detected
|
2024-08-31 03:47:36 +02:00
|
|
|
- name: Run against changes
|
|
|
|
uses: pre-commit/action@v3.0.1
|
|
|
|
if: steps.filter.outputs.addedOrModified == 'true'
|
|
|
|
with:
|
|
|
|
extra_args: --files ${{ steps.filter.outputs.addedOrModified_files }}
|
2024-06-17 01:26:36 +02:00
|
|
|
|
2024-06-17 13:10:40 +02:00
|
|
|
# run if no changed files were detected (e.g. workflow_dispatch on master branch)
|
2024-08-31 03:47:36 +02:00
|
|
|
- name: Run against all files
|
|
|
|
uses: pre-commit/action@v3.0.1
|
|
|
|
if: steps.filter.outputs.addedOrModified != 'true'
|
|
|
|
with:
|
|
|
|
extra_args: --all-files
|
2024-06-17 01:31:42 +02:00
|
|
|
|
2024-08-31 03:47:36 +02:00
|
|
|
- name: Commit pre-commit changes
|
|
|
|
if: always()
|
|
|
|
run: |
|
|
|
|
git config --global user.name "github-actions[bot]"
|
|
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
git add .
|
|
|
|
git commit -m "chore: pre-commit changes [skip ci]" || echo "No changes to commit"
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Push pre-commit changes
|
|
|
|
if: always() && github.event.action != 'pull_request' && github.event.action != 'labeled' && github.event.action != 'synchronize'
|
|
|
|
run: |
|
|
|
|
git push ${{ github.head_ref }}
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- uses: pre-commit-ci/lite-action@v1.0.2
|
|
|
|
if: always()
|