Skip to content

Commit 2239b88

Browse files
authored
repo sync
2 parents 65c2a51 + fd130da commit 2239b88

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

content/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,52 @@ If your workflow does not contain a matrix called `language`, then {% data varia
130130
with:
131131
languages: cpp, csharp, python
132132
```
133+
{% if currentVersion == "free-pro-team@latest" %}
134+
### Analyzing Python dependencies
135+
136+
For GitHub-hosted runners that use Linux only, the {% data variables.product.prodname_codeql_workflow %} will try to auto-install Python dependencies to give more results for the CodeQL analysis. You can control this behavior by specifying the `setup-python-dependencies` parameter for the action called by the "Initialize CodeQL" step. By default, this parameter is set to `true`:
137+
138+
- If the repository contains code written in Python, the "Initialize CodeQL" step installs the necessary dependencies on the GitHub-hosted runner. If the auto-install succeeds, the action also sets the environment variable `CODEQL_PYTHON` to the Python executable file that includes the dependencies.
139+
140+
- If the repository doesn't have any Python dependencies, or the dependencies are specified in an unexpected way, you'll get a warning and the action will continue with the remaining jobs. The action can run successfully even when there are problems interpreting dependencies, but the results may be incomplete.
141+
142+
Alternatively, you can install Python dependencies manually on any operating system. You will need to add `setup-python-dependencies` and set it to `false`, as well as set `CODEQL_PYTHON` to the Python executable that includes the dependencies, as shown in this workflow extract:
143+
144+
```yaml
145+
jobs:
146+
CodeQL-Build:
147+
148+
runs-on: ubuntu-latest
149+
150+
steps:
151+
- name: Checkout repository
152+
uses: actions/checkout@v2
153+
with:
154+
fetch-depth: 2
155+
- name: Set up Python
156+
uses: actions/setup-python@v2
157+
with:
158+
python-version: '3.x'
159+
- name: Install dependencies
160+
run: |
161+
python -m pip install --upgrade pip
162+
if [ -f requirements.txt ];
163+
then pip install -r requirements.txt;
164+
fi
165+
# Set the `CODEQL-PYTHON` environment variable to the Python executable
166+
# that includes the dependencies
167+
echo "::set-env name=CODEQL_PYTHON::$(which python)"
168+
- run: git checkout HEAD^2
169+
if: ${{ github.event_name == 'pull_request' }}
170+
- name: Initialize CodeQL
171+
uses: github/codeql-action/init@v1
172+
with:
173+
languages: python
174+
# Override the default behavior so that the action doesn't attempt
175+
# to auto-install Python dependencies
176+
setup-python-dependencies: false
177+
```
178+
{% endif %}
133179
134180
### Running additional queries
135181

content/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-the-codeql-workflow.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,12 @@ If you split your analysis into multiple workflows as described above, we still
114114
#### Run only during a `schedule` event
115115

116116
If your analysis is still too slow to be run during `push` or `pull_request` events, then you may want to only trigger analysis on the `schedule` event. For more information, see "[Events](/actions/learn-github-actions/introduction-to-github-actions#events)."
117+
118+
{% if currentVersion == "free-pro-team@latest" %}
119+
### Results differ between analysis platforms
120+
121+
If you are analyzing code written in Python, you may see different results depending on whether you run the {% data variables.product.prodname_codeql_workflow %} on Linux, macOS, or Windows.
122+
123+
On GitHub-hosted runners that use Linux, the {% data variables.product.prodname_codeql_workflow %} tries to install and analyze Python dependencies, which could lead to more results. To disable the auto-install, add `setup-python-dependencies: false` to the "Initialize CodeQL" step of the workflow. For more information about configuring the analysis of Python dependencies, see "[Analyzing Python dependencies](/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#analyzing-python-dependencies)."
124+
125+
{% endif %}

0 commit comments

Comments
 (0)