diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 0000000..70b41a5 --- /dev/null +++ b/.github/workflows/format.yaml @@ -0,0 +1,28 @@ +name: format +on: + push: + branches: + - version-1.1 + pull_request: + branches: + - master + +jobs: + build: + name: Test code formatting + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prepare + shell: bash + run: | + sudo ./scripts/install_clang_format_17.sh + continue-on-error: false + + - name: Test formatting + shell: bash + run: | + find . -type f -name "*.hpp" -o -name "*.cpp" -exec clang-format --dry-run --Werror {} \; diff --git a/README.md b/README.md index d6be8f3..be0976d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Command-line argument parser for C++20 [![g++](https://github.com/SpectraL519/cpp-ap/actions/workflows/gpp.yaml/badge.svg)](https://github.com/SpectraL519/cpp-ap/actions/workflows/g++) [![clang++](https://github.com/SpectraL519/cpp-ap/actions/workflows/clang.yaml/badge.svg)](https://github.com/SpectraL519/cpp-ap/actions/workflows/clang++) [![test](https://github.com/SpectraL519/cpp-ap/actions/workflows/test.yaml/badge.svg)](https://github.com/SpectraL519/cpp-ap/actions/workflows/test) +[![format](https://github.com/SpectraL519/cpp-ap/actions/workflows/format.yaml/badge.svg)](https://github.com/SpectraL519/cpp-ap/actions/workflows/format)
@@ -34,8 +35,8 @@ The `CPP-AP` library does not require installing any additional tools or heavy l * [Parsing arguments](#parsing-arguments) * [Examples](#examples) * [Dev notes](#dev-notes) - * [Requirements](#requirements) * [Building and testing](#building-and-testing) + * [Formatting](#formatting) * [Documentation](#documentation) * [Compiler support](#compiler-support) * [Licence](#licence) @@ -438,55 +439,67 @@ The compiled binaries will appear in the `/example/build/bin` dire ## Dev notes -#### Requirements: - * Supported compiler (check compiler support [here](#compiler-support)) - * clang-format-17 ([ubuntu download tutorial](https://ubuntuhandbook.org/index.php/2023/09/how-to-install-clang-17-or-16-in-ubuntu-22-04-20-04/amp/?fbclid=IwAR1ZfJpoiitjwn8aMlKVWpFdkYmUqtaQwraJBju09v1gtc0jQANTgVeCuMY)) +### Building and testing: -
+First build the testing executable: -#### Building and testing: +```shell +cd /test/ +cmake -B build +cd build +make +``` -1. Build the testing executable: +or alternatively: - ```shell - cd /test/ - cmake -B build - cd build - make - ``` +```shell +cd /test/ +mkdir build && cd build +cmake .. +make +``` - or +> **NOTE:** Building on Windows - use the `-G "Unix Makefiles"` option when running CMake to build a GNU Make project instead of a default Visual Studio project. - ```shell - cd /test/ - mkdir build && cd build - cmake .. - make - ``` +Run the tests: + +> **NOTE:** The test executable is generated in the `/test/build` directory. -2. Run tests +* All tests: - Run all tests: ```shell - cd /test/build ./test ``` - Run a single test suite: +* A single test suite: + ```shell ./test -ts="" ``` > **Note**: Test suites in the project have the same name as the files they're in. -3. Tips and tricks: +
- * Changing the CMake generator: +### Formatting - If you wish for CMake to generate a different type of project, use the `-G` option, e.g. (building a Make project on Windows instead of a VS project): - ``` - cmake -G "Unix Makefiles" - ``` +> **NOTE:** The project uses `clang-format-17`. +> +> To install this tool on ubuntu run `sudo ./scripts/install_clang_format_17.sh`. +> +> On windows you can download the LLVM package from the official LLVM [GitHub release page](https://github.com/llvm/llvm-project/releases/tag/llvmorg-17.0.1) + +To format the code use run the following: + +```shell +# Unix platforms +./scripts/format_unix.sh +``` + +```shell +# Windows: powershell +./scripts/format_win.ps1 +```

diff --git a/change_log.md b/change_log.md index 2869158..17951be 100644 --- a/change_log.md +++ b/change_log.md @@ -18,7 +18,9 @@ ### Version 1.1 * Added `change_log.md` -* Aligned the `.clang-format` configuration file and renamed `format/unix_like.sh` to `format/unix.sh` +* Aligned the `.clang-format` configuration file and moved formatting scripts to a new directory `/scripts` +* Added the `install_clang_format_17.sh` script +* Added the `format` workflow TODO: * Split dev notes into sections and include them in table of contents diff --git a/format/unix.sh b/scripts/format_unix.sh similarity index 100% rename from format/unix.sh rename to scripts/format_unix.sh diff --git a/format/win.ps1 b/scripts/format_win.ps1 similarity index 100% rename from format/win.ps1 rename to scripts/format_win.ps1 diff --git a/scripts/install_clang_format_17.sh b/scripts/install_clang_format_17.sh new file mode 100644 index 0000000..32b2e23 --- /dev/null +++ b/scripts/install_clang_format_17.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +if command -v clang-format-17 &>/dev/null; then + echo "clang-format-17 is already installed." + exit 0 +fi + +echo "Adding LLVM apt repository" +wget -q -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - >/dev/null 2>&1 +echo | sudo add-apt-repository "deb http://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc)-17 main" &>/dev/null 2>&1 + +echo "Updating package list" +sudo apt update &>/dev/null 2>&1 + +echo "Installing clang-format-17" +sudo apt install clang-format-17 -y &>/dev/null 2>&1 +echo "Success!"