Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit: Add hooks for qmllint and qmlformat #3915

Merged
merged 3 commits into from
May 26, 2021
Merged
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
19 changes: 12 additions & 7 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ jobs:
pre-commit:
name: Detecting code style issues
runs-on: ubuntu-latest
# The Dockerfile for this container can be found at:
# https://github.com/Holzhaus/mixxx-ci-docker
container: holzhaus/mixxx-ci:20210526
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: "Check out repository"
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: "Set up Python"
uses: actions/setup-python@v2

- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang-format-10

- name: "Detect code style issues (push)"
uses: pre-commit/action@v2.0.0
if: github.event_name == 'push'
Expand All @@ -28,16 +25,24 @@ jobs:
# on Pull Requests!).
env:
SKIP: end-of-file-fixer,trailing-whitespace,clang-format,eslint,no-commit-to-branch
with:
# Enable extra hooks that require special system dependencies that we
# cannot expect to be installed on all contributor's systems.
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
extra_args: --hook-stage manual --all-files

- name: "Detect code style issues (pull_request)"
uses: pre-commit/action@v2.0.0
if: github.event_name == 'pull_request'
env:
SKIP: no-commit-to-branch
with:
# Enable extra hooks that require special system dependencies that are
# available in our custom docker container, but cannot be expected to
# be installed on all contributor's systems.
#
# HEAD is the not yet integrated PR merge commit +refs/pull/xxxx/merge
# HEAD^1 is the PR target branch and HEAD^2 is the HEAD of the source branch
extra_args: --from-ref HEAD^1 --to-ref HEAD
extra_args: --hook-stage manual --from-ref HEAD^1 --to-ref HEAD

- name: "Generate patch file"
if: failure()
Expand Down
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,23 @@ repos:
stages:
- commit
- manual
- id: qmlformat
name: qmlformat
entry: qmlformat -i
pass_filenames: true
require_serial: true
language: system
types: [text]
files: ^.*\.qml$
# Not enabled in commit stage by default, because qmlformat requires Qt
# 5.15 to be installed
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just add a wrapper script that calls qmlformat if it exists or print a message "qmlformat is not installed, skipping qmlformat".
I will never remember running this with manual arguments

Copy link
Member Author

Choose a reason for hiding this comment

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

You will notice when it runs on CI at least. I thought about that as well, but thr problem is that the hook will always pass in that case, and you don't really know it it actually passed or if the tool was just not found.

Copy link
Member Author

Choose a reason for hiding this comment

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

The alternative would be to not make any special workarounds. The hook will only run if you changed QML files anyway. If you really want to change QML files with qml format installed just skip the hook with SKIP=qmlformat git commit

That would also be an option. @poelzi @uklotzde what do you think?

stages:
- manual
- id: qmllint
name: qmllint
entry: qmllint
pass_filenames: true
require_serial: true
language: system
types: [text]
files: ^.*\.qml$