Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/actions/pre-commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: pre-commit
description: Run and cache pre-commit

inputs:
args:
description: Options to pass to the pre-commit run.
required: true
type: string

runs:
using: composite
steps:
- name: Restore pre-commit cache
id: pre-commit-restore
uses: actions/cache/restore@v5
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ hashFiles('.pre-commit-config.yaml') }}|${{ github.sha }}
restore-keys: pre-commit|${{ hashFiles('.pre-commit-config.yaml') }}

- name: Setup pre-commit
shell: sh
run: |
echo "::group::Installing pre-commit"
# Don't know which python we're using, so just access the global scope.
python -m pip install pre-commit
echo "::endgroup::"

echo "::group::Preparing pre-commit dependencies"
# Specify manual hook stage to capture `clangd-tidy` as well.
pre-commit run --hook-stage manual
echo "::endgroup::"

echo "::group::Removing unused dependencies"
# Prevent cache bloat by only keeping current dependencies.
pre-commit gc
echo "::endgroup::"

- name: Save pre-commit cache
uses: actions/cache/save@v5
if: steps.pre-commit-restore.outputs.cache-hit != 'true'
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ hashFiles('.pre-commit-config.yaml') }}|${{ github.sha }}

- name: Run pre-commit
shell: sh
run: pre-commit run --show-diff-on-failure --color=always ${{ inputs.args }}
4 changes: 2 additions & 2 deletions .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ jobs:

- name: Style checks via clangd-tidy
if: matrix.clangd-tidy
uses: ./.github/actions/clangd-tidy
uses: ./.github/actions/pre-commit
with:
changed-files: ${{ inputs.changed-files }}
args: --hook-stage manual clangd-tidy --files ${{ inputs.changed-files }}

- name: Compilation (godot-cpp)
uses: ./.github/actions/godot-cpp-build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
files_yaml_from_source_file: .github/changed_files.yml

- name: Style checks via pre-commit
uses: pre-commit/action@v3.0.1
uses: ./.github/actions/pre-commit
env:
CHANGED_FILES: '"${{ steps.changed-files.outputs.everything_all_changed_files }}"' # Wrap with quotes to bookend internal quote separators.
with:
extra_args: --files ${{ env.CHANGED_FILES }}
args: --files ${{ env.CHANGED_FILES }}
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ repos:

- repo: local
hooks:
# Not automatically triggered (because it requires compile_commands.json to be up-to-date).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for our now hand-made pre-commit action to run scons compiledb_gen_only to update the compiledb forcefully, thus enabling this stage as automatic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like where your head's at, but it's unfortunately unsuitable for a pre-commit hook because of how long that takes even in isolation. What we might be able to do is a wrapper script which either skips or fails the hook if that file isn't present... Will play around with that today

# Invoke it manually via `pre-commit run --hook-stage manual clangd-tidy`.
- id: clangd-tidy
name: clangd-tidy
language: python
entry: clangd-tidy --allow-extensions c,h,cpp,hpp,cc,hh,cxx,hxx,m,mm,java
# TODO .inc ignored for now because they don't include their parent header.
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|java)$
additional_dependencies: [clangd-tidy, clangd, clang-tidy==22.1.0.1]
require_serial: true
stages: [manual]

- id: make-rst
name: make-rst
language: python
Expand Down
Loading