Skip to content

Commit

Permalink
added the format workflow + utility
Browse files Browse the repository at this point in the history
  • Loading branch information
SpectraL519 committed Feb 15, 2024
1 parent 4f78ac9 commit 136da2a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 31 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -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 {} \;
73 changes: 43 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<br />

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -438,55 +439,67 @@ The compiled binaries will appear in the `<project-root>/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:

<br />
First build the testing executable:

#### Building and testing:
```shell
cd <project-root>/test/
cmake -B build
cd build
make
```

1. Build the testing executable:
or alternatively:

```shell
cd <project-root>/test/
cmake -B build
cd build
make
```
```shell
cd <project-root>/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 <project-root>/test/
mkdir build && cd build
cmake ..
make
```
Run the tests:

> **NOTE:** The test executable is generated in the `<project-root>/test/build` directory.

2. Run tests
* All tests:

Run all tests:
```shell
cd <project-root>/test/build
./test
```

Run a single test suite:
* A single test suite:

```shell
./test -ts="<test-suite-name>"
```

> **Note**: Test suites in the project have the same name as the files they're in.
3. Tips and tricks:
<br />
* 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
```
<br />
<br />
Expand Down
4 changes: 3 additions & 1 deletion change_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<project-root>/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
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions scripts/install_clang_format_17.sh
Original file line number Diff line number Diff line change
@@ -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!"

0 comments on commit 136da2a

Please sign in to comment.