Skip to content

Commit

Permalink
CI: Split out file format test as a separate GitHub workflow
Browse files Browse the repository at this point in the history
Split out checking of file format as a separate GitHub workflow, rather
than running it as part of the project tests for every platform and
toolchain combination in CI, so that this test is not effected by the
changed paths constraints which are applied to the project tests.
  • Loading branch information
jon-turney authored and mensinda committed Jun 11, 2021
1 parent 25f2d88 commit 636bf91
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 48 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/file_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: File format check

on: [push, pull_request]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: python3 ./run_format_tests.py
82 changes: 82 additions & 0 deletions run_format_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3

# Copyright 2012-2019 The Meson development team

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# some simple checks on the file format of:
# - python code
# - code samples in tests
# - markdown documentation
#
# checks are:
# - no use of tabs
# - no use of DOS line endings

import os
import re
from pathlib import Path

def check_file(file: Path) -> None:
lines = file.read_bytes().split(b'\n')
tabdetector = re.compile(br' *\t')
for i, line in enumerate(lines):
if re.match(tabdetector, line):
raise SystemExit("File {} contains a tab indent on line {:d}. Only spaces are permitted.".format(file, i + 1))
if line.endswith(b'\r'):
raise SystemExit("File {} contains DOS line ending on line {:d}. Only unix-style line endings are permitted.".format(file, i + 1))

def check_format() -> None:
check_suffixes = {'.c',
'.cpp',
'.cxx',
'.cc',
'.rs',
'.f90',
'.vala',
'.d',
'.s',
'.m',
'.mm',
'.asm',
'.java',
'.txt',
'.py',
'.swift',
'.build',
'.md',
}
skip_dirs = {
'.dub', # external deps are here
'.pytest_cache',
'meson-logs', 'meson-private',
'work area',
'.eggs', '_cache', # e.g. .mypy_cache
'venv', # virtualenvs have DOS line endings
}
for (root, _, filenames) in os.walk('.'):
if any([x in root for x in skip_dirs]):
continue
for fname in filenames:
file = Path(fname)
if file.suffix.lower() in check_suffixes:
if file.name in ('sitemap.txt', 'meson-test-run.txt'):
continue
check_file(root / file)


if __name__ == '__main__':
script_dir = os.path.split(__file__)[0]
if script_dir != '':
os.chdir(script_dir)
check_format()
48 changes: 0 additions & 48 deletions run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,53 +1330,6 @@ def tqdm_print(*args: mlog.TV_Loggable, sep: str = ' ') -> None:
ET.ElementTree(element=junit_root).write(xmlname, xml_declaration=True, encoding='UTF-8')
return passing_tests, failing_tests, skipped_tests

def check_file(file: Path) -> None:
lines = file.read_bytes().split(b'\n')
tabdetector = re.compile(br' *\t')
for i, line in enumerate(lines):
if re.match(tabdetector, line):
raise SystemExit("File {} contains a tab indent on line {:d}. Only spaces are permitted.".format(file, i + 1))
if line.endswith(b'\r'):
raise SystemExit("File {} contains DOS line ending on line {:d}. Only unix-style line endings are permitted.".format(file, i + 1))

def check_format() -> None:
check_suffixes = {'.c',
'.cpp',
'.cxx',
'.cc',
'.rs',
'.f90',
'.vala',
'.d',
'.s',
'.m',
'.mm',
'.asm',
'.java',
'.txt',
'.py',
'.swift',
'.build',
'.md',
}
skip_dirs = {
'.dub', # external deps are here
'.pytest_cache',
'meson-logs', 'meson-private',
'work area',
'.eggs', '_cache', # e.g. .mypy_cache
'venv', # virtualenvs have DOS line endings
}
for (root, _, filenames) in os.walk('.'):
if any([x in root for x in skip_dirs]):
continue
for fname in filenames:
file = Path(fname)
if file.suffix.lower() in check_suffixes:
if file.name in ('sitemap.txt', 'meson-test-run.txt'):
continue
check_file(root / file)

def check_meson_commands_work(use_tmpdir: bool, extra_args: T.List[str]) -> None:
global backend, compile_commands, test_commands, install_commands
testdir = PurePath('test cases', 'common', '1 trivial').as_posix()
Expand Down Expand Up @@ -1567,7 +1520,6 @@ def clear_transitive_files() -> None:
script_dir = os.path.split(__file__)[0]
if script_dir != '':
os.chdir(script_dir)
check_format()
check_meson_commands_work(options.use_tmpdir, options.extra_args)
only = collections.defaultdict(list)
for i in options.only:
Expand Down

0 comments on commit 636bf91

Please sign in to comment.