-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Move coding-style check to GitHub actions #16266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
474a309
1b686e2
efa9895
bd22201
e905135
bc25670
9e45e2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| name: Code Style Check | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| chk_coding_style: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt -q update | ||
| sudo apt install -y shellcheck git openssl | ||
|
|
||
| - name: Check for C++ coding style | ||
| id: style-check | ||
| run: | | ||
| output=$(scripts/check_style.sh 2>&1) || { | ||
| delimiter="$(openssl rand -hex 8)" | ||
| { | ||
| echo "output<<${delimiter}" | ||
| echo "$output" | ||
| echo "${delimiter}" | ||
| } >> $GITHUB_OUTPUT | ||
| exit 1 | ||
| } | ||
|
|
||
| - name: Comment PR on failure | ||
| if: ${{ failure() && steps.style-check.outcome == 'failure' }} | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd #v8.0.0 | ||
| env: | ||
| STYLE_OUTPUT: ${{ steps.style-check.outputs.output }} | ||
| with: | ||
| script: | | ||
| const output = process.env.STYLE_OUTPUT; | ||
| const headSha = context.payload.pull_request.head.sha; | ||
| const body = `There was an error when running \`Code Style Check\` for commit \`${headSha}\`: | ||
| \`\`\` | ||
| ${output} | ||
| \`\`\` | ||
| Please check that your changes are working as intended.`; | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: body | ||
| }); | ||
|
|
||
| for (const line of output.split('\n')) { | ||
| const match = line.match(/^\[([^\]]+)\]\s*([^:]+\.(cpp|h)):(\d+):/); | ||
| if (!match) continue; | ||
| const [, errorDescription, filePath, , lineNumber] = match; | ||
| try { | ||
| await github.rest.pulls.createReviewComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.issue.number, | ||
| commit_id: headSha, | ||
| path: filePath, | ||
| line: parseInt(lineNumber), | ||
| side: 'RIGHT', | ||
| body: `**Coding style error:** ${errorDescription}` | ||
| }); | ||
| } catch (error) { | ||
| console.log(`Could not add inline comment for ${filePath}:${lineNumber}: ${error.message}`); | ||
| } | ||
| } | ||
|
|
||
| - name: checking shell scripts | ||
| run: scripts/chk_shellscripts/chk_shellscripts.sh | ||
|
|
||
| - name: Check for broken symlinks | ||
| run: scripts/check_symlinks.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
| #include "libsolutil/Common.h" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style error: Use angle brackets for includes |
||
|
|
||
| using namespace std; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style error: Do not use 'using namespace std' |
||
|
|
||
| namespace solidity::util { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style error: Missing space before opening brace in namespace |
||
|
|
||
| const int BAD_CONST = 42; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style error: const should be on the right side of the type |
||
|
|
||
| void testFunction() | ||
| { | ||
| if(true) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style error: Missing space after keyword There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style error: Opening brace on same line as if |
||
| int& badRef = BAD_CONST; | ||
| auto x = move(badRef); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style error: Use std::move |
||
| } | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.