From 607f166fda769e3b6b546858a012df847afd7c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:12:37 +0100 Subject: [PATCH 1/8] create clang-format workflow --- .clang-format | 1 + .github/workflows/clang-format.yml | 59 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/clang-format.yml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..2593ef5 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: Google \ No newline at end of file diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000..7041661 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,59 @@ +# 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: Clang-Format +on: + pull_request_target: + branches: + - "master" + paths: + - "**.cpp" + - "**.h" + +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@f62da5e3d3a2d88ff364771d9d938773a618ab5e # @v4.11.0 + id: clang-format + continue-on-error: true + with: + clang-format-version: "18" + exclude-regex: "incbin" + + - name: Comment on PR + if: steps.clang-format.outcome == 'failure' + uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # @v2.5.0 + with: + message: | + clang-format 18 needs to be run on this PR. + If you do not have clang-format installed, the maintainer will run it when merging. + For the exact version please see https://packages.ubuntu.com/noble/clang-format-18. + + _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ + comment_tag: execution + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Comment on PR + if: steps.clang-format.outcome != 'failure' + uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # @v2.5.0 + with: + message: | + _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ + create_if_not_exists: false + comment_tag: execution + mode: delete + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From b8cb628b50ac2eddb153fb165fdd92bee79a714e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:41:32 +0100 Subject: [PATCH 2/8] update workflow/clang-format config --- .clang-format | 4 +++- .github/workflows/clang-format.yml | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.clang-format b/.clang-format index 2593ef5..ebfa82e 100644 --- a/.clang-format +++ b/.clang-format @@ -1 +1,3 @@ -BasedOnStyle: Google \ No newline at end of file +BasedOnStyle: Google +IndentWidth: 4 +ColumnLimit: 100 \ No newline at end of file diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 7041661..7d980ad 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -9,11 +9,12 @@ name: Clang-Format on: pull_request_target: branches: - - "master" + - "main" paths: - "**.cpp" - "**.h" +# needed for automatic comment in pr permissions: pull-requests: write @@ -27,33 +28,31 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Run clang-format style check - uses: jidicula/clang-format-action@f62da5e3d3a2d88ff364771d9d938773a618ab5e # @v4.11.0 + uses: jidicula/clang-format-action@v4.15.0 id: clang-format continue-on-error: true with: - clang-format-version: "18" - exclude-regex: "incbin" + clang-format-version: "20" - name: Comment on PR if: steps.clang-format.outcome == 'failure' - uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # @v2.5.0 + uses: thollander/actions-comment-pull-request@v3.0.1 with: message: | - clang-format 18 needs to be run on this PR. + clang-format 20 needs to be run on this PR. If you do not have clang-format installed, the maintainer will run it when merging. - For the exact version please see https://packages.ubuntu.com/noble/clang-format-18. _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ - comment_tag: execution - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + comment-tag: execution + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Comment on PR if: steps.clang-format.outcome != 'failure' - uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # @v2.5.0 + uses: thollander/actions-comment-pull-request@v3.0.1 with: message: | _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ - create_if_not_exists: false - comment_tag: execution + create-if-not-exists: false + comment-tag: execution mode: delete - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From c4fdb571a6d72ecd93c52fe8d398587a8f0a7268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Sat, 22 Mar 2025 16:53:04 +0100 Subject: [PATCH 3/8] create format workflow --- .github/workflows/clang-format-dispatch.yml | 33 +++++++++++++++++++ .../{clang-format.yml => clang-format-pr.yml} | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/clang-format-dispatch.yml rename .github/workflows/{clang-format.yml => clang-format-pr.yml} (98%) diff --git a/.github/workflows/clang-format-dispatch.yml b/.github/workflows/clang-format-dispatch.yml new file mode 100644 index 0000000..c942da2 --- /dev/null +++ b/.github/workflows/clang-format-dispatch.yml @@ -0,0 +1,33 @@ +# 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.yml b/.github/workflows/clang-format-pr.yml similarity index 98% rename from .github/workflows/clang-format.yml rename to .github/workflows/clang-format-pr.yml index 7d980ad..8efbbec 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format-pr.yml @@ -5,7 +5,7 @@ # executes no shell script nor runs make. # Read this before editing: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ -name: Clang-Format +name: ClangFormat check on: pull_request_target: branches: From 35c44dee651b8f2c4784be1bfd9537f06c8947c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Sat, 22 Mar 2025 22:55:30 +0100 Subject: [PATCH 4/8] create build and release workflow --- .github/workflows/build.yml | 31 ++++++++++++++++ .github/workflows/release-tag.yml | 60 +++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release-tag.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..023de73 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,31 @@ +# It builds the project on multiple operating systems (Ubuntu, Windows, and macOS) + +on: + pull_request: + branches: + - main + +jobs: + debug: + name: Debug Build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: true + + - name: Build Project + uses: threeal/cmake-action@v2.1.0 + with: + run-build: false + + - name: Build Debug + run: cmake --build debug --config Debug + + - name: Build Release + run: cmake --build release --config Release \ 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..b18497a --- /dev/null +++ b/.github/workflows/release-tag.yml @@ -0,0 +1,60 @@ +# This workflow runs when a tag is pushed to the repository. +# It builds the project on multiple operating systems (Ubuntu, Windows, and macOS) and +# creates a pre-release. + +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Build Project + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: true + + - name: Build Project + uses: threeal/cmake-action@v2.1.0 + with: + run-build: false + + - name: Build Release + run: cmake --build build --config Release + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.release.outputs.upload_url }} + asset_path: build/ + asset_name: build-${{ matrix.os }} + asset_content_type: application/zip + + release: + needs: build + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + 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 \ No newline at end of file From d7bbe1f94dd5f1f1bd573668e4778188ef995866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Sun, 23 Mar 2025 00:12:22 +0100 Subject: [PATCH 5/8] implement build Debug and Release --- .github/workflows/build.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 023de73..38b986d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,7 @@ # It builds the project on multiple operating systems (Ubuntu, Windows, and macOS) +name: Build Project + on: pull_request: branches: @@ -12,6 +14,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] + build-configuration: [ Debug, Release ] steps: - name: Checkout repository @@ -22,10 +25,4 @@ jobs: - name: Build Project uses: threeal/cmake-action@v2.1.0 with: - run-build: false - - - name: Build Debug - run: cmake --build debug --config Debug - - - name: Build Release - run: cmake --build release --config Release \ No newline at end of file + args: -DCMAKE_BUILD_TYPE=${{ matrix.build-configuration }} \ No newline at end of file From a5d5b80e8414c97d91892cd6f846d7a04a0b1a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Sun, 23 Mar 2025 01:21:06 +0100 Subject: [PATCH 6/8] improve build workflow with specific build environment --- .github/workflows/build.yml | 14 +++++++++++--- .github/workflows/clang-format-dispatch.yml | 1 + .github/workflows/release-tag.yml | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38b986d..ca5f4ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,10 +10,13 @@ on: jobs: debug: name: Debug Build - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.config.os }} strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] + config: + - { name: "Windows MSVC", os: windows-latest, cc: "cl", cxx: "cl" } + - { 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: @@ -22,7 +25,12 @@ jobs: with: submodules: true + - name: Setup Ninja + uses: ashutoshvarma/setup-ninja@master + - name: Build Project uses: threeal/cmake-action@v2.1.0 with: - args: -DCMAKE_BUILD_TYPE=${{ matrix.build-configuration }} \ No newline at end of file + 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 index c942da2..05083d3 100644 --- a/.github/workflows/clang-format-dispatch.yml +++ b/.github/workflows/clang-format-dispatch.yml @@ -1,6 +1,7 @@ # This workflow should only be run by administrators name: ClangFormat correction + on: workflow_dispatch: diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index b18497a..5aabc66 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -2,6 +2,8 @@ # It builds the project on multiple operating systems (Ubuntu, Windows, and macOS) and # creates a pre-release. +name: Create Release + on: push: tags: From a163a6f4949bdeb63eb264d3e80b3ddfafcbcd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Sun, 23 Mar 2025 11:04:48 +0100 Subject: [PATCH 7/8] update release-tag.yml --- .github/workflows/build.yml | 2 +- .github/workflows/release-tag.yml | 72 ++++++++++++++++++------------- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca5f4ae..f466be4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: jobs: debug: - name: Debug Build + name: Build runs-on: ${{ matrix.config.os }} strategy: matrix: diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index 5aabc66..dc061f3 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -10,12 +10,37 @@ on: - 'v*' jobs: + release: + name: Create Release + needs: build + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + 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 - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.config.os }} strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] + config: + - { name: "Windows MSVC", os: windows-latest, cc: "cl", cxx: "cl" } + - { 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 @@ -23,40 +48,29 @@ jobs: with: submodules: true + - name: Setup Ninja + uses: ashutoshvarma/setup-ninja@master + - name: Build Project uses: threeal/cmake-action@v2.1.0 with: - run-build: false + args: -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build-configuration }} + c-compiler: ${{ matrix.config.cc }} + cxx-compiler: ${{ matrix.config.cxx }} - - name: Build Release - run: cmake --build build --config Release + - name: Compress Build Directory + uses: thedoctor0/zip-release@0.7.5 + with: + type: 'zip' + path: 'build' + filename: 'build.zip' - name: Upload Release Asset uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - upload_url: ${{ needs.release.outputs.upload_url }} - asset_path: build/ - asset_name: build-${{ matrix.os }} - asset_content_type: application/zip - - release: - needs: build - runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} - 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 \ No newline at end of file + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build.zip + asset_name: ${{ matrix.config.os }}.zip + asset_content_type: application/zip \ No newline at end of file From 44ad40d18243a69326c00aeed7c6a274b21af512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= <134922046+LordofGhost@users.noreply.github.com> Date: Sun, 23 Mar 2025 14:10:07 +0100 Subject: [PATCH 8/8] small improvements - remove pr message from format check - switch from msvc to gcc - change the way how files are pushed to a release --- .github/workflows/build.yml | 2 +- .github/workflows/clang-format-pr.yml | 26 +------------------------- .github/workflows/release-tag.yml | 19 +++++++------------ 3 files changed, 9 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f466be4..2b7a58d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: config: - - { name: "Windows MSVC", os: windows-latest, cc: "cl", cxx: "cl" } + - { 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 ] diff --git a/.github/workflows/clang-format-pr.yml b/.github/workflows/clang-format-pr.yml index 8efbbec..085384f 100644 --- a/.github/workflows/clang-format-pr.yml +++ b/.github/workflows/clang-format-pr.yml @@ -30,29 +30,5 @@ jobs: - name: Run clang-format style check uses: jidicula/clang-format-action@v4.15.0 id: clang-format - continue-on-error: true with: - clang-format-version: "20" - - - name: Comment on PR - if: steps.clang-format.outcome == 'failure' - uses: thollander/actions-comment-pull-request@v3.0.1 - with: - message: | - clang-format 20 needs to be run on this PR. - If you do not have clang-format installed, the maintainer will run it when merging. - - _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ - comment-tag: execution - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Comment on PR - if: steps.clang-format.outcome != 'failure' - uses: thollander/actions-comment-pull-request@v3.0.1 - with: - message: | - _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ - create-if-not-exists: false - comment-tag: execution - mode: delete - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + clang-format-version: "20" \ No newline at end of file diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index dc061f3..1f19943 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -1,4 +1,4 @@ -# This workflow runs when a tag is pushed to the repository. +# 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. @@ -12,10 +12,7 @@ on: jobs: release: name: Create Release - needs: build runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -33,11 +30,12 @@ jobs: build: name: Build Project + needs: release runs-on: ${{ matrix.config.os }} strategy: matrix: config: - - { name: "Windows MSVC", os: windows-latest, cc: "cl", cxx: "cl" } + - { 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 ] @@ -63,14 +61,11 @@ jobs: with: type: 'zip' path: 'build' - filename: 'build.zip' + filename: '${{ matrix.config.os}}-build.zip' - name: Upload Release Asset - uses: actions/upload-release-asset@v1 + uses: alexellis/upload-assets@0.4.0 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: build.zip - asset_name: ${{ matrix.config.os }}.zip - asset_content_type: application/zip \ No newline at end of file + asset_paths: '["${{ matrix.config.os}}-build.zip"]' \ No newline at end of file