Skip to content

Commit

Permalink
Test tox installation on pre-installed python
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Aug 23, 2024
1 parent 5c6377e commit b99d4a9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 25 additions & 3 deletions dist/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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");
Expand Down Expand Up @@ -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"));
Expand Down
28 changes: 25 additions & 3 deletions src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");

Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit b99d4a9

Please sign in to comment.