mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-28 14:10:13 +00:00
Merge remote-tracking branch 'origin/master' into develop
This commit is contained in:
commit
462c3a6151
21
.github/workflows/format.yaml
vendored
21
.github/workflows/format.yaml
vendored
@ -19,7 +19,9 @@ jobs:
|
|||||||
container: qmkfm/qmk_cli
|
container: qmkfm/qmk_cli
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: rlespinasse/github-slug-action@v3.x
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update && apt-get install -y dos2unix
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
@ -31,12 +33,17 @@ jobs:
|
|||||||
output: ' '
|
output: ' '
|
||||||
fileOutput: ' '
|
fileOutput: ' '
|
||||||
|
|
||||||
- name: Run qmk format-c and qmk format-python
|
- name: Run qmk formatters
|
||||||
shell: 'bash {0}'
|
shell: 'bash {0}'
|
||||||
run: |
|
run: |
|
||||||
qmk format-c --core-only -n $(< ~/files.txt)
|
qmk format-c --core-only $(< ~/files.txt)
|
||||||
format_c_exit=$?
|
qmk format-python
|
||||||
qmk format-python -n
|
qmk format-text $(< ~/files.txt)
|
||||||
format_python_exit=$?
|
git diff
|
||||||
|
|
||||||
exit $((format_c_exit + format_python_exit))
|
- name: Fail when formatting required
|
||||||
|
run: |
|
||||||
|
for file in $(git diff --name-only); do
|
||||||
|
echo "::error file=${file}::::File Requires Formatting"
|
||||||
|
done
|
||||||
|
test -z "$(git diff --name-only)"
|
||||||
|
@ -1,27 +1,57 @@
|
|||||||
"""Ensure text files have the proper line endings.
|
"""Ensure text files have the proper line endings.
|
||||||
"""
|
"""
|
||||||
from subprocess import CalledProcessError
|
from itertools import islice
|
||||||
|
from subprocess import DEVNULL
|
||||||
|
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
|
from qmk.path import normpath
|
||||||
|
|
||||||
|
|
||||||
|
def _get_chunks(it, size):
|
||||||
|
"""Break down a collection into smaller parts
|
||||||
|
"""
|
||||||
|
it = iter(it)
|
||||||
|
return iter(lambda: tuple(islice(it, size)), ())
|
||||||
|
|
||||||
|
|
||||||
|
def dos2unix_run(files):
|
||||||
|
"""Spawn multiple dos2unix subprocess avoiding too long commands on formatting everything
|
||||||
|
"""
|
||||||
|
for chunk in _get_chunks(files, 10):
|
||||||
|
dos2unix = cli.run(['dos2unix', *chunk])
|
||||||
|
|
||||||
|
if dos2unix.returncode:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@cli.argument('-b', '--base-branch', default='origin/master', help='Branch to compare to diffs to.')
|
||||||
|
@cli.argument('-a', '--all-files', arg_only=True, action='store_true', help='Format all files.')
|
||||||
|
@cli.argument('files', nargs='*', arg_only=True, type=normpath, help='Filename(s) to format.')
|
||||||
@cli.subcommand("Ensure text files have the proper line endings.", hidden=True)
|
@cli.subcommand("Ensure text files have the proper line endings.", hidden=True)
|
||||||
def format_text(cli):
|
def format_text(cli):
|
||||||
"""Ensure text files have the proper line endings.
|
"""Ensure text files have the proper line endings.
|
||||||
"""
|
"""
|
||||||
try:
|
# Find the list of files to format
|
||||||
file_list_cmd = cli.run(['git', 'ls-files', '-z'], check=True)
|
if cli.args.files:
|
||||||
except CalledProcessError as e:
|
files = list(cli.args.files)
|
||||||
cli.log.error('Could not get file list: %s', e)
|
|
||||||
exit(1)
|
|
||||||
except Exception as e:
|
|
||||||
cli.log.error('Unhandled exception: %s: %s', e.__class__.__name__, e)
|
|
||||||
cli.log.exception(e)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
dos2unix = cli.run(['xargs', '-0', 'dos2unix'], stdin=None, input=file_list_cmd.stdout)
|
if cli.args.all_files:
|
||||||
|
cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files)))
|
||||||
|
|
||||||
if dos2unix.returncode != 0:
|
elif cli.args.all_files:
|
||||||
print(dos2unix.stderr)
|
git_ls_cmd = ['git', 'ls-files']
|
||||||
|
git_ls = cli.run(git_ls_cmd, stdin=DEVNULL)
|
||||||
|
files = list(filter(None, git_ls.stdout.split('\n')))
|
||||||
|
|
||||||
return dos2unix.returncode
|
else:
|
||||||
|
git_diff_cmd = ['git', 'diff', '--name-only', cli.args.base_branch]
|
||||||
|
git_diff = cli.run(git_diff_cmd, stdin=DEVNULL)
|
||||||
|
files = list(filter(None, git_diff.stdout.split('\n')))
|
||||||
|
|
||||||
|
# Sanity check
|
||||||
|
if not files:
|
||||||
|
cli.log.error('No changed files detected. Use "qmk format-text -a" to format all files')
|
||||||
|
return False
|
||||||
|
|
||||||
|
return dos2unix_run(files)
|
||||||
|
Loading…
Reference in New Issue
Block a user