From 23434f635a8f768dd7ceea9bb14c0650a5f8a153 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Fri, 29 Nov 2019 10:11:19 +0900 Subject: [PATCH 1/3] initial version --- .gitattributes | 5 +++ .github/workflows/docker-build.yml | 18 +++++++++ .github/workflows/pr-test.yml | 15 ++++++++ .github/workflows/reviewdog.yml | 27 ++++++++++++++ .github/workflows/self-test.yml | 18 +++++++++ .gitignore | 2 + Dockerfile | 17 +++++++++ LICENSE | 21 +++++++++++ README.md | 59 +++++++++++++++++++++++++++++- action.yml | 40 ++++++++++++++++++++ entrypoint.sh | 8 ++++ reviewdog-cpplint.code-workspace | 15 ++++++++ testdata/test.cpp | 21 +++++++++++ testdata/test.hpp | 2 + testdata/test2.c | 9 +++++ testdata/test2.h | 5 +++ 16 files changed, 280 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/workflows/docker-build.yml create mode 100644 .github/workflows/pr-test.yml create mode 100644 .github/workflows/reviewdog.yml create mode 100644 .github/workflows/self-test.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 action.yml create mode 100644 entrypoint.sh create mode 100644 reviewdog-cpplint.code-workspace create mode 100644 testdata/test.cpp create mode 100644 testdata/test.hpp create mode 100644 testdata/test2.c create mode 100644 testdata/test2.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..36cac43 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +* text=auto +*.gitattributes text eol=lf +*.gitignore text eol=lf + +* text eol=lf diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..f7389c1 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,18 @@ +name: Docker Image CI + +on: [push] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - name: Clone repo + uses: actions/checkout@master + with: + fetch-depth: 1 + + - name: Build the Docker image + run: docker build . --file Dockerfile --tag reviewdog-cpplint:$(date +%s) diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml new file mode 100644 index 0000000..1a1eb9e --- /dev/null +++ b/.github/workflows/pr-test.yml @@ -0,0 +1,15 @@ +name: PR test +on: [pull_request] + +jobs: + cpplint: + runs-on: ubuntu-latest + steps: + - name: clone + uses: actions/checkout@master + - uses: srz-zumix/reviewdog-cpplint@master + with: + github_token: ${{ secrets.github_token }} + # reporter: github-pr-review + reporter: github-pr-check + flags: --linelength=50 diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..ee3a509 --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,27 @@ +name: Reviewdog +on: [push, pull_request] + +jobs: + cpplint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: srz-zumix/reviewdog-cpplint@master + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + flags: --linelength=50 # Optional + + shellcheck: + name: runner / shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: shellcheck + uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review # Change reporter. + path: "." # Optional. + pattern: "*.sh" # Optional. + exclude: "./.git/*" # Optional. diff --git a/.github/workflows/self-test.yml b/.github/workflows/self-test.yml new file mode 100644 index 0000000..a8b8500 --- /dev/null +++ b/.github/workflows/self-test.yml @@ -0,0 +1,18 @@ +name: Self test +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: clone + uses: actions/checkout@master + with: + fetch-depth: 2 + - name: testbuild + run: | + cd testdata + g++ --version + g++ ./test.cpp -o test + ls + ./test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..251fb87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cpplint.py +*.exe \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d11151d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.8-alpine +# styleguide cpplint not support python3 +# FROM python:2.7-alpine + +RUN apk --no-cache --update add git \ + && rm -rf /var/cache/apk/* + +RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b /usr/local/bin/ + +# RUN git clone https://github.com/google/styleguide.git cpplint \ +# && cp cpplint/cpplint/cpplint.py /usr/local/bin/cpplint.py \ +# && rm -rf cpplint +RUN pip install cpplint + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f70a73a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 srz_zumix + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index aa4a1be..6a1e5e8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,57 @@ -# action-cpplint -Run cpplint with reviewdog \ No newline at end of file +# GitHub Action: Run cpplint with reviewdog + +[![Docker Image CI Status](https://github.com/srz-zumix/reviewdog-cpplint/workflows/Docker%20Image%20CI/badge.svg?branch=master)](https://github.com/srz-zumix/iutest/actions) +[![Release](https://img.shields.io/github/release/srz-zumix/reviewdog-cpplint.svg?maxAge=43200)](https://github.com/srz-zumix/reviewdog-cpplint/releases) + +[![github-pr-check sample](https://user-images.githubusercontent.com/1439172/67361002-68025080-f5a2-11e9-97b7-530d0531edb4.png)](https://github.com/srz-zumix/reviewdog-cpplint/pull/4) +[![github-pr-review sample](https://user-images.githubusercontent.com/1439172/67361077-9c760c80-f5a2-11e9-98e4-975052cd6fd4.png)](https://github.com/srz-zumix/reviewdog-cpplint/pull/4) + + +This action runs [cpplint](https://pypi.org/project/cpplint/) with [reviewdog](https://github.com/reviewdog/reviewdog) on pull requests to improve code review experience. + +## Inputs + +### `github_token` + +**Required**. Must be in form of `github_token: ${{ secrets.github_token }}`'. + +### `level` + +Optional. Report level for reviewdog [info,warning,error]. +It's same as `-level` flag of reviewdog. +Default is `error`. + +### `reporter` + +Reporter of reviewdog command [github-pr-check,github-pr-review]. +Default is `github-pr-check`. + +### `flags` + +Optional. List of arguments to send to cpplint. +Default is `--extensions=h,hpp,c,cpp,cc,cu,hh,ipp`. + +### `targets` + +Optional. List of file list arguments to send to cpplint. +Default is `--recursive .`. + +## Example Usage + +### [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml) + +```yml +name: Reviewdog +on: [push, pull_request] + +jobs: + cpplint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: srz-zumix/reviewdog-cpplint@master + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + flags: --linelength=50 # Optional +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1cd324f --- /dev/null +++ b/action.yml @@ -0,0 +1,40 @@ +name: 'Run cpplint with reviewdog' +description: '🐶 Run cpplint with reviewdog on pull requests to enforce best practices' +author: 'srz-zumix' + +inputs: + github_token: + description: 'GITHUB_TOKEN' + required: true + level: + description: | + Report level for reviewdog [info,warning,error]. + Default is 'error'. + default: 'error' + reporter: + description: | + Reporter of reviewdog command [github-pr-check,github-pr-review]. + Default is 'github-pr-check'. + default: 'github-pr-check' + flags: + description: | + List of arguments to send to cpplint. + Default is '--extensions=h,hpp,c,cpp,cc,cu,hh,ipp'. + default: '--extensions=h,hpp,c,cpp,cc,cu,hh,ipp' + targets: + description: | + List of file list arguments to send to cpplint. + Default is '--recursive .'. + default: '--recursive .' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.github_token }} + - ${{ inputs.level }} + - ${{ inputs.reporter }} + - ${{ inputs.flags }} + - ${{ inputs.targets }} +branding: + icon: 'plus-circle' + color: 'blue' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..a0f47bb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +cd "${GITHUB_WORKSPACE}" + +export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" + +cpplint ${INPUT_FLAGS} ${INPUT_TARGETS} 2>&1 \ + | reviewdog -efm="%f:%l: %m" -name="cpplint" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" diff --git a/reviewdog-cpplint.code-workspace b/reviewdog-cpplint.code-workspace new file mode 100644 index 0000000..55de849 --- /dev/null +++ b/reviewdog-cpplint.code-workspace @@ -0,0 +1,15 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "editor.rulers": [ + 50, + 80, + 110, + 140 + ], + } +} \ No newline at end of file diff --git a/testdata/test.cpp b/testdata/test.cpp new file mode 100644 index 0000000..308af3e --- /dev/null +++ b/testdata/test.cpp @@ -0,0 +1,21 @@ +// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +// +#include "test.hpp" +#include + +class Hoge +{ +public: + Hoge(int a) : m_a(a) {} +public: + int getA() const { return m_a; } +private: + int m_a; +}; + +int main(int, const char**) +{ + Hoge hoge(42); + std::cout << hoge.getA() << std::endl; + return 0; +} diff --git a/testdata/test.hpp b/testdata/test.hpp new file mode 100644 index 0000000..80cad7a --- /dev/null +++ b/testdata/test.hpp @@ -0,0 +1,2 @@ + +int f(); diff --git a/testdata/test2.c b/testdata/test2.c new file mode 100644 index 0000000..1e275fe --- /dev/null +++ b/testdata/test2.c @@ -0,0 +1,9 @@ +// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +// +#include "test2.h" + +int foge() +{ + return 42; +} + diff --git a/testdata/test2.h b/testdata/test2.h new file mode 100644 index 0000000..a7af7f7 --- /dev/null +++ b/testdata/test2.h @@ -0,0 +1,5 @@ +// test2.h +// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + +#if(__GNUC__>4 ||(__GNUC__==4 && __GNUC_MINOR__>=3))&&defined(__GXX_EXPERIMENTAL_CXX0X__) +#endif \ No newline at end of file From 3ec9d4c813fb55be842d4345940ddc54b5bce17e Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Fri, 29 Nov 2019 10:28:16 +0900 Subject: [PATCH 2/3] fix name and url --- .github/workflows/pr-test.yml | 2 +- .github/workflows/reviewdog.yml | 2 +- README.md | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 1a1eb9e..7240194 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -7,7 +7,7 @@ jobs: steps: - name: clone uses: actions/checkout@master - - uses: srz-zumix/reviewdog-cpplint@master + - uses: reviewdog/action-cpplint@master with: github_token: ${{ secrets.github_token }} # reporter: github-pr-review diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index ee3a509..4901d95 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - uses: srz-zumix/reviewdog-cpplint@master + - uses: reviewdog/action-cpplint@master with: github_token: ${{ secrets.github_token }} reporter: github-pr-review diff --git a/README.md b/README.md index 6a1e5e8..99fe123 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # GitHub Action: Run cpplint with reviewdog -[![Docker Image CI Status](https://github.com/srz-zumix/reviewdog-cpplint/workflows/Docker%20Image%20CI/badge.svg?branch=master)](https://github.com/srz-zumix/iutest/actions) -[![Release](https://img.shields.io/github/release/srz-zumix/reviewdog-cpplint.svg?maxAge=43200)](https://github.com/srz-zumix/reviewdog-cpplint/releases) +[![Docker Image CI Status](https://github.com/reviewdog/action-cpplint/workflows/Docker%20Image%20CI/badge.svg?branch=master)](https://github.com/reviewdog/action-cpplint/actions) +[![Release](https://img.shields.io/github/release/reviewdog/action-cpplint.svg?maxAge=43200)](https://github.com/reviewdog/action-cpplint/releases) -[![github-pr-check sample](https://user-images.githubusercontent.com/1439172/67361002-68025080-f5a2-11e9-97b7-530d0531edb4.png)](https://github.com/srz-zumix/reviewdog-cpplint/pull/4) -[![github-pr-review sample](https://user-images.githubusercontent.com/1439172/67361077-9c760c80-f5a2-11e9-98e4-975052cd6fd4.png)](https://github.com/srz-zumix/reviewdog-cpplint/pull/4) +[![github-pr-check sample](https://user-images.githubusercontent.com/1439172/67361002-68025080-f5a2-11e9-97b7-530d0531edb4.png)](https://github.com/reviewdog/action-cpplint/pull/2) +[![github-pr-review sample](https://user-images.githubusercontent.com/1439172/67361077-9c760c80-f5a2-11e9-98e4-975052cd6fd4.png)](https://github.com/reviewdog/action-cpplint/pull/2) This action runs [cpplint](https://pypi.org/project/cpplint/) with [reviewdog](https://github.com/reviewdog/reviewdog) on pull requests to improve code review experience. @@ -49,7 +49,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - uses: srz-zumix/reviewdog-cpplint@master + - uses: reviewdog/action-cpplint@master with: github_token: ${{ secrets.github_token }} reporter: github-pr-review From 2addb2b266dcbc5ce4e3b885204411db861cf224 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Fri, 29 Nov 2019 10:30:07 +0900 Subject: [PATCH 3/3] sample --- testdata/test.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/testdata/test.cpp b/testdata/test.cpp index 308af3e..a6d8fe7 100644 --- a/testdata/test.cpp +++ b/testdata/test.cpp @@ -1,5 +1,6 @@ // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa // +#include #include "test.hpp" #include @@ -13,9 +14,24 @@ class Hoge int m_a; }; +// https://github.com/yohhoy/cpp-longest-identifier/wiki +bool longest_identifier() +{ + std::atomic x(3); + + int expected = 3; + const bool result = std::atomic_compare_exchange_strong_explicit(&x, &expected, 2, + std::memory_order_acquire, + std::memory_order_acquire); + + std::cout << std::boolalpha << result << " " << x.load() << " " << expected << std::endl; + return result; +} + int main(int, const char**) { Hoge hoge(42); + longest_identifier(); std::cout << hoge.getA() << std::endl; return 0; -} +} \ No newline at end of file