diff options
author | Joel Challis <git@zvecr.com> | 2020-12-10 17:01:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-10 17:01:51 +0000 |
commit | 6c4b6531fe8fed46bec54fae993a1bab8246dd7d (patch) | |
tree | dbe9ad71cbccafee465545cdf7180e65694e4630 | |
parent | 82bb47a2f12429dda49886571173024cc8b80357 (diff) | |
download | qmk_firmware-6c4b6531fe8fed46bec54fae993a1bab8246dd7d.tar.gz qmk_firmware-6c4b6531fe8fed46bec54fae993a1bab8246dd7d.zip |
CI: Add workflow for codebase formatting (#7382)
* Add workflow for codebase formatting
* stash
* review comments
* Swap to a more complete push action
-rw-r--r-- | .github/workflows/format.yaml | 34 | ||||
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | lib/python/qmk/cli/__init__.py | 1 | ||||
-rw-r--r-- | lib/python/qmk/cli/fileformat.py | 13 | ||||
-rwxr-xr-x | util/travis_compiled_push.sh | 5 |
5 files changed, 48 insertions, 6 deletions
diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 000000000..ac0835c3a --- /dev/null +++ b/.github/workflows/format.yaml | |||
@@ -0,0 +1,34 @@ | |||
1 | name: Format Codebase | ||
2 | |||
3 | on: | ||
4 | push: | ||
5 | branches: | ||
6 | - master | ||
7 | |||
8 | jobs: | ||
9 | generate: | ||
10 | runs-on: ubuntu-latest | ||
11 | container: qmkfm/base_container | ||
12 | |||
13 | # protect against those who develop with their fork on master | ||
14 | if: github.repository == 'qmk/qmk_firmware' | ||
15 | |||
16 | steps: | ||
17 | - uses: actions/checkout@v2 | ||
18 | |||
19 | - name: Install dependencies | ||
20 | run: | | ||
21 | apt-get update && apt-get install -y dos2unix | ||
22 | |||
23 | - name: Format files | ||
24 | run: | | ||
25 | bin/qmk cformat | ||
26 | bin/qmk pyformat | ||
27 | bin/qmk fileformat | ||
28 | |||
29 | - name: Commit files | ||
30 | uses: stefanzweifel/git-auto-commit-action@v4 | ||
31 | with: | ||
32 | commit_message: "Format code according to conventions for ${GITHUB_SHA}" | ||
33 | commit_user_name: QMK Bot | ||
34 | commit_user_email: hello@qmk.fm | ||
diff --git a/.travis.yml b/.travis.yml index a6533d613..17f401da4 100644 --- a/.travis.yml +++ b/.travis.yml | |||
@@ -19,7 +19,6 @@ addons: | |||
19 | - llvm-toolchain-trusty-7 | 19 | - llvm-toolchain-trusty-7 |
20 | packages: | 20 | packages: |
21 | - diffutils | 21 | - diffutils |
22 | - dos2unix | ||
23 | - clang-format-7 | 22 | - clang-format-7 |
24 | - libstdc++-7-dev | 23 | - libstdc++-7-dev |
25 | script: | 24 | script: |
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 10536bb23..372c40921 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py | |||
@@ -14,6 +14,7 @@ from . import compile | |||
14 | from . import config | 14 | from . import config |
15 | from . import docs | 15 | from . import docs |
16 | from . import doctor | 16 | from . import doctor |
17 | from . import fileformat | ||
17 | from . import flash | 18 | from . import flash |
18 | from . import generate | 19 | from . import generate |
19 | from . import hello | 20 | from . import hello |
diff --git a/lib/python/qmk/cli/fileformat.py b/lib/python/qmk/cli/fileformat.py new file mode 100644 index 000000000..502a3b7b1 --- /dev/null +++ b/lib/python/qmk/cli/fileformat.py | |||
@@ -0,0 +1,13 @@ | |||
1 | """Format files according to QMK's style. | ||
2 | """ | ||
3 | from milc import cli | ||
4 | |||
5 | import subprocess | ||
6 | |||
7 | |||
8 | @cli.subcommand("Format files according to QMK's style.", hidden=True) | ||
9 | def fileformat(cli): | ||
10 | """Run several general formatting commands. | ||
11 | """ | ||
12 | dos2unix = subprocess.run(['bash', '-c', 'dos2unix **']) | ||
13 | return dos2unix.returncode | ||
diff --git a/util/travis_compiled_push.sh b/util/travis_compiled_push.sh index a9c6f028f..6300442fd 100755 --- a/util/travis_compiled_push.sh +++ b/util/travis_compiled_push.sh | |||
@@ -10,12 +10,7 @@ echo "Using git hash ${rev}" | |||
10 | 10 | ||
11 | if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]] ; then | 11 | if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]] ; then |
12 | 12 | ||
13 | # fix formatting | ||
14 | git checkout master | 13 | git checkout master |
15 | git diff --diff-filter=AM --name-only -n 1 -z ${TRAVIS_COMMIT_RANGE} | xargs -0 dos2unix | ||
16 | git diff --diff-filter=AM --name-only -n 1 -z ${TRAVIS_COMMIT_RANGE} '*.c' '*.h' '*.cpp' | grep -z -e '^drivers' -e '^quantum' -e '^tests' -e '^tmk_core' | grep -zv -e 'quantum/template' -e 'tmk_core/protocol/usb_hid' -e 'platforms/chibios' | xargs -0 clang-format-7 -i | ||
17 | git diff --diff-filter=AM --name-only -n 1 -z ${TRAVIS_COMMIT_RANGE} | xargs -0 git add | ||
18 | git commit -m "format code according to conventions [skip ci]" && git push git@github.com:qmk/qmk_firmware.git master | ||
19 | 14 | ||
20 | git diff --name-only -n 1 ${TRAVIS_COMMIT_RANGE} | 15 | git diff --name-only -n 1 ${TRAVIS_COMMIT_RANGE} |
21 | 16 | ||