diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ebfa82e --- /dev/null +++ b/.clang-format @@ -0,0 +1,3 @@ +BasedOnStyle: Google +IndentWidth: 4 +ColumnLimit: 100 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2b7a58d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,36 @@ +# It builds the project on multiple operating systems (Ubuntu, Windows, and macOS) + +name: Build Project + +on: + pull_request: + branches: + - main + +jobs: + debug: + name: Build + runs-on: ${{ matrix.config.os }} + strategy: + matrix: + config: + - { name: "Windows gcc", os: windows-latest, cc: "gcc", cxx: "g++" } + - { name: "Ubuntu gcc", os: ubuntu-latest, cc: "gcc", cxx: "g++" } + - { name: "MacOS clang", os: macos-latest, cc: "clang", cxx: "clang++" } + build-configuration: [ Debug, Release ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: true + + - name: Setup Ninja + uses: ashutoshvarma/setup-ninja@master + + - name: Build Project + uses: threeal/cmake-action@v2.1.0 + with: + args: -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build-configuration }} + c-compiler: ${{ matrix.config.cc }} + cxx-compiler: ${{ matrix.config.cxx }} \ No newline at end of file diff --git a/.github/workflows/clang-format-dispatch.yml b/.github/workflows/clang-format-dispatch.yml new file mode 100644 index 0000000..05083d3 --- /dev/null +++ b/.github/workflows/clang-format-dispatch.yml @@ -0,0 +1,34 @@ +# This workflow should only be run by administrators + +name: ClangFormat correction + +on: + workflow_dispatch: + +jobs: + ClangFormat: + name: ClangFormat correction + runs-on: ubuntu-22.04 + + # Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository. + permissions: + contents: write + + steps: + # Clone Repo + - name: Checkout + uses: actions/checkout@v4 + + - name: Install clang-format + run: sudo apt-get update && sudo apt-get install -y clang-format + + - name: Format code + #run: clang-format -i **/*.cpp + run: find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -exec clang-format -i {} \; + + # Commit all changed files back to the repository + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'Apply Clang formatting' + create_branch: false \ No newline at end of file diff --git a/.github/workflows/clang-format-pr.yml b/.github/workflows/clang-format-pr.yml new file mode 100644 index 0000000..085384f --- /dev/null +++ b/.github/workflows/clang-format-pr.yml @@ -0,0 +1,34 @@ +# This workflow is from https://github.com/official-stockfish/Stockfish/blob/master/.github/workflows/clang-format.yml#L23 + +# This workflow will run clang-format and comment on the PR. +# Because of security reasons, it is crucial that this workflow +# executes no shell script nor runs make. +# Read this before editing: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ + +name: ClangFormat check +on: + pull_request_target: + branches: + - "main" + paths: + - "**.cpp" + - "**.h" + +# needed for automatic comment in pr +permissions: + pull-requests: write + +jobs: + Clang-Format: + name: Clang-Format + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Run clang-format style check + uses: jidicula/clang-format-action@v4.15.0 + id: clang-format + with: + clang-format-version: "20" \ No newline at end of file diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml new file mode 100644 index 0000000..1f19943 --- /dev/null +++ b/.github/workflows/release-tag.yml @@ -0,0 +1,71 @@ +# This workflow runs when a tag is pushed to the repository point to the main branch. +# It builds the project on multiple operating systems (Ubuntu, Windows, and macOS) and +# creates a pre-release. + +name: Create Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: true + + build: + name: Build Project + needs: release + runs-on: ${{ matrix.config.os }} + strategy: + matrix: + config: + - { name: "Windows gcc", os: windows-latest, cc: "gcc", cxx: "g++" } + - { name: "Ubuntu gcc", os: ubuntu-latest, cc: "gcc", cxx: "g++" } + - { name: "MacOS clang", os: macos-latest, cc: "clang", cxx: "clang++" } + build-configuration: [ Release ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: true + + - name: Setup Ninja + uses: ashutoshvarma/setup-ninja@master + + - name: Build Project + uses: threeal/cmake-action@v2.1.0 + with: + args: -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build-configuration }} + c-compiler: ${{ matrix.config.cc }} + cxx-compiler: ${{ matrix.config.cxx }} + + - name: Compress Build Directory + uses: thedoctor0/zip-release@0.7.5 + with: + type: 'zip' + path: 'build' + filename: '${{ matrix.config.os}}-build.zip' + + - name: Upload Release Asset + uses: alexellis/upload-assets@0.4.0 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + asset_paths: '["${{ matrix.config.os}}-build.zip"]' \ No newline at end of file