Skip to content

Commit fbfb734

Browse files
committed
fixup! ci: Run static code analysis
1 parent 0b9164a commit fbfb734

File tree

2 files changed

+91
-10
lines changed

2 files changed

+91
-10
lines changed

.github/workflows/build.yml

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository }}
3434
outputs:
3535
version: ${{ steps.version.outputs.value }}
36+
should_run: ${{ steps.check_static_analysis.outputs.should_run }}
3637

3738
steps:
3839
- name: Checkout repository
@@ -43,6 +44,15 @@ jobs:
4344
id: version
4445
run: |
4546
echo "value=$(python3 -u scripts/utils.py --version)" >>$GITHUB_OUTPUT
47+
- name: Check if static analysis is required
48+
id: check_static_analysis
49+
run: |
50+
python3 -u scripts/run_static_analysis.py --check-changed-files
51+
if [ $? -eq 0 ]; then
52+
echo "should_run=true" >> $GITHUB_OUTPUT
53+
else
54+
echo "should_run=false" >> $GITHUB_OUTPUT
55+
fi
4656
- name: Remove artifacts
4757
uses: swift-project/delete-artifact@swift
4858
with:
@@ -106,9 +116,58 @@ jobs:
106116
with:
107117
path: docs/html/
108118

119+
staticAnalysis:
120+
runs-on: ubuntu-22.04
121+
needs: [ preBuild, checks ]
122+
if: ${{ needs.preBuild.outputs.should_run == 'true' }}
123+
steps:
124+
- name: Install Qt
125+
uses: jurplel/install-qt-action@v4
126+
with:
127+
version: ${{ env.qt_version }}
128+
modules: 'qtmultimedia'
129+
cache: true
130+
- name: Install dependencies
131+
run: |
132+
sudo apt-get -y install dbus-x11 libglu1-mesa-dev libpulse-dev libdbus-1-dev ninja-build
133+
pip3 install requests conan
134+
- name: Checkout repository
135+
uses: actions/checkout@v4
136+
with:
137+
submodules: true
138+
fetch-depth: 0
139+
- name: Checkout externals
140+
if: ${{ env.use_externals == 'true' }}
141+
uses: actions/checkout@v4
142+
env:
143+
EXTERNALS_PAT: ${{ secrets.EXTERNALS_PAT }}
144+
with:
145+
repository: ${{ env.externals }}
146+
ref: ${{ env.externals_sha }}
147+
token: ${{ env.EXTERNALS_PAT }}
148+
path: 'third_party/externals'
149+
- name: Install conan dependencies
150+
shell: bash
151+
env:
152+
ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
153+
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
154+
run: |
155+
conan profile detect
156+
conan remote disable conancenter
157+
conan remote add swift https://artifactory.swift-project.org/artifactory/api/conan/conan-local
158+
conan remote login swift "$ARTIFACTORY_USER" --password "$ARTIFACTORY_TOKEN"
159+
conan install . --output-folder=build_conan --deployer=full_deploy -pr=ci/profile_linux
160+
- name: Install conan dependencies
161+
shell: bash
162+
run: |
163+
mkdir build && pushd build
164+
cmake .. --preset ci-build-linux-no-pch
165+
popd ..
166+
python3 scripts/run_static_analysis.py --clang-tidy --build-path build --changed-files-ci
167+
109168
buildLinux:
110169
runs-on: ubuntu-22.04
111-
needs: [preBuild, checks]
170+
needs: [preBuild, checks, staticAnalysis]
112171
env:
113172
BACKTRACE_SYMBOL_TOKEN: ${{ secrets.BACKTRACE_SYMBOL_TOKEN }}
114173
BACKTRACE_MINIDUMP_TOKEN: ${{ secrets.BACKTRACE_MINIDUMP_TOKEN }}
@@ -218,7 +277,7 @@ jobs:
218277

219278
buildWin64:
220279
runs-on: windows-2022
221-
needs: [preBuild, checks]
280+
needs: [preBuild, checks, staticAnalysis]
222281
env:
223282
BACKTRACE_SYMBOL_TOKEN: ${{ secrets.BACKTRACE_SYMBOL_TOKEN }}
224283
BACKTRACE_MINIDUMP_TOKEN: ${{ secrets.BACKTRACE_MINIDUMP_TOKEN }}
@@ -329,7 +388,7 @@ jobs:
329388

330389
buildMacOS:
331390
runs-on: macos-13
332-
needs: [preBuild, checks]
391+
needs: [preBuild, checks, staticAnalysis]
333392
env:
334393
BACKTRACE_SYMBOL_TOKEN: ${{ secrets.BACKTRACE_SYMBOL_TOKEN }}
335394
BACKTRACE_MINIDUMP_TOKEN: ${{ secrets.BACKTRACE_MINIDUMP_TOKEN }}
@@ -438,7 +497,7 @@ jobs:
438497

439498
postBuild:
440499
runs-on: ubuntu-22.04
441-
needs: [preBuild, checks, buildLinux, buildWin64, buildMacOS]
500+
needs: [preBuild, checks, staticAnalysis, buildLinux, buildWin64, buildMacOS]
442501

443502
steps:
444503
- name: Download xswiftbus-thin

scripts/run_static_analysis.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
import os
1515
import subprocess
1616

17+
# Currently we are not checking all directories as they might need to run compilation first for Qt UIC
18+
CHECK_DIRECTORIES = [
19+
"src/core",
20+
"src/misc",
21+
"src/input"
22+
]
23+
1724

1825
def _get_all_files(build_path: str) -> list[str]:
1926
src_path = utils.get_swift_source_path()
@@ -23,11 +30,21 @@ def _get_all_files(build_path: str) -> list[str]:
2330
commands = json.load(f)
2431
commands = set([os.path.relpath(entry["file"], utils.get_swift_source_path()) for entry in commands])
2532

26-
commands = [command for command in commands if not command.startswith("third_party") and not command.startswith(build_path)]
33+
commands = [command for command in commands if not command.startswith("third_party") and not command.startswith(build_path) and command.startswith("src/misc/network/role.cpp")]
2734
return commands
2835

36+
def _get_all_files_ci(build_path: str) -> list[str]:
37+
src_path = utils.get_swift_source_path()
38+
os.chdir(src_path)
2939

30-
def _get_changed_files(build_path: str) -> set[str]:
40+
with open(os.path.join(build_path, "compile_commands.json"), 'r') as f:
41+
commands = json.load(f)
42+
commands = set([os.path.relpath(entry["file"], utils.get_swift_source_path()) for entry in commands])
43+
44+
commands = [command for command in commands if command.startswith(tuple(CHECK_DIRECTORIES))]
45+
return commands
46+
47+
def _get_changed_files_ci(build_path: str) -> set[str]:
3148
src_path = utils.get_swift_source_path()
3249
os.chdir(src_path)
3350

@@ -42,14 +59,13 @@ def _get_changed_files(build_path: str) -> set[str]:
4259
commands = set([os.path.relpath(entry["file"], utils.get_swift_source_path()) for entry in commands])
4360

4461
files = set([line for line in result.stdout.splitlines() if
45-
(line.endswith('.cpp') or line.endswith('.h')) and not line.startswith(
46-
'tests') and not line.startswith('samples') and not line.startswith("third_party") and not line.startswith(build_path)])
62+
(line.endswith('.cpp') or line.endswith('.h')) and line.startswith(tuple(CHECK_DIRECTORIES))])
4763
return files & commands
4864

4965

5066
def run_clang_tidy(build_path: str, changed_source_files: set[str]):
5167
print(f"Run clang-tidy on files: {changed_source_files}")
52-
nproc = os.cpu_count()
68+
nproc = 10
5369
try:
5470
subprocess.run([
5571
'xargs',
@@ -60,6 +76,7 @@ def run_clang_tidy(build_path: str, changed_source_files: set[str]):
6076
'-p', build_path,
6177
'--warnings-as-errors', '*',
6278
'--quiet',
79+
#'--header-filter', '*',
6380
'--header-filter', f'{utils.get_swift_source_path()}/src/',
6481
], input='\n'.join(changed_source_files), text=True, check=True)
6582
except CalledProcessError:
@@ -89,6 +106,8 @@ def main():
89106
parser.add_argument("--build-path", required=True, help='Path to build folder')
90107
parser.add_argument("--all-files", action="store_true",
91108
help="Run check on all files in build database")
109+
parser.add_argument("--files-ci", action="store_true",
110+
help="Run check on specific files in build database which are also used in CI")
92111

93112
parser.add_argument("--clang-tidy", action="store_true",
94113
help="Run clang-tidy checks")
@@ -98,8 +117,11 @@ def main():
98117

99118
if args.all_files:
100119
source_files = _get_all_files(args.build_path)
120+
elif args.files_ci:
121+
source_files = _get_all_files_ci(args.build_path)
101122
else:
102-
source_files = _get_changed_files(args.build_path)
123+
source_files = _get_changed_files_ci(args.build_path)
124+
103125
if args.clang_tidy:
104126
run_clang_tidy(args.build_path, source_files)
105127
elif args.clazy:

0 commit comments

Comments
 (0)