Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add workflow for testing python setup
  • Loading branch information
David Verdeguer committed Sep 29, 2020
1 parent 1831270 commit 67ddca1
Showing 33 changed files with 495 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/python-deps.yml
@@ -0,0 +1,81 @@
name: Test Python Package Installation

on:
push:
branches: [main, v1]
pull_request:

jobs:

test-setup-python-scripts:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- test_dir: python-setup/tests/pipenv/requests-2
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
- test_dir: python-setup/tests/pipenv/requests-3
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3

- test_dir: python-setup/tests/poetry/requests-2
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
- test_dir: python-setup/tests/poetry/requests-3
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3

- test_dir: python-setup/tests/requirements/requests-2
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
- test_dir: python-setup/tests/requirements/requests-3
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3

- test_dir: python-setup/tests/setup_py/requests-2
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 2
- test_dir: python-setup/tests/setup_py/requests-3
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3

# This one shouldn't fail, but also won't install packages
- test_dir: python-setup/tests/requirements/non-standard-location
test_script: test -z $LGTM_INDEX_IMPORT_PATH

# All of these should fail
- test_dir: python-setup/tests/pipenv/python-version-not-available
test_script: /bin/false
- test_dir: python-setup/tests/poetry/python-version-not-available
test_script: /bin/false
- test_dir: python-setup/tests/requirements/invalid-package
test_script: /bin/false
- test_dir: python-setup/tests/requirements/invalid-version
test_script: /bin/false
- test_dir: python-setup/tests/setup_py/invalid-version
test_script: /bin/false
- test_dir: python-setup/tests/setup_py/invalid-file
test_script: /bin/false
- test_dir: python-setup/tests/setup_py/extra-require-not-installed
test_script: $GITHUB_WORKSPACE/python-setup/tests/check_requests_123.sh 3
- test_dir: python-setup/tests/setup_py/wrong-python-version
test_script: /bin/false

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: python

- name: Test Auto Package Installation
run: |
set -x
$GITHUB_WORKSPACE/python-setup/install_tools.sh
echo -e '\n\n\n\n\n' && sleep 0.5
cd $GITHUB_WORKSPACE/${{ matrix.test_dir }}
$GITHUB_WORKSPACE/python-setup/auto_install_packages.py /opt/hostedtoolcache/CodeQL/0.0.0-20200826/x64/codeql/
- name: Setup for extractor
run: |
echo $CODEQL_PYTHON
# only run if $CODEQL_PYTHON is set
test ! -z $CODEQL_PYTHON && $GITHUB_WORKSPACE/python-setup/tests/from_python_exe.py $CODEQL_PYTHON || /bin/true
- name: Verify packages installed
run: |
${{ matrix.test_script }}
32 changes: 32 additions & 0 deletions python-setup/tests/check_requests_123.sh
@@ -0,0 +1,32 @@
#!/bin/bash

set -e

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

EXPECTED_VERSION=$1

FOUND_VERSION="$LGTM_PYTHON_SETUP_VERSION"
FOUND_PYTHONPATH="$LGTM_INDEX_IMPORT_PATH"

echo "FOUND_VERSION=${FOUND_VERSION} FOUND_PYTHONPATH=${FOUND_PYTHONPATH} "

if [[ $FOUND_VERSION != $EXPECTED_VERSION ]]; then
echo "Script told us to use Python ${FOUND_VERSION}, but expected ${EXPECTED_VERSION}"
exit 1
else
echo "Script told us to use Python ${FOUND_VERSION}, which was expected"
fi

PYTHON_EXE="python${EXPECTED_VERSION}"

INSTALLED_REQUESTS_VERSION=$(PYTHONPATH="${FOUND_PYTHONPATH}" "${PYTHON_EXE}" -c 'import requests; print(requests.__version__)')

EXPECTED_REQUESTS="1.2.3"

if [[ "$INSTALLED_REQUESTS_VERSION" != "$EXPECTED_REQUESTS" ]]; then
echo "Using ${FOUND_PYTHONPATH} as PYTHONPATH, we found version $INSTALLED_REQUESTS_VERSION of requests, but expected $EXPECTED_REQUESTS"
exit 1
else
echo "Using ${FOUND_PYTHONPATH} as PYTHONPATH, we found version $INSTALLED_REQUESTS_VERSION of requests, which was expected"
fi
31 changes: 31 additions & 0 deletions python-setup/tests/from_python_exe.py
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

import sys
import subprocess
from typing import Tuple

def get_details(path_to_python_exe: str) -> Tuple[str, str]:
import_path = subprocess.check_output(
[
path_to_python_exe,
"-c",
"import os; import pip; print(os.path.dirname(os.path.dirname(pip.__file__)))",
],
stdin=subprocess.DEVNULL,
)
version = subprocess.check_output(
[path_to_python_exe, "-c", "import sys; print(sys.version_info[0])"],
stdin=subprocess.DEVNULL,
)

return version.decode("utf-8").strip(), import_path.decode("utf-8").strip()


if __name__ == "__main__":
version, import_path = get_details(sys.argv[1])

print("Setting LGTM_PYTHON_SETUP_VERSION={}".format(version))
print("::set-env name=LGTM_PYTHON_SETUP_VERSION::{}".format(version))

print("Setting LGTM_INDEX_IMPORT_PATH={}".format(import_path))
print("::set-env name=LGTM_INDEX_IMPORT_PATH::{}".format(import_path))
12 changes: 12 additions & 0 deletions python-setup/tests/pipenv/python-3.8/Pipfile
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
requests = "*"

[requires]
python_version = "3.8"
28 changes: 28 additions & 0 deletions python-setup/tests/pipenv/python-3.8/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions python-setup/tests/pipenv/python-version-not-available/Pipfile
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
requests = "*"

[requires]
python_version = "3.100"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions python-setup/tests/pipenv/requests-2/Pipfile
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
requests = "*"

[requires]
python_version = "2.7"
28 changes: 28 additions & 0 deletions python-setup/tests/pipenv/requests-2/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions python-setup/tests/pipenv/requests-3/Pipfile
@@ -0,0 +1,11 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
requests = "*"

[requires]
28 changes: 28 additions & 0 deletions python-setup/tests/pipenv/requests-3/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions python-setup/tests/poetry/python-3.8/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions python-setup/tests/poetry/python-3.8/pyproject.toml
@@ -0,0 +1,15 @@
[tool.poetry]
name = "autoinstall-test"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.8"
requests = "*"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
16 changes: 16 additions & 0 deletions python-setup/tests/poetry/python-version-not-available/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,15 @@
[tool.poetry]
name = "autoinstall-test"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.100"
requests = "*"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
16 changes: 16 additions & 0 deletions python-setup/tests/poetry/requests-2/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 67ddca1

Please sign in to comment.