2020-04-29 13:57:02 -04:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as tc from '@actions/tool-cache';
|
|
|
|
import * as exec from '@actions/exec';
|
|
|
|
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
2022-06-16 11:08:06 -04:00
|
|
|
import {IS_WINDOWS, IS_LINUX, isGhes} from './utils';
|
2020-04-29 13:57:02 -04:00
|
|
|
|
2020-05-20 09:35:09 -04:00
|
|
|
const TOKEN = core.getInput('token');
|
2022-06-16 11:08:06 -04:00
|
|
|
const AUTH = !TOKEN || isGhes() ? undefined : `token ${TOKEN}`;
|
2020-04-29 13:57:02 -04:00
|
|
|
const MANIFEST_REPO_OWNER = 'actions';
|
|
|
|
const MANIFEST_REPO_NAME = 'python-versions';
|
2020-07-15 05:26:28 -04:00
|
|
|
const MANIFEST_REPO_BRANCH = 'main';
|
|
|
|
export const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
|
2020-04-29 13:57:02 -04:00
|
|
|
|
|
|
|
export async function findReleaseFromManifest(
|
|
|
|
semanticVersionSpec: string,
|
|
|
|
architecture: string
|
|
|
|
): Promise<tc.IToolRelease | undefined> {
|
|
|
|
const manifest: tc.IToolRelease[] = await tc.getManifestFromRepo(
|
|
|
|
MANIFEST_REPO_OWNER,
|
|
|
|
MANIFEST_REPO_NAME,
|
2020-07-15 05:26:28 -04:00
|
|
|
AUTH,
|
|
|
|
MANIFEST_REPO_BRANCH
|
2020-04-29 13:57:02 -04:00
|
|
|
);
|
|
|
|
return await tc.findFromManifest(
|
|
|
|
semanticVersionSpec,
|
2020-07-17 05:58:03 -04:00
|
|
|
false,
|
2020-04-29 13:57:02 -04:00
|
|
|
manifest,
|
|
|
|
architecture
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function installPython(workingDirectory: string) {
|
|
|
|
const options: ExecOptions = {
|
|
|
|
cwd: workingDirectory,
|
2020-10-05 08:51:21 -04:00
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
...(IS_LINUX && {LD_LIBRARY_PATH: path.join(workingDirectory, 'lib')})
|
|
|
|
},
|
2020-04-29 13:57:02 -04:00
|
|
|
silent: true,
|
|
|
|
listeners: {
|
|
|
|
stdout: (data: Buffer) => {
|
2020-07-15 13:13:43 -04:00
|
|
|
core.info(data.toString().trim());
|
|
|
|
},
|
|
|
|
stderr: (data: Buffer) => {
|
|
|
|
core.error(data.toString().trim());
|
2020-04-29 13:57:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (IS_WINDOWS) {
|
|
|
|
await exec.exec('powershell', ['./setup.ps1'], options);
|
|
|
|
} else {
|
|
|
|
await exec.exec('bash', ['./setup.sh'], options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function installCpythonFromRelease(release: tc.IToolRelease) {
|
|
|
|
const downloadUrl = release.files[0].download_url;
|
|
|
|
|
|
|
|
core.info(`Download from "${downloadUrl}"`);
|
2020-05-20 09:35:09 -04:00
|
|
|
const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
|
2020-04-29 13:57:02 -04:00
|
|
|
core.info('Extract downloaded archive');
|
|
|
|
let pythonExtractedFolder;
|
|
|
|
if (IS_WINDOWS) {
|
2020-07-20 12:29:05 -04:00
|
|
|
pythonExtractedFolder = await tc.extractZip(pythonPath);
|
2020-04-29 13:57:02 -04:00
|
|
|
} else {
|
2020-07-20 12:29:05 -04:00
|
|
|
pythonExtractedFolder = await tc.extractTar(pythonPath);
|
2020-04-29 13:57:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
core.info('Execute installation script');
|
|
|
|
await installPython(pythonExtractedFolder);
|
|
|
|
}
|