non compliant commit for PR. #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: pre-commit | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| on: | |
| push: | |
| branches: [dev, main] | |
| pull_request: | |
| branches: [dev, main] | |
| workflow_call: | |
| inputs: | |
| working-directory: | |
| type: string | |
| required: false | |
| default: '.' | |
| jobs: | |
| pre-commit: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| - name: Set up Python | |
| id: setup-python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| cache: 'pip' | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pre-commit | |
| key: > | |
| ${{ format('pre-commit-{0}-{1}', | |
| steps.setup-python.outputs.python-version, | |
| hashFiles('.pre-commit-config.yaml') | |
| ) }} | |
| - name: Install pre-commit | |
| run: | | |
| pip install --upgrade pip | |
| pip install pre-commit | |
| pre-commit install | |
| - name: Run pre-commit hooks | |
| continue-on-error: true | |
| working-directory: ${{ inputs.working-directory }} | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| git fetch --no-tags --depth=1 origin "${{ github.base_ref }}" | |
| pre-commit run \ | |
| --from-ref "${{ github.base_ref }}" \ | |
| --to-ref "HEAD" \ | |
| --show-diff-on-failure \ | |
| --color=always | |
| else | |
| pre-commit run \ | |
| --from-ref "HEAD~1" \ | |
| --to-ref "HEAD" \ | |
| --show-diff-on-failure \ | |
| --color=always | |
| fi | |
| - name: Commit if changes | |
| # always() bypasses the error code from pre-commit. | |
| # don't run again if this review has been triggered by github-actions[bot], | |
| # since this would create an action loop. | |
| if: github.event_name == 'pull_request' && github.actor != 'github-actions[bot]' | |
| # Normally github message would include [skip ci] to prevent loops, but since this is the pre-commit fixer, it should be stable. | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| if ! git diff --cached --quiet; then | |
| git commit -m "chore: auto-format code [skip ci]" | |
| git push | |
| fi | |
| - name: Re-run pre-commit hooks | |
| working-directory: ${{ inputs.working-directory }} | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| git fetch --no-tags --depth=1 origin "${{ github.base_ref }}" | |
| pre-commit run \ | |
| --from-ref "${{ github.base_ref }}" \ | |
| --to-ref "HEAD" \ | |
| --show-diff-on-failure \ | |
| --color=always | |
| else | |
| pre-commit run \ | |
| --from-ref "HEAD~1" \ | |
| --to-ref "HEAD" \ | |
| --show-diff-on-failure \ | |
| --color=always | |
| fi |