diff --git a/action.yml b/action.yml index abcd4262..b5dcf476 100644 --- a/action.yml +++ b/action.yml @@ -8,11 +8,8 @@ inputs: default: '3.x' architecture: description: 'The target architecture (x86, x64) of the Python interpreter.' - default: 'x64' token: - description: > - Personal access token (PAT) used to fetch the manifest file from master of repository - [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) + description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user. default: ${{ github.token }} outputs: python-version: diff --git a/dist/index.js b/dist/index.js index 476683a7..94ee28a3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2500,12 +2500,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(__webpack_require__(696)); const finder = __importStar(__webpack_require__(507)); const path = __importStar(__webpack_require__(622)); +const os = __importStar(__webpack_require__(87)); function run() { return __awaiter(this, void 0, void 0, function* () { try { let version = core.getInput('python-version'); if (version) { - const arch = core.getInput('architecture', { required: true }); + const arch = core.getInput('architecture') || os.arch(); const installed = yield finder.findPythonVersion(version, arch); core.info(`Successfully setup ${installed.impl} (${installed.version})`); } @@ -2600,7 +2601,7 @@ const MANIFEST_REPO_OWNER = 'actions'; const MANIFEST_REPO_NAME = 'python-versions'; exports.MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/master/versions-manifest.json`; const IS_WINDOWS = process.platform === 'win32'; -const IS_LINUX = process.platform === 'linux'; +const IS_MACOS = process.platform === 'darwin'; function findReleaseFromManifest(semanticVersionSpec, architecture) { return __awaiter(this, void 0, void 0, function* () { const manifest = yield tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH_TOKEN); @@ -2608,6 +2609,28 @@ function findReleaseFromManifest(semanticVersionSpec, architecture) { }); } exports.findReleaseFromManifest = findReleaseFromManifest; +function _installPython(workingDirectory) { + return __awaiter(this, void 0, void 0, function* () { + const options = { + cwd: workingDirectory, + silent: true, + listeners: { + stdout: (data) => { + core.debug(data.toString().trim()); + } + } + }; + if (IS_WINDOWS) { + yield exec.exec('powershell', ['./setup.ps1'], options); + } + else if (IS_MACOS) { + yield exec.exec('bash', ['./setup.sh'], options); + } + else { + yield exec.exec('sudo', ['-n', 'bash', './setup.sh'], options); + } + }); +} function installCpythonFromRelease(release) { return __awaiter(this, void 0, void 0, function* () { const downloadUrl = release.files[0].download_url; @@ -2622,25 +2645,8 @@ function installCpythonFromRelease(release) { else { pythonExtractedFolder = yield tc.extractTar(pythonPath, `./${fileName}`); } - const options = { - cwd: pythonExtractedFolder, - silent: true, - listeners: { - stdout: (data) => { - core.debug(data.toString().trim()); - } - } - }; core.info('Execute installation script'); - if (IS_WINDOWS) { - yield exec.exec('powershell', ['./setup.ps1'], options); - } - else if (IS_LINUX) { - yield exec.exec('sudo', ['bash', './setup.sh'], options); - } - else { - yield exec.exec('bash', ['./setup.sh'], options); - } + yield _installPython(pythonExtractedFolder); }); } exports.installCpythonFromRelease = installCpythonFromRelease; @@ -3648,23 +3654,6 @@ const os = __importStar(__webpack_require__(87)); const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(305)); const installer = __importStar(__webpack_require__(400)); -let cacheDirectory = process.env['RUNNER_TOOLSDIRECTORY'] || ''; -if (!cacheDirectory) { - let baseLocation; - if (process.platform === 'win32') { - // On windows use the USERPROFILE env variable - baseLocation = process.env['USERPROFILE'] || 'C:\\'; - } - else { - if (process.platform === 'darwin') { - baseLocation = '/Users'; - } - else { - baseLocation = '/home'; - } - } - cacheDirectory = path.join(baseLocation, 'actions', 'cache'); -} const core = __importStar(__webpack_require__(696)); const tc = __importStar(__webpack_require__(475)); const IS_WINDOWS = process.platform === 'win32'; diff --git a/src/find-python.ts b/src/find-python.ts index eb89f146..cd9663f9 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -5,23 +5,6 @@ import * as semver from 'semver'; import * as installer from './install-python'; -let cacheDirectory = process.env['RUNNER_TOOLSDIRECTORY'] || ''; - -if (!cacheDirectory) { - let baseLocation; - if (process.platform === 'win32') { - // On windows use the USERPROFILE env variable - baseLocation = process.env['USERPROFILE'] || 'C:\\'; - } else { - if (process.platform === 'darwin') { - baseLocation = '/Users'; - } else { - baseLocation = '/home'; - } - } - cacheDirectory = path.join(baseLocation, 'actions', 'cache'); -} - import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; diff --git a/src/install-python.ts b/src/install-python.ts index 1456420e..73dec9f0 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -10,7 +10,7 @@ const MANIFEST_REPO_NAME = 'python-versions'; export const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/master/versions-manifest.json`; const IS_WINDOWS = process.platform === 'win32'; -const IS_LINUX = process.platform === 'linux'; +const IS_MACOS = process.platform === 'darwin'; export async function findReleaseFromManifest( semanticVersionSpec: string, @@ -29,6 +29,26 @@ export async function findReleaseFromManifest( ); } +async function _installPython(workingDirectory: string) { + const options: ExecOptions = { + cwd: workingDirectory, + silent: true, + listeners: { + stdout: (data: Buffer) => { + core.debug(data.toString().trim()); + } + } + }; + + if (IS_WINDOWS) { + await exec.exec('powershell', ['./setup.ps1'], options); + } else if (IS_MACOS) { + await exec.exec('bash', ['./setup.sh'], options); + } else { + await exec.exec('sudo', ['-n', 'bash', './setup.sh'], options); + } +} + export async function installCpythonFromRelease(release: tc.IToolRelease) { const downloadUrl = release.files[0].download_url; @@ -43,22 +63,6 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) { pythonExtractedFolder = await tc.extractTar(pythonPath, `./${fileName}`); } - const options: ExecOptions = { - cwd: pythonExtractedFolder, - silent: true, - listeners: { - stdout: (data: Buffer) => { - core.debug(data.toString().trim()); - } - } - }; - core.info('Execute installation script'); - if (IS_WINDOWS) { - await exec.exec('powershell', ['./setup.ps1'], options); - } else if (IS_LINUX) { - await exec.exec('sudo', ['bash', './setup.sh'], options); - } else { - await exec.exec('bash', ['./setup.sh'], options); - } + await _installPython(pythonExtractedFolder); } diff --git a/src/setup-python.ts b/src/setup-python.ts index b22d83c2..c97f314c 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -1,12 +1,13 @@ import * as core from '@actions/core'; import * as finder from './find-python'; import * as path from 'path'; +import * as os from 'os'; async function run() { try { let version = core.getInput('python-version'); if (version) { - const arch: string = core.getInput('architecture', {required: true}); + const arch: string = core.getInput('architecture') || os.arch(); const installed = await finder.findPythonVersion(version, arch); core.info(`Successfully setup ${installed.impl} (${installed.version})`); }