Skip to content

Commit 7fe412b

Browse files
Update CodeQL Action (#9079)
Part of #9058. ### Description This updates the CodeQL action to get this running again. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 02201b8 commit 7fe412b

4 files changed

Lines changed: 82 additions & 36 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,67 +9,110 @@
99
# the `language` matrix defined below to confirm you have the correct set of
1010
# supported CodeQL languages.
1111
#
12-
name: "CodeQL"
12+
name: "CodeQL Advanced"
1313

1414
on:
1515
push:
1616
branches: [ dev, main ]
1717
pull_request:
18-
# The branches below must be a subset of the branches above
1918
branches: [ dev ]
2019
schedule:
21-
- cron: '18 1 * * 0'
20+
- cron: '0 2 * * 1' # 2AM Monday
21+
22+
env:
23+
PYTHON_VER: '3.11'
24+
PYTORCH_VER: '2.8.0'
25+
BUILD_MONAI: 1
26+
PIP_EXTRA_INDEX_URL: "https://download.pytorch.org/whl/cpu" # forces CPU PyTorch installation, should be faster
2227

2328
jobs:
2429
analyze:
25-
name: Analyze
30+
name: Analyze (${{ matrix.language }})
31+
# Runner size impacts CodeQL analysis time. To learn more, please see:
32+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
33+
# - https://gh.io/supported-runners-and-hardware-resources
34+
# - https://gh.io/using-larger-runners (GitHub.com only)
35+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
2636
runs-on: ubuntu-latest
2737
permissions:
38+
# required for all workflows
39+
security-events: write
40+
41+
# required to fetch internal or private CodeQL packs
42+
packages: read
43+
44+
# only required for workflows in private repositories
2845
actions: read
2946
contents: read
30-
security-events: write
3147

3248
strategy:
3349
fail-fast: false
3450
matrix:
35-
language: [ 'cpp', 'python' ]
36-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37-
# Learn more about CodeQL language support at https://git.io/codeql-language-support
38-
51+
include:
52+
- language: actions
53+
build-mode: none
54+
- language: c-cpp
55+
build-mode: none # TODO: get Cpp building working, autobuild doesn't work and manual fails for inexplicable reasons.
56+
- language: python
57+
build-mode: none
58+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
59+
# Use `c-cpp` to analyze code written in C, C++ or both
60+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
61+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
62+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
63+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
64+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
65+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
3966
steps:
4067
- name: Checkout repository
4168
uses: actions/checkout@v7
4269

70+
# Add any setup steps before running the `github/codeql-action/init` action.
71+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
72+
# or others). This is typically only required for manual builds.
73+
# - name: Setup runtime (example)
74+
# uses: actions/setup-example@v1
75+
4376
# Initializes the CodeQL tools for scanning.
4477
- name: Initialize CodeQL
4578
uses: github/codeql-action/init@v4
4679
with:
4780
languages: ${{ matrix.language }}
81+
build-mode: ${{ matrix.build-mode }}
4882
# If you wish to specify custom queries, you can do so here or in a config file.
4983
# By default, queries listed here will override any specified in a config file.
5084
# Prefix the list here with "+" to use these queries and those in the config file.
51-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
5285

53-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54-
# If this step fails, then you should remove it and run the build manually (see below)
55-
# - name: Autobuild
56-
# uses: github/codeql-action/autobuild@v2
86+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
87+
# queries: security-extended,security-and-quality
5788

89+
# If the analyze step fails for one of the languages you are analyzing with
90+
# "We were unable to automatically build your code", modify the matrix above
91+
# to set the build mode to "manual" for that language. Then modify this step
92+
# to build your code.
5893
# ℹ️ Command-line programs to run using the OS shell.
59-
# 📚 https://git.io/JvXDl
60-
61-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62-
# and modify them (or add more) to build your code if your project
63-
# uses a compiled language
94+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
95+
- name: Set up Python ${{ env.PYTHON_VER }}
96+
if: matrix.language == 'c-cpp' && matrix.build-mode == 'manual'
97+
uses: actions/setup-python@v6
98+
with:
99+
python-version: ${{ env.PYTHON_VER }}
100+
cache: 'pip'
64101

65-
- name: Build
102+
- name: Run manual build steps
103+
if: matrix.language == 'c-cpp' && matrix.build-mode == 'manual'
104+
shell: bash
66105
run: |
67106
rm -rf /opt/hostedtoolcache/{node,go,Ruby,Java*}
68107
ls -al /opt/hostedtoolcache
69-
rm -rf /usr/share/dotnet/
108+
sudo rm -rf /usr/share/dotnet/
70109
python -m pip install -U pip wheel wheel-stub
71-
python -m pip install .[all,testing]
72-
BUILD_MONAI=1 ./runtests.sh --build
110+
python -m pip install torch==${PYTORCH_VER} torchvision
111+
python -m pip install --user --upgrade pip wheel
112+
python monai/config/print_dependencies.py build-system | xargs pip install --no-build-isolation
113+
python -m pip install --no-build-isolation .
73114
74115
- name: Perform CodeQL Analysis
75116
uses: github/codeql-action/analyze@v4
117+
with:
118+
category: "/language:${{matrix.language}}"

monai/networks/nets/dints.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,23 @@
3636
__all__ = ["DiNTS", "TopologyConstruction", "TopologyInstance", "TopologySearch"]
3737

3838

39-
@torch.jit.interface
40-
class CellInterface(torch.nn.Module):
41-
"""interface for torchscriptable Cell"""
39+
# TODO: added temporarily for PyTorch 2.14 warnings, remove when factoring out deprecated Torchscript components
40+
with warnings.catch_warnings():
41+
warnings.simplefilter("ignore")
4242

43-
def forward(self, x: torch.Tensor, weight: torch.Tensor | None) -> torch.Tensor: # type: ignore
44-
pass
43+
@torch.jit.interface
44+
class CellInterface(torch.nn.Module):
45+
"""interface for torchscriptable Cell"""
4546

47+
def forward(self, x: torch.Tensor, weight: torch.Tensor | None) -> torch.Tensor: # type: ignore
48+
pass
4649

47-
@torch.jit.interface
48-
class StemInterface(torch.nn.Module):
49-
"""interface for torchscriptable Stem"""
50+
@torch.jit.interface
51+
class StemInterface(torch.nn.Module):
52+
"""interface for torchscriptable Stem"""
5053

51-
def forward(self, x: torch.Tensor) -> torch.Tensor: # type: ignore
52-
pass
54+
def forward(self, x: torch.Tensor) -> torch.Tensor: # type: ignore
55+
pass
5356

5457

5558
class StemTS(StemInterface):

monai/utils/profiling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def torch_profiler_full(func):
5757

5858
@wraps(func)
5959
def wrapper(*args, **kwargs):
60-
with torch.autograd.profiler.profile(use_cuda=True) as prof:
60+
with torch.autograd.profiler.profile() as prof:
6161
result = func(*args, **kwargs)
6262

6363
print(prof, flush=True)
@@ -76,7 +76,7 @@ def torch_profiler_time_cpu_gpu(func):
7676

7777
@wraps(func)
7878
def wrapper(*args, **kwargs):
79-
with torch.autograd.profiler.profile(use_cuda=True) as prof:
79+
with torch.autograd.profiler.profile() as prof:
8080
result = func(*args, **kwargs)
8181

8282
cpu_time = prof.self_cpu_time_total

monai/visualize/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def get_label_rgb(cmap: str, label: NdarrayOrTensor) -> NdarrayOrTensor:
211211
_cmap = plt.colormaps.get_cmap(cmap)
212212
label_np, *_ = convert_data_type(label, np.ndarray)
213213
label_rgb_np = _cmap(label_np[0])
214-
label_rgb_np = np.moveaxis(label_rgb_np, -1, 0)[:3]
214+
label_rgb_np = np.moveaxis(label_rgb_np, -1, 0)[:3] # pyrefly: ignore [bad-specialization]
215215
label_rgb, *_ = convert_to_dst_type(label_rgb_np, label)
216216
return label_rgb
217217

0 commit comments

Comments
 (0)