1
0
Fork 0
mirror of https://code.forgejo.org/actions/setup-python synced 2025-06-09 21:02:19 +02: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:
MaksimZhukov 2020-04-29 20:57:02 +03:00 committed by GitHub
parent 985150d1f6
commit e5af64b2df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 4109 additions and 3654 deletions

View file

@ -3,22 +3,7 @@ import * as path from 'path';
import * as semver from 'semver';
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 installer from './install-python';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
@ -92,29 +77,33 @@ async function useCpythonVersion(
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
const installDir: string | null = tc.find(
let installDir: string | null = tc.find(
'Python',
semanticVersionSpec,
architecture
);
if (!installDir) {
// Fail and list available versions
const x86Versions = tc
.findAllVersions('Python', 'x86')
.map(s => `${s} (x86)`)
.join(os.EOL);
core.info(
`Version ${semanticVersionSpec} was not found in the local cache`
);
const foundRelease = await installer.findReleaseFromManifest(
semanticVersionSpec,
architecture
);
const x64Versions = tc
.findAllVersions('Python', 'x64')
.map(s => `${s} (x64)`)
.join(os.EOL);
if (foundRelease && foundRelease.files && foundRelease.files.length > 0) {
core.info(`Version ${semanticVersionSpec} is available for downloading`);
await installer.installCpythonFromRelease(foundRelease);
installDir = tc.find('Python', semanticVersionSpec, architecture);
}
}
if (!installDir) {
throw new Error(
[
`Version ${version} with arch ${architecture} not found`,
'Available versions:',
x86Versions,
x64Versions
`The list of all available versions can be found here: ${installer.MANIFEST_URL}`
].join(os.EOL)
);
}