2020-04-29 19:57:02 +02: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';
|
|
|
|
|
2020-05-20 15:35:09 +02:00
|
|
|
const TOKEN = core.getInput('token');
|
|
|
|
const AUTH = !TOKEN || isGhes() ? undefined : `token ${TOKEN}`;
|
2020-04-29 19:57:02 +02:00
|
|
|
const MANIFEST_REPO_OWNER = 'actions';
|
|
|
|
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';
|
|
|
|
|
|
|
|
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-05-20 15:35:09 +02:00
|
|
|
AUTH
|
2020-04-29 19:57:02 +02:00
|
|
|
);
|
|
|
|
return await tc.findFromManifest(
|
|
|
|
semanticVersionSpec,
|
|
|
|
true,
|
|
|
|
manifest,
|
|
|
|
architecture
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
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 15:35:09 +02:00
|
|
|
const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
|
2020-04-29 19:57:02 +02:00
|
|
|
const fileName = path.basename(pythonPath, '.zip');
|
|
|
|
core.info('Extract downloaded archive');
|
|
|
|
let pythonExtractedFolder;
|
|
|
|
if (IS_WINDOWS) {
|
|
|
|
pythonExtractedFolder = await tc.extractZip(pythonPath, `./${fileName}`);
|
|
|
|
} else {
|
|
|
|
pythonExtractedFolder = await tc.extractTar(pythonPath, `./${fileName}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
core.info('Execute installation script');
|
|
|
|
await installPython(pythonExtractedFolder);
|
|
|
|
}
|
2020-05-20 15:35:09 +02:00
|
|
|
|
|
|
|
function isGhes(): boolean {
|
|
|
|
const ghUrl = new URL(
|
|
|
|
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
|
|
);
|
|
|
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
|
|
|
}
|