2024-12-22 13:36:26 +01:00
|
|
|
name: Pre-commit
|
|
|
|
|
|
|
|
on:
|
2025-01-13 19:27:27 +01:00
|
|
|
workflow_dispatch:
|
2025-01-21 12:09:01 +01:00
|
|
|
schedule:
|
|
|
|
- cron: "0 0 * * 1"
|
2024-12-22 13:36:26 +01:00
|
|
|
|
2025-01-02 19:22:14 +01:00
|
|
|
permissions:
|
|
|
|
contents: read
|
2024-12-22 13:36:26 +01:00
|
|
|
|
|
|
|
jobs:
|
2025-01-13 19:27:27 +01:00
|
|
|
pre-commit:
|
2024-12-22 13:36:26 +01:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
contents: write
|
|
|
|
pull-requests: write
|
|
|
|
steps:
|
2025-01-13 19:27:27 +01:00
|
|
|
- name: Harden Runner
|
|
|
|
uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3
|
|
|
|
with:
|
|
|
|
egress-policy: audit
|
|
|
|
|
2025-01-20 20:59:17 +01:00
|
|
|
- name: Generate GitHub App Token
|
|
|
|
id: generate-token
|
|
|
|
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
|
|
|
|
with:
|
|
|
|
app-id: ${{ secrets.GH_APP_ID }}
|
|
|
|
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
|
|
|
|
|
|
|
|
- name: Get GitHub App User ID
|
|
|
|
id: get-user-id
|
|
|
|
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> $GITHUB_OUTPUT
|
|
|
|
env:
|
|
|
|
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
|
|
|
|
|
|
|
- id: committer
|
|
|
|
run: |
|
|
|
|
echo "string=${{ steps.generate-token.outputs.app-slug }}[bot] <${{ steps.get-user-id.outputs.user-id }}+${{ steps.generate-token.outputs.app-slug }}[bot]@users.noreply.github.com>" >> "$GITHUB_OUTPUT"
|
|
|
|
|
2024-12-22 13:36:26 +01:00
|
|
|
- name: Checkout repository
|
2024-12-22 16:02:23 +01:00
|
|
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
2024-12-22 17:36:46 +01:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2024-12-22 13:36:26 +01:00
|
|
|
- name: Set up Python
|
2025-01-02 19:22:14 +01:00
|
|
|
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
|
2024-12-22 13:36:26 +01:00
|
|
|
with:
|
|
|
|
python-version: 3.12
|
2025-01-16 23:04:38 +01:00
|
|
|
cache: 'pip' # caching pip dependencies
|
2024-12-22 17:36:46 +01:00
|
|
|
- name: Run Pre-Commit Hooks
|
2025-01-13 19:27:27 +01:00
|
|
|
run: |
|
|
|
|
pip install --require-hashes -r ./.github/scripts/requirements_pre_commit.txt
|
|
|
|
- run: pre-commit run --all-files -c .pre-commit-config.yaml
|
2024-12-22 17:36:46 +01:00
|
|
|
continue-on-error: true
|
2024-12-22 13:36:26 +01:00
|
|
|
- name: Set up git config
|
|
|
|
run: |
|
2025-01-20 20:59:17 +01:00
|
|
|
git config --global user.name ${{ steps.generate-token.outputs.app-slug }}[bot]
|
|
|
|
git config --global user.email "${{ steps.get-user-id.outputs.user-id }}+${{ steps.generate-token.outputs.app-slug }}[bot]@users.noreply.github.com"
|
2024-12-22 17:36:46 +01:00
|
|
|
- name: git add
|
2024-12-22 13:36:26 +01:00
|
|
|
run: |
|
|
|
|
git add .
|
2025-01-20 20:59:17 +01:00
|
|
|
git diff --staged --quiet || echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
|
2024-12-22 13:36:26 +01:00
|
|
|
- name: Create Pull Request
|
2025-01-20 20:59:17 +01:00
|
|
|
if: env.CHANGES_DETECTED == 'true'
|
2025-01-02 15:24:04 +01:00
|
|
|
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6
|
2024-12-22 13:36:26 +01:00
|
|
|
with:
|
2025-01-20 20:59:17 +01:00
|
|
|
token: ${{ steps.generate-token.outputs.token }}
|
|
|
|
commit-message: ":file_folder: pre-commit"
|
|
|
|
committer: ${{ steps.committer.outputs.string }}
|
|
|
|
author: ${{ steps.committer.outputs.string }}
|
2024-12-22 13:36:26 +01:00
|
|
|
signoff: true
|
|
|
|
branch: pre-commit
|
2025-01-20 20:59:17 +01:00
|
|
|
title: "🤖 format everything with pre-commit by <${{ steps.generate-token.outputs.app-slug }}>"
|
2024-12-22 13:36:26 +01:00
|
|
|
body: |
|
2025-01-20 20:59:17 +01:00
|
|
|
Auto-generated by [create-pull-request][1] with **${{ steps.generate-token.outputs.app-slug }}**
|
2024-12-22 13:36:26 +01:00
|
|
|
|
|
|
|
[1]: https://github.com/peter-evans/create-pull-request
|
|
|
|
draft: false
|
|
|
|
delete-branch: true
|
|
|
|
labels: github-actions
|
|
|
|
sign-commits: true
|