Skip to content

Commit

Permalink
ci: add meson.build fmt check
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Jan 4, 2025
1 parent a5c47ff commit 14fbb8b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/format-meson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check meson.build Format

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
format-meson:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Meson
run: pip install git+https://github.com/mesonbuild/meson

- name: Format Checks
run: python ./tools/run_meson_fmt.py --check
34 changes: 34 additions & 0 deletions tools/run_meson_fmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
format or check all meson.build file in projects
"""

import sys
import pathlib
import subprocess
from shutil import which
from itertools import chain

is_check = "--check" in sys.argv

base_command = [which("meson"), "fmt", "--editor-config"]
if is_check:
base_command.append("--check-only")
else:
base_command.append("--inplace")

project_root = pathlib.Path(__file__).parent.parent

for meson_file in chain(
[project_root.joinpath("meson.build")],
project_root.glob("subprojects/packagefiles/**/meson.build"),
):
readable_filename = meson_file.relative_to(project_root).as_posix()
print("processing:", readable_filename)
try:
subprocess.check_call(base_command + [str(meson_file)], cwd=str(project_root))
except subprocess.CalledProcessError as e:
if is_check:
print("{} is not formatted".format(readable_filename))
sys.exit(e.returncode)
else:
print("failed to format {}".format(readable_filename))

0 comments on commit 14fbb8b

Please sign in to comment.