diff --git a/.circleci/config.yml b/.circleci/config.yml index 1bb787062772..ce4cef1d9b6b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -918,25 +918,6 @@ jobs: command: test/docsCodeStyle.sh - matrix_notify_failure_unless_pr - chk_coding_style: - <<: *base_cimg_small - steps: - - checkout - - run: - name: Install shellcheck - command: | - sudo apt -q update - sudo apt install -y shellcheck - - run: - name: Check for C++ coding style - command: scripts/check_style.sh - - run: - name: checking shell scripts - command: scripts/chk_shellscripts/chk_shellscripts.sh - - run: - name: Check for broken symlinks - command: scripts/check_symlinks.sh - - matrix_notify_failure_unless_pr chk_errorcodes: <<: *base_ubuntu2404_small @@ -1946,7 +1927,6 @@ workflows: jobs: # basic checks - chk_spelling: *requires_nothing - - chk_coding_style: *requires_nothing # DISABLED FOR 0.6.0 - chk_docs_examples: *requires_nothing - chk_buglist: *requires_nothing - chk_proofs: *requires_nothing diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml new file mode 100644 index 000000000000..714ea6dbd6aa --- /dev/null +++ b/.github/workflows/code-style.yml @@ -0,0 +1,73 @@ +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 + + - name: Check for C++ coding style + id: style-check + run: | + output=$(scripts/check_style.sh 2>&1) || { + { + echo "output<> $GITHUB_OUTPUT + exit 1 + } + + - name: Comment PR on failure + if: ${{ failure() && steps.style-check.outcome == 'failure' }} + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd #v8.0.0 + with: + script: | + const output = `${{ steps.style-check.outputs.output }}`; + const body = `There was an error when running \`Code Style Check\` for commit \`${context.sha}\`: + \`\`\` + ${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(/^([^:]+\.(cpp|h)):(\d+):/); + if (!match) continue; + const [, filePath, , lineNumber] = match; + await github.rest.pulls.createReviewComment({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + commit_id: context.sha, + path: filePath, + line: parseInt(lineNumber), + side: 'RIGHT', + body: 'Coding style error' + }); + } + + - name: checking shell scripts + run: scripts/chk_shellscripts/chk_shellscripts.sh + + - name: Check for broken symlinks + run: scripts/check_symlinks.sh diff --git a/scripts/check_style.sh b/scripts/check_style.sh index d67f7b60ca22..3ab3ee2434f0 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -33,8 +33,6 @@ if [[ "$WHITESPACE" != "" ]] then echo "Error: Trailing whitespace found:" | tee -a "$ERROR_LOG" echo "$WHITESPACE" | tee -a "$ERROR_LOG" - scripts/ci/post_style_errors_on_github.sh "$ERROR_LOG" - exit 1 fi function preparedGrep @@ -78,7 +76,10 @@ if [[ "$FORMATEDERRORS" != "" ]] then echo "Coding style error:" | tee -a "$ERROR_LOG" echo "$FORMATEDERRORS" | tee -a "$ERROR_LOG" - scripts/ci/post_style_errors_on_github.sh "$ERROR_LOG" - exit 1 +fi + +if [[ -s "$ERROR_LOG" ]] +then + exit 1 fi )