Skip to content

Commit 8167bae

Browse files
committed
Split coding standard validation into multiple workflows
This work simplifies the main workflow and applies optimizations such a matrix strategies to the workflows implementing the various validations.
1 parent 3bbd6eb commit 8167bae

File tree

5 files changed

+244
-164
lines changed

5 files changed

+244
-164
lines changed

.github/workflows/validate-coding-standards.yml

Lines changed: 20 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -5,181 +5,37 @@ on:
55
push:
66
branches:
77
- main
8-
- "rc/**"
98
- next
109
pull_request:
1110
branches:
1211
- main
13-
- "rc/**"
1412
- next
1513

16-
env:
17-
XARGS_MAX_PROCS: 4
14+
permissions:
15+
contents: read
16+
actions: write
1817

1918
jobs:
2019
validate-package-files:
2120
name: Validate Package Files
22-
runs-on: ubuntu-22.04
23-
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v2
21+
uses: ./.github/workflows/validate-package-files.yml
22+
with:
23+
ref: ${{ github.ref }}
2624

27-
- name: Install Python
28-
uses: actions/setup-python@v4
29-
with:
30-
python-version: "3.9"
31-
32-
- name: Install CodeQL
33-
run: |
34-
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
35-
gh extensions install github/gh-codeql
36-
gh codeql set-version "$VERSION"
37-
gh codeql install-stub
38-
env:
39-
GITHUB_TOKEN: ${{ github.token }}
40-
41-
- name: Install generate_package_files.py dependencies
42-
run: pip install -r scripts/requirements.txt
43-
44-
- name: Validate Package Descriptions (CPP)
45-
run: |
46-
python scripts/validate-rule-package.py rule_packages/cpp/*.json
47-
48-
- name: Validate Package Descriptions (C)
49-
run: |
50-
python scripts/validate-rule-package.py rule_packages/c/*.json
51-
52-
- name: Validate Package Descriptions consistency (CPP)
53-
run: |
54-
python scripts/verify_rule_package_consistency.py cpp
55-
56-
- name: Validate Package Descriptions consistency (C)
57-
run: |
58-
python scripts/verify_rule_package_consistency.py c
59-
60-
- name: Validate Package Files (CPP)
61-
run: |
62-
find rule_packages/cpp -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py cpp
63-
git diff
64-
git diff --compact-summary
65-
git diff --quiet
66-
67-
- name: Validate Package Files (C)
68-
run: |
69-
find rule_packages/c -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py c
70-
git diff
71-
git diff --compact-summary
72-
git diff --quiet
73-
74-
validate-codeql-format:
75-
name: "Validate CodeQL Format"
76-
runs-on: ubuntu-22.04
77-
steps:
78-
- name: Checkout
79-
uses: actions/checkout@v2
80-
81-
- name: Install CodeQL
82-
run: |
83-
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
84-
gh extensions install github/gh-codeql
85-
gh codeql set-version "$VERSION"
86-
gh codeql install-stub
87-
env:
88-
GITHUB_TOKEN: ${{ github.token }}
89-
90-
- name: Validate CodeQL Format (CPP)
91-
run: |
92-
find cpp -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
93-
94-
git diff
95-
git diff --compact-summary
96-
git diff --quiet
97-
98-
- name: Validate CodeQL Format (C)
99-
run: |
100-
find c -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
101-
102-
git diff
103-
git diff --compact-summary
104-
git diff --quiet
25+
validate-codeql-query-formatting:
26+
name: "Validate CodeQL Query Formatting"
27+
uses: ./.github/workflows/validate-query-formatting.yml
28+
with:
29+
ref: ${{ github.ref }}
10530

10631
validate-query-help-files:
10732
name: Validate Query Help Files
108-
runs-on: ubuntu-22.04
109-
steps:
110-
- name: Checkout
111-
uses: actions/checkout@v2
112-
113-
- name: Validate CPP Query Help Files
114-
run: |
115-
exit_code=0
116-
for help_file in `find cpp -name '*.md'`
117-
do
118-
if grep -F -q 'REPLACE THIS' "$help_file" > /dev/null
119-
then
120-
echo "Help file $help_file contains placeholders that are not replaced or removed!"
121-
exit_code=1
122-
fi
123-
done
124-
125-
exit $exit_code
126-
127-
- name: Validate C Query Help Files
128-
run: |
129-
exit_code=0
130-
for help_file in `find c -name '*.md'`
131-
do
132-
if grep -F -q 'REPLACE THIS' "$help_file" > /dev/null
133-
then
134-
echo "Help file $help_file contains placeholders that are not replaced or removed!"
135-
exit_code=1
136-
fi
137-
done
138-
139-
exit $exit_code
140-
141-
validate-cpp-test-files:
142-
name: Validate C++ Test Files
143-
runs-on: ubuntu-22.04
144-
steps:
145-
- name: Checkout
146-
uses: actions/checkout@v2
147-
148-
- name: Install clang-format
149-
run: |
150-
sudo apt-get install --yes --quiet --no-install-recommends clang-format
151-
echo "::debug::$(clang-format -version)"
152-
153-
- name: Validate C++ Test Files
154-
run: |
155-
if ! test -f .clang-format; then
156-
echo "Cannot find .clang-format in '$PWD'. Exiting..."
157-
fi
158-
159-
find cpp/*/test -name \*.cpp -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" clang-format --style=file -i --verbose
160-
git diff
161-
git diff --compact-summary
162-
git diff --quiet
163-
164-
validate-c-test-files:
165-
name: Validate C Test Files
166-
runs-on: ubuntu-22.04
167-
steps:
168-
- name: Checkout
169-
uses: actions/checkout@v2
170-
171-
- name: Install clang-format
172-
run: |
173-
sudo apt-get install --yes --quiet --no-install-recommends clang-format
174-
echo "::debug::$(clang-format -version)"
175-
176-
- name: Validate C++ Test Files
177-
run: |
178-
if ! test -f .clang-format; then
179-
echo "Cannot find .clang-format in '$PWD'. Exiting..."
180-
fi
181-
182-
find c/*/test -name \*.c -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" clang-format --style=file -i --verbose
183-
git diff
184-
git diff --compact-summary
185-
git diff --quiet
33+
uses: ./.github/workflows/validate-query-help.yml
34+
with:
35+
ref: ${{ github.ref }}
36+
37+
validate-test-case-formatting:
38+
name: Validate Test
39+
uses: ./.github/workflows/validate-query-test-case-formatting.yml
40+
with:
41+
ref: ${{ github.ref }}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Validate Package Files
2+
on:
3+
workflow_call:
4+
inputs:
5+
ref:
6+
description: 'The ref to validate. Defaults to the default branch.'
7+
required: true
8+
type: string
9+
workflow_dispatch:
10+
inputs:
11+
ref:
12+
description: 'The ref to validate. Defaults to the default branch.'
13+
required: true
14+
type: string
15+
16+
jobs:
17+
validate-package-files:
18+
strategy:
19+
matrix:
20+
language: [cpp, c]
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
ref: ${{ inputs.ref }}
27+
28+
- name: Install Python
29+
uses: actions/setup-python@v4
30+
with:
31+
python-version: "3.9"
32+
33+
- name: Install CodeQL
34+
run: |
35+
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
36+
gh extensions install github/gh-codeql
37+
gh codeql set-version "$VERSION"
38+
gh codeql install-stub
39+
env:
40+
GITHUB_TOKEN: ${{ github.token }}
41+
42+
- name: Install generate_package_files.py dependencies
43+
run: pip install -r scripts/requirements.txt
44+
45+
- name: Validate Package Descriptions
46+
env:
47+
LANGUAGE: ${{ matrix.language }}
48+
run: |
49+
python scripts/validate-rule-package.py rule_packages/$LANGUAGE/*.json
50+
51+
- name: Validate Package Descriptions consistency
52+
env:
53+
LANGUAGE: ${{ matrix.language }}
54+
run: |
55+
python scripts/verify_rule_package_consistency.py $LANGUAGE
56+
57+
- name: Validate Current versus Expected Package Files
58+
env:
59+
LANGUAGE: ${{ matrix.language }}
60+
run: |
61+
find rule_packages/$LANGUAGE -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py $LANGUAGE
62+
git diff
63+
git diff --compact-summary
64+
git diff --quiet
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "Validate Query Formatting"
2+
on:
3+
workflow_call:
4+
inputs:
5+
ref:
6+
description: 'The ref to validate. Defaults to the default branch.'
7+
required: true
8+
type: string
9+
xargs-max-procs:
10+
description: 'The maximum number of processes to use for xargs.'
11+
required: false
12+
type: number
13+
default: 4
14+
workflow_dispatch:
15+
inputs:
16+
ref:
17+
description: 'The ref to validate. Defaults to the default branch.'
18+
required: true
19+
type: string
20+
xargs-max-procs:
21+
description: 'The maximum number of processes to use for xargs.'
22+
required: false
23+
type: number
24+
default: 4
25+
26+
env:
27+
XARGS_MAX_PROCS: ${{ inputs.xargs-max-procs }}
28+
29+
jobs:
30+
validate-query-formatting:
31+
strategy:
32+
matrix:
33+
language: [cpp, c]
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v3
38+
with:
39+
ref: ${{ inputs.ref }}
40+
41+
- name: Install CodeQL
42+
run: |
43+
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
44+
gh extensions install github/gh-codeql
45+
gh codeql set-version "$VERSION"
46+
gh codeql install-stub
47+
env:
48+
GITHUB_TOKEN: ${{ github.token }}
49+
50+
- name: Validate query format
51+
env:
52+
LANGUAGE: ${{ matrix.language }}
53+
run: |
54+
find $LANGUAGE -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
55+
56+
git diff
57+
git diff --compact-summary
58+
git diff --quiet
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Validate Query Help Files
2+
on:
3+
workflow_call:
4+
inputs:
5+
ref:
6+
description: 'The ref to validate. Defaults to the default branch.'
7+
required: true
8+
type: string
9+
workflow_dispatch:
10+
inputs:
11+
ref:
12+
description: 'The ref to validate. Defaults to the default branch.'
13+
required: true
14+
type: string
15+
16+
jobs:
17+
validate-query-help-files:
18+
strategy:
19+
matrix:
20+
language: [cpp, c]
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
ref: ${{ inputs.ref }}
27+
28+
- name: Validate Query Help Files
29+
env:
30+
LANGUAGE: ${{ matrix.language }}
31+
run: |
32+
exit_code=0
33+
for help_file in `find $LANGUAGE -name '*.md'`
34+
do
35+
if grep -F -q 'REPLACE THIS' "$help_file" > /dev/null
36+
then
37+
echo "Help file $help_file contains placeholders that are not replaced or removed!"
38+
exit_code=1
39+
fi
40+
done
41+
42+
exit $exit_code

0 commit comments

Comments
 (0)