4343 - language : javascript-typescript
4444 build-mode : none
4545 - language : python
46- build-mode : manual
46+ build-mode : none
4747 # CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
4848 # Use `c-cpp` to analyze code written in C, C++ or both
4949 # Use 'java-kotlin' to analyze code written in Java, Kotlin or both
8888 uses : github/codeql-action/init@v3
8989 with :
9090 languages : ${{ matrix.language }}
91- build-mode : ${{ matrix.build-mode }}
91+ build-mode : none
9292 source-root : ./.dagger-ci
9393
94+ # Run another Python script after CodeQL initialization to ensure it captures the code
95+ - name : Run Python code after CodeQL init
96+ if : ${{ matrix.language == 'python' }}
97+ run : |
98+ cd ./.dagger-ci
99+ # Create a simple script that exercises the code
100+ echo "import os" > run_code.py
101+ echo "for root, dirs, files in os.walk('.'):" >> run_code.py
102+ echo " for file in files:" >> run_code.py
103+ echo " if file.endswith('.py') and not file in ['run_code.py', 'import_all.py']:" >> run_code.py
104+ echo " print(f'Processing {os.path.join(root, file)}')" >> run_code.py
105+ # Run the script
106+ python run_code.py
107+
94108 # If you wish to specify custom queries, you can do so here or in a config file.
95109 # By default, queries listed here will override any specified in a config file.
96110 # Prefix the list here with "+" to use these queries and those in the config file.
@@ -99,16 +113,29 @@ jobs:
99113 # 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
100114 # queries: security-extended,security-and-quality
101115
102- # Build Python code for CodeQL analysis
103- - name : Build Python code for CodeQL analysis
116+ # Prepare Python code for CodeQL analysis
117+ - name : Prepare Python code for CodeQL analysis
104118 if : ${{ matrix.language == 'python' }}
105119 run : |
106120 # Change to the Python source directory
107121 cd ./.dagger-ci
108- # Run a simple Python command to make sure CodeQL sees the code
122+ # Run a simple Python command to make sure files are accessed
109123 python -m compileall .
110124 # List all Python files to ensure they're visible
111125 find . -name "*.py" | sort
126+ # Create a simple script that imports all modules to ensure they're loaded
127+ echo "import os, sys" > import_all.py
128+ echo "for root, dirs, files in os.walk('.'):" >> import_all.py
129+ echo " for file in files:" >> import_all.py
130+ echo " if file.endswith('.py') and not file == 'import_all.py':" >> import_all.py
131+ echo " module = os.path.join(root, file)[2:-3].replace('/', '.')" >> import_all.py
132+ echo " try:" >> import_all.py
133+ echo " print(f'Importing {module}')" >> import_all.py
134+ echo " __import__(module)" >> import_all.py
135+ echo " except Exception as e:" >> import_all.py
136+ echo " print(f'Failed to import {module}: {e}')" >> import_all.py
137+ # Run the import script
138+ python import_all.py
112139
113140 - name : Perform CodeQL Analysis
114141 uses : github/codeql-action/analyze@v3
0 commit comments