salt/.github/workflows/pre-commit-action.yml
2025-03-07 15:05:05 -07:00

68 lines
2.1 KiB
YAML

---
name: Pre-Commit
on:
workflow_call:
inputs:
changed-files:
required: true
type: string
description: JSON string containing information about changed files
pre-commit-version:
required: true
type: string
description: The pre-commit version to install
cache-seed:
required: true
type: string
description: Seed used to invalidate caches
jobs:
Pre-Commit:
name: Run Pre-Commit Against Salt
runs-on: ubuntu-22.04
container:
image: ghcr.io/saltstack/salt-ci-containers/testing:ubuntu-22.04
env:
PRE_COMMIT_COLOR: always
steps:
- name: Add Git Safe Directory
run: |
git config --global --add safe.directory "$(pwd)"
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-actionlint
with:
cache-seed: ${{ inputs.cache-seed }}
- uses: ./.github/actions/setup-shellcheck
with:
cache-seed: ${{ inputs.cache-seed }}
- uses: ./.github/actions/setup-pre-commit
with:
version: ${{ inputs.pre-commit-version }}
cache-seed: ${{ inputs.cache-seed }}
- name: Check ALL Files On Branch
if: ${{ !cancelled() && github.event_name != 'pull_request' }}
env:
SKIP: lint-salt,lint-tests,remove-import-headers,pyupgrade
run: |
pre-commit run --show-diff-on-failure --color=always --all-files
- name: Check Changed Files On PR
if: ${{ !cancelled() && github.event_name == 'pull_request' && fromJSON(inputs.changed-files)['repo'] }}
env:
SKIP: lint-salt,lint-tests
GH_ACTIONS_ANNOTATE: "1"
run: |
pre-commit run --show-diff-on-failure --color=always --files ${{ join(fromJSON(inputs.changed-files)['repo_files'], ' ') }}
- name: Check Docs On Deleted Files
if: ${{ !cancelled() && github.event_name == 'pull_request' && fromJSON(inputs.changed-files)['deleted'] }}
run: |
pre-commit run --show-diff-on-failure --color=always check-docs --files ${{ join(fromJSON(inputs.changed-files)['deleted_files'], ' ') }}