Skip to content

Commit fdcae64

Browse files
authored
Merge pull request #1932 from github/update-v2.22.1-18e6c398c
Merge main into releases/v2
2 parents 2cb752a + 8554648 commit fdcae64

15 files changed

+129
-11
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test that the workaround for python 3.12 on windows works
2+
3+
on:
4+
push:
5+
branches: [main, releases/v2]
6+
pull_request:
7+
# Run checks on reopened draft PRs to support triggering PR checks on draft PRs that were opened
8+
# by other workflows.
9+
types: [opened, synchronize, reopened, ready_for_review]
10+
schedule:
11+
# Weekly on Monday.
12+
- cron: '0 0 * * 1'
13+
workflow_dispatch:
14+
15+
jobs:
16+
test-setup-python-scripts:
17+
timeout-minutes: 45
18+
runs-on: windows-latest
19+
20+
steps:
21+
- uses: actions/setup-python@v4
22+
with:
23+
python-version: 3.12
24+
25+
- uses: actions/checkout@v4
26+
27+
- name: Prepare test
28+
uses: ./.github/actions/prepare-test
29+
with:
30+
version: default
31+
32+
- name: Initialize CodeQL
33+
uses: ./../action/init
34+
with:
35+
tools: latest
36+
languages: python
37+
38+
- name: Analyze
39+
uses: ./../action/analyze
40+
with:
41+
upload-database: false

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
See the [releases page](https://github.com/github/codeql-action/releases) for the relevant changes to the CodeQL CLI and language packs.
44

5+
## 2.22.1 - 09 Oct 2023
6+
7+
- Add a workaround for Python 3.12, which is not supported in CodeQL CLI version 2.14.6 or earlier. If you are running an analysis on Windows and using Python 3.12 or later, the CodeQL Action will switch to running Python 3.11. In this case, if Python 3.11 is not found, then the workflow will fail. [#1928](https://github.com/github/codeql-action/pull/1928)
8+
59
## 2.22.0 - 06 Oct 2023
610

711
- The CodeQL Action now requires CodeQL version 2.10.5 or later. For more information, see the corresponding changelog entry for CodeQL Action version 2.21.8. [#1907](https://github.com/github/codeql-action/pull/1907)

lib/analyze-action.js

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init.js

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeql",
3-
"version": "2.22.0",
3+
"version": "2.22.1",
44
"private": true,
55
"description": "CodeQL action",
66
"scripts": {

python-setup/check_python12.ps1

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
#! /usr/bin/pwsh
3+
4+
# If we are running greater than or equal to python 3.12, change py to run version 3.11
5+
Write-Host "Checking python version"
6+
if ((py -3 -c "import sys; print(0 if sys.version_info >= (3, 12) else 1)") -eq "0") {
7+
Write-Host "python 3.12+ detected, setting PY_PYTHON3=3.11"
8+
# First make sure we have python 3.11 installed
9+
py -3.11 -c "import imp"
10+
if ($LASTEXITCODE -eq 0) {
11+
Write-Host "python 3.11 detected, using this version instead of 3.12+."
12+
Write-Output "PY_PYTHON3=3.11" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
13+
} else {
14+
Write-Host "FAILURE: Python 3.12+ is not supported, and Python 3.11 could not be detected on the system. Please install Python 3.11."
15+
exit 1
16+
}
17+
} else {
18+
Write-Host "python 3.12+ not detected, not making any changes."
19+
}

src/analyze-action.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ async function run() {
239239
// precedence in the PATH, thus potentially circumventing our workaround that allows tracing to work.
240240
const goWrapperPath = process.env[EnvVar.GO_BINARY_LOCATION];
241241

242-
if (goWrapperPath !== undefined) {
242+
if (
243+
process.env[EnvVar.DID_AUTOBUILD_GOLANG] !== "true" &&
244+
goWrapperPath !== undefined
245+
) {
243246
const goBinaryPath = await safeWhich("go");
244247

245248
if (goWrapperPath !== goBinaryPath) {

src/init-action.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import { CodeQL } from "./codeql";
1717
import * as configUtils from "./config-utils";
1818
import { EnvVar } from "./environment";
1919
import { Feature, Features } from "./feature-flags";
20-
import { initCodeQL, initConfig, installPythonDeps, runInit } from "./init";
20+
import {
21+
checkInstallPython311,
22+
initCodeQL,
23+
initConfig,
24+
installPythonDeps,
25+
runInit,
26+
} from "./init";
2127
import { Language } from "./languages";
2228
import { getActionsLogger, Logger } from "./logging";
2329
import { parseRepositoryNwo } from "./repository";
@@ -277,6 +283,8 @@ async function run() {
277283
logger,
278284
);
279285

286+
await checkInstallPython311(config.languages, codeql);
287+
280288
if (
281289
config.languages.includes(Language.python) &&
282290
getRequiredInput("setup-python-dependencies") === "true"

src/init.ts

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
FeatureEnablement,
1414
useCodeScanningConfigInCli,
1515
} from "./feature-flags";
16+
import { Language } from "./languages";
1617
import { Logger } from "./logging";
1718
import { RepositoryNwo } from "./repository";
1819
import { ToolsSource } from "./setup-codeql";
@@ -181,6 +182,30 @@ function processError(e: any): Error {
181182
return e;
182183
}
183184

185+
/**
186+
* If we are running python 3.12+ on windows, we need to switch to python 3.11.
187+
* This check happens in a powershell script.
188+
*/
189+
export async function checkInstallPython311(
190+
languages: Language[],
191+
codeql: CodeQL,
192+
) {
193+
if (
194+
languages.includes(Language.python) &&
195+
process.platform === "win32" &&
196+
!(await codeql.getVersion()).features?.supportsPython312
197+
) {
198+
const script = path.resolve(
199+
__dirname,
200+
"../python-setup",
201+
"check_python12.ps1",
202+
);
203+
await new toolrunner.ToolRunner(await safeWhich.safeWhich("powershell"), [
204+
script,
205+
]).exec();
206+
}
207+
}
208+
184209
export async function installPythonDeps(codeql: CodeQL, logger: Logger) {
185210
logger.startGroup("Setup Python dependencies");
186211

0 commit comments

Comments
 (0)