Skip to content

Commit 8059962

Browse files
committed
Move coding-style check to GitHub actions
1 parent 0344851 commit 8059962

File tree

3 files changed

+78
-24
lines changed

3 files changed

+78
-24
lines changed

.circleci/config.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -886,25 +886,6 @@ jobs:
886886
command: test/docsCodeStyle.sh
887887
- matrix_notify_failure_unless_pr
888888

889-
chk_coding_style:
890-
<<: *base_cimg_small
891-
steps:
892-
- checkout
893-
- run:
894-
name: Install shellcheck
895-
command: |
896-
sudo apt -q update
897-
sudo apt install -y shellcheck
898-
- run:
899-
name: Check for C++ coding style
900-
command: scripts/check_style.sh
901-
- run:
902-
name: checking shell scripts
903-
command: scripts/chk_shellscripts/chk_shellscripts.sh
904-
- run:
905-
name: Check for broken symlinks
906-
command: scripts/check_symlinks.sh
907-
- matrix_notify_failure_unless_pr
908889

909890
chk_errorcodes:
910891
<<: *base_ubuntu2404_small
@@ -1876,7 +1857,6 @@ workflows:
18761857
jobs:
18771858
# basic checks
18781859
- chk_spelling: *requires_nothing
1879-
- chk_coding_style: *requires_nothing
18801860
# DISABLED FOR 0.6.0 - chk_docs_examples: *requires_nothing
18811861
- chk_buglist: *requires_nothing
18821862
- chk_proofs: *requires_nothing

.github/workflows/code-style.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Code Style Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: read
10+
11+
jobs:
12+
chk_coding_style:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
16+
17+
- name: Install dependencies
18+
run: |
19+
sudo apt -q update
20+
sudo apt install -y shellcheck git
21+
22+
- name: Check for C++ coding style
23+
id: style-check
24+
run: |
25+
output=$(scripts/check_style.sh 2>&1) || {
26+
{
27+
echo "output<<EOF"
28+
echo "$output"
29+
echo "EOF"
30+
} >> $GITHUB_OUTPUT
31+
exit 1
32+
}
33+
34+
- name: Comment PR on failure
35+
if: ${{ failure() && steps.style-check.outcome == 'failure' }}
36+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd #v8.0.0
37+
with:
38+
script: |
39+
const output = `${{ steps.style-check.outputs.output }}`;
40+
const body = `There was an error when running \`Code Style Check\` for commit \`${context.sha}\`:
41+
\`\`\`
42+
${output}
43+
\`\`\`
44+
Please check that your changes are working as intended.`;
45+
46+
await github.rest.issues.createComment({
47+
issue_number: context.issue.number,
48+
owner: context.repo.owner,
49+
repo: context.repo.repo,
50+
body: body
51+
});
52+
53+
for (const line of output.split('\n')) {
54+
const match = line.match(/^([^:]+\.(cpp|h)):(\d+):/);
55+
if (!match) continue;
56+
const [, filePath, , lineNumber] = match;
57+
await github.rest.pulls.createReviewComment({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
pull_number: context.issue.number,
61+
commit_id: context.sha,
62+
path: filePath,
63+
line: parseInt(lineNumber),
64+
side: 'RIGHT',
65+
body: 'Coding style error'
66+
});
67+
}
68+
69+
- name: checking shell scripts
70+
run: scripts/chk_shellscripts/chk_shellscripts.sh
71+
72+
- name: Check for broken symlinks
73+
run: scripts/check_symlinks.sh

scripts/check_style.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ if [[ "$WHITESPACE" != "" ]]
3333
then
3434
echo "Error: Trailing whitespace found:" | tee -a "$ERROR_LOG"
3535
echo "$WHITESPACE" | tee -a "$ERROR_LOG"
36-
scripts/ci/post_style_errors_on_github.sh "$ERROR_LOG"
37-
exit 1
3836
fi
3937

4038
function preparedGrep
@@ -78,7 +76,10 @@ if [[ "$FORMATEDERRORS" != "" ]]
7876
then
7977
echo "Coding style error:" | tee -a "$ERROR_LOG"
8078
echo "$FORMATEDERRORS" | tee -a "$ERROR_LOG"
81-
scripts/ci/post_style_errors_on_github.sh "$ERROR_LOG"
82-
exit 1
79+
fi
80+
81+
if [[ -s "$ERROR_LOG" ]]
82+
then
83+
exit 1
8384
fi
8485
)

0 commit comments

Comments
 (0)