From b99d4a96b75001cf167246575ffa6afbd5608d02 Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Fri, 23 Aug 2024 13:12:03 -0500 Subject: [PATCH] Test tox installation on pre-installed python --- .github/workflows/e2e.yaml | 28 ++++++++++++++++++++++++++++ action.yaml | 4 ++++ dist/bootstrap/index.js | 28 +++++++++++++++++++++++++--- src/bootstrap/index.ts | 28 +++++++++++++++++++++++++--- 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index a1694d9..aa497c2 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -18,6 +18,34 @@ jobs: reporter: github-pr-check fail-on-error: true + + test-python-pre-installed: + name: Test pre-installed-python environment + runs-on: ubuntu-latest + strategy: + matrix: + python: + - '3.8' + - '3.10' + - '3.12' + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - name: Check out code + uses: actions/checkout@v4 + - uses: ./ + with: + provider: lxd + channel: latest/stable + juju-channel: 3/stable + - name: Run Tests for != 3.x + run: | + tox -e tests -- -k "not k8s" + exit $? + + test-lxd: name: Test lxd environment runs-on: ${{ matrix.os }} diff --git a/action.yaml b/action.yaml index 9bc9818..feaa251 100644 --- a/action.yaml +++ b/action.yaml @@ -67,6 +67,10 @@ inputs: description: "microk8s addons to enable" required: false default: "storage dns rbac" + tox-version: + description: "Version of tox to install" + required: false + default: "" container-registry-url: description: "Container registry to use" runs: diff --git a/dist/bootstrap/index.js b/dist/bootstrap/index.js index c619c54..17f0d49 100644 --- a/dist/bootstrap/index.js +++ b/dist/bootstrap/index.js @@ -5671,6 +5671,29 @@ function fixed_revision_args(app, channel, arch) { } return `--channel=${channel}`; } +function install_tox(tox_version = "") { + return __awaiter(this, void 0, void 0, function* () { + // Install tox if it's not already installed + const hasTox = yield exec.exec("which tox", [], ignoreFail); + if (hasTox == 0) { + core.info("tox is already installed"); + exec.exec("tox --version"); + return; + } + const hasPip = yield exec.exec("which pip", [], ignoreFail); + const version = tox_version ? `==${tox_version}` : ""; + if (hasPip == 0) { + core.info(`pip is available, install tox${version}`); + yield exec.exec(`pip install tox${version}`); + } + else { + core.info("Neither tox nor pip are available, install python3-pip via apt, then tox"); + yield apt_get("update -yqq"); + yield apt_get("install -yqq python3-pip"); + yield exec.exec(`sudo --preserve-env=http_proxy,https_proxy,no_proxy pip3 install tox${version}`); + } + }); +} function run() { return __awaiter(this, void 0, void 0, function* () { const HOME = process.env["HOME"]; @@ -5687,6 +5710,7 @@ function run() { const juju_channel = core.getInput("juju-channel"); const juju_bundle_channel = core.getInput("juju-bundle-channel"); const juju_crashdump_channel = core.getInput("juju-crashdump-channel"); + const tox_version = core.getInput("tox-version"); const lxd_channel = (provider === "lxd" && channel) ? channel : core.getInput("lxd-channel"); const microk8s_group = get_microk8s_group(); let bootstrap_constraints = core.getInput("bootstrap-constraints"); @@ -5717,9 +5741,7 @@ function run() { yield exec.exec('bash', ['-c', 'sudo usermod -a -G lxd $USER']); core.endGroup(); core.startGroup("Install tox"); - yield apt_get("update -yqq"); - yield apt_get("install -yqq python3-pip"); - yield exec.exec("sudo --preserve-env=http_proxy,https_proxy,no_proxy pip3 install tox"); + yield install_tox(tox_version); core.endGroup(); core.startGroup("Install Juju"); yield snap_install("juju", juju_channel, juju_channel.includes("2.9")); diff --git a/src/bootstrap/index.ts b/src/bootstrap/index.ts index 7efa510..92e49e0 100644 --- a/src/bootstrap/index.ts +++ b/src/bootstrap/index.ts @@ -192,6 +192,29 @@ function fixed_revision_args(app:string, channel:string, arch:string): string{ return `--channel=${channel}` } + +async function install_tox(tox_version: string = "") { + // Install tox if it's not already installed + const hasTox = await exec.exec("which tox", [], ignoreFail); + if (hasTox == 0) { + core.info("tox is already installed"); + exec.exec("tox --version"); + return; + } + const hasPip = await exec.exec("which pip", [], ignoreFail); + const version = tox_version ? `==${tox_version}` : ""; + if (hasPip == 0) { + core.info(`pip is available, install tox${version}`); + await exec.exec(`pip install tox${version}`); + } else { + core.info("Neither tox nor pip are available, install python3-pip via apt, then tox"); + await apt_get("update -yqq"); + await apt_get("install -yqq python3-pip"); + await exec.exec(`sudo --preserve-env=http_proxy,https_proxy,no_proxy pip3 install tox${version}`); + } +} + + async function run() { const HOME = process.env["HOME"] const GITHUB_SHA = process.env["GITHUB_SHA"].slice(0, 5) @@ -208,6 +231,7 @@ async function run() { const juju_channel = core.getInput("juju-channel"); const juju_bundle_channel = core.getInput("juju-bundle-channel"); const juju_crashdump_channel = core.getInput("juju-crashdump-channel") + const tox_version = core.getInput("tox-version"); const lxd_channel = (provider === "lxd" && channel) ? channel : core.getInput("lxd-channel"); @@ -240,9 +264,7 @@ async function run() { await exec.exec('bash', ['-c', 'sudo usermod -a -G lxd $USER']); core.endGroup(); core.startGroup("Install tox"); - await apt_get("update -yqq"); - await apt_get("install -yqq python3-pip"); - await exec.exec("sudo --preserve-env=http_proxy,https_proxy,no_proxy pip3 install tox"); + await install_tox(tox_version); core.endGroup(); core.startGroup("Install Juju"); await snap_install("juju", juju_channel, juju_channel.includes("2.9"));