Permalink
Cannot retrieve contributors at this time
86 lines (76 sloc)
2.44 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
setup-python/src/install-python.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
import {IS_WINDOWS, IS_LINUX} from './utils'; | |
const TOKEN = core.getInput('token'); | |
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`; | |
const MANIFEST_REPO_OWNER = 'actions'; | |
const MANIFEST_REPO_NAME = 'python-versions'; | |
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`; | |
export async function findReleaseFromManifest( | |
semanticVersionSpec: string, | |
architecture: string, | |
manifest: tc.IToolRelease[] | null | |
): Promise<tc.IToolRelease | undefined> { | |
if (!manifest) { | |
manifest = await getManifest(); | |
} | |
const foundRelease = await tc.findFromManifest( | |
semanticVersionSpec, | |
false, | |
manifest, | |
architecture | |
); | |
return foundRelease; | |
} | |
export function getManifest(): Promise<tc.IToolRelease[]> { | |
core.debug( | |
`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}` | |
); | |
return tc.getManifestFromRepo( | |
MANIFEST_REPO_OWNER, | |
MANIFEST_REPO_NAME, | |
AUTH, | |
MANIFEST_REPO_BRANCH | |
); | |
} | |
async function installPython(workingDirectory: string) { | |
const options: ExecOptions = { | |
cwd: workingDirectory, | |
env: { | |
...process.env, | |
...(IS_LINUX && {LD_LIBRARY_PATH: path.join(workingDirectory, 'lib')}) | |
}, | |
silent: true, | |
listeners: { | |
stdout: (data: Buffer) => { | |
core.info(data.toString().trim()); | |
}, | |
stderr: (data: Buffer) => { | |
core.error(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); | |
core.info('Extract downloaded archive'); | |
let pythonExtractedFolder; | |
if (IS_WINDOWS) { | |
pythonExtractedFolder = await tc.extractZip(pythonPath); | |
} else { | |
pythonExtractedFolder = await tc.extractTar(pythonPath); | |
} | |
core.info('Execute installation script'); | |
await installPython(pythonExtractedFolder); | |
} |