mirror of
https://github.com/actions/setup-python.git
synced 2025-06-28 05:33:47 +00:00
Use GitHub releases to download python versions (#85)
This pull-request improves `setup-python` action to add ability to download specific version of Python on flight if it is not available by default. **Details:** `setup-python` action will download and install specific Python version from GitHub releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) in case the version is not found in the local cache. All versions of Python available for installation are published in [actions/python-versions](https://github.com/actions/python-versions) repository. All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/master/versions-manifest.json) file. **Installation time:** - Ubuntu / macOS: 10-20 seconds - Windows: ~ 1 minute (mostly related to fact that we use MSI installer for Python on Windows) Co-authored-by: MaksimZhukov <v-mazhuk@microsoft.com> Co-authored-by: Konrad Pabjan <konradpabjan@github.com> Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
This commit is contained in:
parent
985150d1f6
commit
e5af64b2df
11 changed files with 4109 additions and 3654 deletions
65
src/install-python.ts
Normal file
65
src/install-python.ts
Normal file
|
@ -0,0 +1,65 @@
|
|||
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';
|
||||
|
||||
const AUTH_TOKEN = core.getInput('token');
|
||||
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,
|
||||
AUTH_TOKEN
|
||||
);
|
||||
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}"`);
|
||||
const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH_TOKEN);
|
||||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue