Skip to content

fix: Fix action-lint for empty commit hash #4

fix: Fix action-lint for empty commit hash

fix: Fix action-lint for empty commit hash #4

Workflow file for this run

name: Lint Code Base
on:
pull_request:
branches:
- main
push:
jobs:
lint:
name: Lint Code Base
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install Dependencies
run: pip install pre-commit
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Lint Code Base
run: |
if [ "${{ github.event_name }}" == "push" ]; then
GITHUB_FROM_SHA="${{ github.event.before }}"
GITHUB_TO_SHA="${{ github.event.after }}"
elif [ "${{ github.event_name }}" == "pull_request" ]; then
GITHUB_FROM_SHA="${{ github.event.pull_request.base.sha }}"
GITHUB_TO_SHA="${{ github.event.pull_request.head.sha }}"
else
GITHUB_FROM_SHA="4b825dc642cb6eb9a060e54bf8d69288fbee4904"
GITHUB_TO_SHA="HEAD"
fi
if [ "$GITHUB_FROM_SHA" == "0000000000000000000000000000000000000000" ]; then
GITHUB_FROM_SHA="4b825dc642cb6eb9a060e54bf8d69288fbee4904"
fi
echo "::notice::GITHUB_FROM_SHA: $GITHUB_FROM_SHA"
echo "::notice::GITHUB_TO_SHA: $GITHUB_TO_SHA"
pre-commit run \
--color always \
--show-diff-on-failure \
--from-ref $GITHUB_FROM_SHA \
--to-ref $GITHUB_TO_SHA