Call python3 when running in a container

This commit is contained in:
Peter Evans 2020-02-13 17:36:57 +09:00
parent 9d58699da5
commit 4beea725d3
2 changed files with 43 additions and 21 deletions

23
dist/index.js vendored
View file

@ -1002,7 +1002,6 @@ module.exports = require("os");
const { inspect } = __webpack_require__(669); const { inspect } = __webpack_require__(669);
const isDocker = __webpack_require__(160); const isDocker = __webpack_require__(160);
const fs = __webpack_require__(747);
const core = __webpack_require__(470); const core = __webpack_require__(470);
const exec = __webpack_require__(986); const exec = __webpack_require__(986);
const setupPython = __webpack_require__(139); const setupPython = __webpack_require__(139);
@ -1013,15 +1012,27 @@ async function run() {
const src = __webpack_require__.ab + "src"; const src = __webpack_require__.ab + "src";
core.debug(`src: ${src}`); core.debug(`src: ${src}`);
// Determine how to access python and pip
const { pip, python } = (function() {
if (isDocker()) { if (isDocker()) {
core.info('Running inside a Docker container'); core.info("Running inside a Docker container");
// Python 3 assumed to be installed and on the PATH
return {
pip: "pip3",
python: "python3"
};
} else { } else {
// Setup Python from the tool cache // Setup Python from the tool cache
setupPython("3.8.x", "x64"); setupPython("3.x", "x64");
return {
pip: "pip",
python: "python"
};
} }
})();
// Install requirements // Install requirements
await exec.exec("pip", [ await exec.exec(pip, [
"install", "install",
"--requirement", "--requirement",
`${src}/requirements.txt`, `${src}/requirements.txt`,
@ -1047,7 +1058,7 @@ async function run() {
projectColumn: core.getInput("project-column"), projectColumn: core.getInput("project-column"),
branch: core.getInput("branch"), branch: core.getInput("branch"),
base: core.getInput("base"), base: core.getInput("base"),
branchSuffix: core.getInput("branch-suffix"), branchSuffix: core.getInput("branch-suffix")
}; };
core.debug(`Inputs: ${inspect(inputs)}`); core.debug(`Inputs: ${inspect(inputs)}`);
@ -1071,7 +1082,7 @@ async function run() {
if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix; if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix;
// Execute python script // Execute python script
await exec.exec("python", [`${src}/create_pull_request.py`]); await exec.exec(python, [`${src}/create_pull_request.py`]);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }

View file

@ -1,6 +1,5 @@
const { inspect } = require("util"); const { inspect } = require("util");
const isDocker = require('is-docker'); const isDocker = require("is-docker");
const fs = require("fs");
const core = require("@actions/core"); const core = require("@actions/core");
const exec = require("@actions/exec"); const exec = require("@actions/exec");
const setupPython = require("./src/setup-python"); const setupPython = require("./src/setup-python");
@ -11,15 +10,27 @@ async function run() {
const src = __dirname + "/src"; const src = __dirname + "/src";
core.debug(`src: ${src}`); core.debug(`src: ${src}`);
// Determine how to access python and pip
const { pip, python } = (function() {
if (isDocker()) { if (isDocker()) {
core.info('Running inside a Docker container'); core.info("Running inside a Docker container");
// Python 3 assumed to be installed and on the PATH
return {
pip: "pip3",
python: "python3"
};
} else { } else {
// Setup Python from the tool cache // Setup Python from the tool cache
setupPython("3.8.x", "x64"); setupPython("3.x", "x64");
return {
pip: "pip",
python: "python"
};
} }
})();
// Install requirements // Install requirements
await exec.exec("pip", [ await exec.exec(pip, [
"install", "install",
"--requirement", "--requirement",
`${src}/requirements.txt`, `${src}/requirements.txt`,
@ -45,7 +56,7 @@ async function run() {
projectColumn: core.getInput("project-column"), projectColumn: core.getInput("project-column"),
branch: core.getInput("branch"), branch: core.getInput("branch"),
base: core.getInput("base"), base: core.getInput("base"),
branchSuffix: core.getInput("branch-suffix"), branchSuffix: core.getInput("branch-suffix")
}; };
core.debug(`Inputs: ${inspect(inputs)}`); core.debug(`Inputs: ${inspect(inputs)}`);
@ -69,7 +80,7 @@ async function run() {
if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix; if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix;
// Execute python script // Execute python script
await exec.exec("python", [`${src}/create_pull_request.py`]); await exec.exec(python, [`${src}/create_pull_request.py`]);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }