AutoTeam-F / .github /workflows /pre-commit.yml
cnitlrt's picture
ci: 添加 GitHub Actions pre-commit 检查
052058e
Raw
History Blame Contribute Delete
1.29 kB
name: pre-commit
on:
pull_request:
push:
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install tooling
run: |
python -m pip install --upgrade pip
python -m pip install pre-commit
- name: Run pre-commit on changed files
env:
EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BEFORE_SHA: ${{ github.event.before }}
HEAD_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "pull_request" ]; then
FROM_SHA="$BASE_SHA"
else
FROM_SHA="$BEFORE_SHA"
fi
if [ -z "${FROM_SHA:-}" ] || [ "$FROM_SHA" = "0000000000000000000000000000000000000000" ]; then
echo "No valid base SHA found; running on all files."
pre-commit run --all-files --show-diff-on-failure --color=always
else
pre-commit run --from-ref "$FROM_SHA" --to-ref "$HEAD_SHA" --show-diff-on-failure --color=always
fi