Skip to content

Commit 59913e8

Browse files
committed
Merge remote-tracking branch 'origin/robertbrignull/runner_workflow' into robertbrignull/runner_workflow
2 parents 269b8b9 + b6e9407 commit 59913e8

14 files changed

Lines changed: 212 additions & 45 deletions

.github/workflows/codeql.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v2
17-
with:
18-
# Must fetch at least the immediate parents so that if this is
19-
# a pull request then we can checkout the head of the pull request.
20-
fetch-depth: 2
21-
22-
# If this run was triggered by a pull request event then checkout
23-
# the head of the pull request instead of the merge commit.
24-
- run: git checkout HEAD^2
25-
if: ${{ github.event_name == 'pull_request' }}
26-
2717
- uses: ./init
2818
with:
2919
languages: javascript
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test Python Package Installation
1+
name: Test Python Package Installation on Linux
22

33
on:
44
push:
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Test Python Package Installation on Windows
2+
3+
4+
on:
5+
push:
6+
branches: [main, v1]
7+
pull_request:
8+
9+
jobs:
10+
11+
test-setup-python-scripts:
12+
runs-on: windows-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- test_dir: python-setup/tests/pipenv/requests-2
18+
python_version: 2
19+
- test_dir: python-setup/tests/pipenv/requests-3
20+
python_version: 3
21+
22+
- test_dir: python-setup/tests/poetry/requests-2
23+
python_version: 2
24+
- test_dir: python-setup/tests/poetry/requests-3
25+
python_version: 3
26+
27+
- test_dir: python-setup/tests/requirements/requests-2
28+
python_version: 2
29+
- test_dir: python-setup/tests/requirements/requests-3
30+
python_version: 3
31+
32+
- test_dir: python-setup/tests/setup_py/requests-2
33+
python_version: 2
34+
- test_dir: python-setup/tests/setup_py/requests-3
35+
python_version: 3
36+
37+
steps:
38+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
39+
- uses: actions/checkout@v2
40+
41+
- name: Initialize CodeQL
42+
uses: github/codeql-action/init@v1
43+
with:
44+
languages: python
45+
46+
- name: Test Auto Package Installation
47+
run: |
48+
$cmd = $Env:GITHUB_WORKSPACE + "\\python-setup\\install_tools.ps1"
49+
powershell -File $cmd
50+
51+
cd $Env:GITHUB_WORKSPACE\\${{ matrix.test_dir }}
52+
py -3 $Env:GITHUB_WORKSPACE\\python-setup\\auto_install_packages.py C:\\hostedtoolcache\\windows\\CodeQL\\0.0.0-20200826\\x64\\codeql
53+
- name: Setup for extractor
54+
run: |
55+
echo $Env:CODEQL_PYTHON
56+
57+
py -3 $Env:GITHUB_WORKSPACE\\python-setup\\tests\\from_python_exe.py $Env:CODEQL_PYTHON
58+
- name: Verify packages installed
59+
run: |
60+
$cmd = $Env:GITHUB_WORKSPACE + "\\python-setup\\tests\\check_requests_123.ps1"
61+
powershell -File $cmd ${{ matrix.python_version }}

.github/workflows/release-runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
inputs:
66
bundle-tag:
77
description: 'Tag of the bundle release (e.g., "codeql-bundle-20200826")'
8-
required: true
8+
required: false
99

1010
jobs:
1111
release-runner:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ on:
3131
# │ │ │ │ │
3232
# │ │ │ │ │
3333
# * * * * *
34-
- cron: '0 0 * * 0'
34+
- cron: '30 1 * * 0'
3535

3636
jobs:
3737
CodeQL-Build:

lib/defaults.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"bundleVersion": "codeql-bundle-20200826"
2+
"bundleVersion": "codeql-bundle-20201008"
33
}

lib/init.js

Lines changed: 25 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python-setup/auto_install_packages.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ def _check_output(command):
2323

2424

2525
def install_packages_with_poetry():
26+
command = [sys.executable, '-m', 'poetry']
27+
if sys.platform.startswith('win32'):
28+
# In windows the default path were the deps are installed gets wiped out between steps,
29+
# so we have to set it up to a folder that will be kept
30+
os.environ['POETRY_VIRTUALENVS_PATH'] = os.path.join(os.environ['RUNNER_WORKSPACE'], 'virtualenvs')
2631
try:
27-
_check_call(['poetry', 'install', '--no-root'])
32+
_check_call(command + ['install', '--no-root'])
2833
except subprocess.CalledProcessError:
2934
sys.exit('package installation with poetry failed, see error above')
3035

@@ -33,44 +38,69 @@ def install_packages_with_poetry():
3338
# virtualenv for the package, which was the case for using poetry for Python 2 when
3439
# default system interpreter was Python 3 :/
3540

36-
poetry_out = _check_output(['poetry', 'run', 'which', 'python'])
41+
poetry_out = _check_output(command + ['run', 'which', 'python'])
3742
python_executable_path = poetry_out.decode('utf-8').splitlines()[-1]
3843

44+
if sys.platform.startswith('win32'):
45+
# Poetry produces a path that starts by /d instead of D:\ and Windows doesn't like that way of specifying the drive letter.
46+
# We completely remove it because it is not needed as everything is in the same drive (We are installing the dependencies in the RUNNER_WORKSPACE)
47+
python_executable_path = python_executable_path[2:]
3948
return python_executable_path
4049

4150

4251
def install_packages_with_pipenv():
52+
command = [sys.executable, '-m', 'pipenv']
53+
if sys.platform.startswith('win32'):
54+
# In windows the default path were the deps are installed gets wiped out between steps,
55+
# so we have to set it up to a folder that will be kept
56+
os.environ['WORKON_HOME'] = os.path.join(os.environ['RUNNER_WORKSPACE'], 'virtualenvs')
4357
try:
44-
_check_call(['pipenv', 'install', '--keep-outdated', '--ignore-pipfile'])
58+
_check_call(command + ['install', '--keep-outdated', '--ignore-pipfile'])
4559
except subprocess.CalledProcessError:
4660
sys.exit('package installation with pipenv failed, see error above')
4761

48-
pipenv_out = _check_output(['pipenv', 'run', 'which', 'python'])
62+
pipenv_out = _check_output(command + ['run', 'which', 'python'])
4963
python_executable_path = pipenv_out.decode('utf-8').splitlines()[-1]
5064

65+
if sys.platform.startswith('win32'):
66+
# Pipenv produces a path that starts by /d instead of D:\ and Windows doesn't like that way of specifying the drive letter.
67+
# We completely remove it because it is not needed as everything is in the same drive (We are installing the dependencies in the RUNNER_WORKSPACE)
68+
python_executable_path = python_executable_path[2:]
5169
return python_executable_path
5270

5371

5472
def _create_venv(version: int):
5573
# create temporary directory ... that just lives "forever"
56-
venv_path = mkdtemp(prefix='codeql-action-python-autoinstall-')
74+
venv_path = os.path.join(os.environ['RUNNER_WORKSPACE'], 'codeql-action-python-autoinstall')
75+
print ("Creating venv in " + venv_path, flush = True)
5776

5877
# virtualenv is a bit nicer for setting up virtual environment, since it will provide
5978
# up-to-date versions of pip/setuptools/wheel which basic `python3 -m venv venv` won't
6079

61-
if version == 2:
62-
_check_call(['python2', '-m', 'virtualenv', venv_path])
63-
elif version == 3:
64-
_check_call(['python3', '-m', 'virtualenv', venv_path])
80+
if sys.platform.startswith('win32'):
81+
if version == 2:
82+
_check_call(['py', '-2', '-m', 'virtualenv', venv_path])
83+
elif version == 3:
84+
_check_call(['py', '-3', '-m', 'virtualenv', venv_path])
85+
else:
86+
if version == 2:
87+
_check_call(['python2', '-m', 'virtualenv', venv_path])
88+
elif version == 3:
89+
_check_call(['python3', '-m', 'virtualenv', venv_path])
6590

6691
return venv_path
6792

6893

6994
def install_requirements_txt_packages(version: int):
7095
venv_path = _create_venv(version)
96+
7197
venv_pip = os.path.join(venv_path, 'bin', 'pip')
7298
venv_python = os.path.join(venv_path, 'bin', 'python')
7399

100+
if sys.platform.startswith('win32'):
101+
venv_pip = os.path.join(venv_path, 'Scripts', 'pip')
102+
venv_python = os.path.join(venv_path, 'Scripts', 'python')
103+
74104
try:
75105
_check_call([venv_pip, 'install', '-r', 'requirements.txt'])
76106
except subprocess.CalledProcessError:
@@ -81,9 +111,14 @@ def install_requirements_txt_packages(version: int):
81111

82112
def install_with_setup_py(version: int):
83113
venv_path = _create_venv(version)
114+
84115
venv_pip = os.path.join(venv_path, 'bin', 'pip')
85116
venv_python = os.path.join(venv_path, 'bin', 'python')
86117

118+
if sys.platform.startswith('win32'):
119+
venv_pip = os.path.join(venv_path, 'Scripts', 'pip')
120+
venv_python = os.path.join(venv_path, 'Scripts', 'python')
121+
87122
try:
88123
# We have to choose between `python setup.py develop` and `pip install -e .`.
89124
# Modern projects use `pip install -e .` and I wasn't able to see any downsides
@@ -135,12 +170,11 @@ def install_packages(codeql_base_dir) -> Optional[str]:
135170

136171
codeql_base_dir = sys.argv[1]
137172

138-
# The binaries for packages installed with `pip install --user` are not available on
139-
# PATH by default, so we need to manually add them.
140-
os.environ['PATH'] = os.path.expanduser('~/.local/bin') + os.pathsep + os.environ['PATH']
141-
142173
python_executable_path = install_packages(codeql_base_dir)
143174

144175
if python_executable_path is not None:
176+
# see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
177+
env_file = open(os.environ["GITHUB_ENV"], mode="at")
178+
145179
print("Setting CODEQL_PYTHON={}".format(python_executable_path))
146-
print("::set-env name=CODEQL_PYTHON::{}".format(python_executable_path))
180+
print("CODEQL_PYTHON={}".format(python_executable_path), file=env_file)

python-setup/install_tools.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/pwsh
2+
3+
py -2 -m pip install --user --upgrade pip setuptools wheel
4+
py -3 -m pip install --user --upgrade pip setuptools wheel
5+
6+
# virtualenv is a bit nicer for setting up virtual environment, since it will provide up-to-date versions of
7+
# pip/setuptools/wheel which basic `python3 -m venv venv` won't
8+
py -2 -m pip install --user virtualenv
9+
py -3 -m pip install --user virtualenv
10+
11+
# poetry 1.0.10 has error (https://github.com/python-poetry/poetry/issues/2711)
12+
py -3 -m pip install --user poetry!=1.0.10
13+
py -3 -m pip install --user pipenv

0 commit comments

Comments
 (0)