From 19490993c53e09c61e35ab822f90ef42193aa1d7 Mon Sep 17 00:00:00 2001 From: MuhammadTahaNaveed Date: Thu, 29 Dec 2022 10:47:53 +0500 Subject: [PATCH 1/6] rename "clang-format.5" to ".clang-format" --- clang-format.5 => .clang-format | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename clang-format.5 => .clang-format (100%) diff --git a/clang-format.5 b/.clang-format similarity index 100% rename from clang-format.5 rename to .clang-format From 3d94eab4910257f96ec39ed27297163f719a2c2e Mon Sep 17 00:00:00 2001 From: MuhammadTahaNaveed Date: Thu, 29 Dec 2022 11:01:52 +0500 Subject: [PATCH 2/6] add configuration for pre-commit to run --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..1ce1a4cca --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v14.0.6 + hooks: + - id: clang-format + files: \.(c|cpp|h)$ \ No newline at end of file From a3146e2a3a44d2db318d14d008ae973c44321b86 Mon Sep 17 00:00:00 2001 From: MuhammadTahaNaveed Date: Thu, 29 Dec 2022 11:06:18 +0500 Subject: [PATCH 3/6] add workflow for code format - this workflow will run on push or pull request to master branch. - the workflow will fail if any PR or push is not abiding by the code standards defined in .clang-format - You can also run "pre-commit" on your repo locally. --- .github/workflows/format.yaml | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/format.yaml diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 000000000..1a581a40f --- /dev/null +++ b/.github/workflows/format.yaml @@ -0,0 +1,36 @@ +name: Code Format Test + +on: + pull_request: + branches: [ "master" , "code-format-workflow" ] + + push: + branches: [ "master" ] + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install clang-format-12 + run: sudo apt-get install clang-format-12 + + - name: Install and run pre-commit + run: | + python -m pip install pre-commit + git fetch origin + pre-commit run --show-diff-on-failure --color=always --from-ref origin/${{ github.event.pull_request.base.ref }} --to-ref ${{ github.event.pull_request.head.sha }} + id: precommit + + - name: Upload pre-commit changes + if: failure() && steps.precommit.outcome == 'failure' + uses: rhaschke/upload-git-patch-action@main + with: + name: pre-commit \ No newline at end of file From 4429fa81825988cedcf3c1cc8946e2ada34e2477 Mon Sep 17 00:00:00 2001 From: MuhammadTahaNaveed Date: Thu, 29 Dec 2022 11:36:25 +0500 Subject: [PATCH 4/6] update for workflow to run on master branch only. --- .github/workflows/format.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 1a581a40f..72483e862 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -2,7 +2,7 @@ name: Code Format Test on: pull_request: - branches: [ "master" , "code-format-workflow" ] + branches: [ "master" ] push: branches: [ "master" ] From 607ec87b3184a1908e6b67aa302f87a15afe558c Mon Sep 17 00:00:00 2001 From: MuhammadTahaNaveed Date: Thu, 29 Dec 2022 21:20:47 +0500 Subject: [PATCH 5/6] remove 'upload patch' from workflow - This is because rhaschke/upload-git-patch-action@main is not allowed to be used in apache/age. --- .github/workflows/format.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 72483e862..d663f297a 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -27,10 +27,4 @@ jobs: python -m pip install pre-commit git fetch origin pre-commit run --show-diff-on-failure --color=always --from-ref origin/${{ github.event.pull_request.base.ref }} --to-ref ${{ github.event.pull_request.head.sha }} - id: precommit - - - name: Upload pre-commit changes - if: failure() && steps.precommit.outcome == 'failure' - uses: rhaschke/upload-git-patch-action@main - with: - name: pre-commit \ No newline at end of file + id: precommit \ No newline at end of file From c7fe2917182cfd54d65f2fa22773b4d870fa18c4 Mon Sep 17 00:00:00 2001 From: MuhammadTahaNaveed Date: Fri, 30 Dec 2022 09:27:16 +0500 Subject: [PATCH 6/6] update workflow --- .github/workflows/format.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index d663f297a..da7c6267d 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -26,5 +26,5 @@ jobs: run: | python -m pip install pre-commit git fetch origin - pre-commit run --show-diff-on-failure --color=always --from-ref origin/${{ github.event.pull_request.base.ref }} --to-ref ${{ github.event.pull_request.head.sha }} + pre-commit run --show-diff-on-failure --color=always --from-ref origin/master --to-ref HEAD id: precommit \ No newline at end of file