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

CI: Add workflow for codebase formatting #7382

Merged
merged 4 commits into from
Dec 10, 2020
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
34 changes: 34 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Format Codebase

on:
push:
branches:
- master

jobs:
generate:
runs-on: ubuntu-latest
container: qmkfm/base_container

# protect against those who develop with their fork on master
if: github.repository == 'qmk/qmk_firmware'

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
apt-get update && apt-get install -y dos2unix
- name: Format files
run: |
bin/qmk cformat
bin/qmk pyformat
bin/qmk fileformat
zvecr marked this conversation as resolved.
Show resolved Hide resolved
- name: Commit files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Format code according to conventions for ${GITHUB_SHA}"
commit_user_name: QMK Bot
commit_user_email: [email protected]
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ addons:
- llvm-toolchain-trusty-7
packages:
- diffutils
- dos2unix
- clang-format-7
- libstdc++-7-dev
script:
Expand Down
1 change: 1 addition & 0 deletions lib/python/qmk/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import config
from . import docs
from . import doctor
from . import fileformat
from . import flash
from . import generate
from . import hello
Expand Down
13 changes: 13 additions & 0 deletions lib/python/qmk/cli/fileformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Format files according to QMK's style.
"""
from milc import cli

import subprocess


@cli.subcommand("Format files according to QMK's style.", hidden=True)
def fileformat(cli):
"""Run several general formatting commands.
zvecr marked this conversation as resolved.
Show resolved Hide resolved
"""
dos2unix = subprocess.run(['bash', '-c', 'dos2unix **'])
return dos2unix.returncode
5 changes: 0 additions & 5 deletions util/travis_compiled_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ echo "Using git hash ${rev}"

if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]] ; then

# fix formatting
git checkout master
git diff --diff-filter=AM --name-only -n 1 -z ${TRAVIS_COMMIT_RANGE} | xargs -0 dos2unix
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
git diff --diff-filter=AM --name-only -n 1 -z ${TRAVIS_COMMIT_RANGE} | xargs -0 git add
git commit -m "format code according to conventions [skip ci]" && git push [email protected]:qmk/qmk_firmware.git master

git diff --name-only -n 1 ${TRAVIS_COMMIT_RANGE}

Expand Down