Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ inputs:
default: false
pip-version:
description: "Used to specify the version of pip to install with the Python. Supported format: major[.minor][.patch]."
python_download_base_url:
description: "Used to specify an alternative base URL to download the python releases instead of github.com. The Action will try to download the python releases from <python_download_base_url>/<release version>/<python version tar file>"
outputs:
python-version:
description: "The installed Python or PyPy version. Useful when given a version range as input."
Expand Down
5 changes: 4 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97762,6 +97762,7 @@ const MANIFEST_REPO_OWNER = 'actions';
const MANIFEST_REPO_NAME = 'python-versions';
const MANIFEST_REPO_BRANCH = 'main';
exports.MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
const PYTHON_DOWNLOAD_BASE_URL = core.getInput('python_download_base_url');
function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) {
return __awaiter(this, void 0, void 0, function* () {
if (!manifest) {
Expand Down Expand Up @@ -97852,7 +97853,9 @@ function installCpythonFromRelease(release) {
if (!release.files || release.files.length === 0) {
throw new Error('No files found in the release to download.');
}
const downloadUrl = release.files[0].download_url;
const downloadUrl = !PYTHON_DOWNLOAD_BASE_URL
? release.files[0].download_url
: release.files[0].download_url.replace('https://github.com/actions/python-versions/releases/download', PYTHON_DOWNLOAD_BASE_URL);
core.info(`Download from "${downloadUrl}"`);
let pythonPath = '';
try {
Expand Down
9 changes: 7 additions & 2 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,12 @@ One quick way to grant access is to change the user and group of `/Users/runner/

### No access to github.com

If the runner is not able to access github.com, any Python versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information.
If the runner is not able to access github.com, any Python versions requested during a workflow run must come from the runner's tool cache or defining and alternative mirror to download the distributions. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information.

### Using an alternative location to download Python distributions

If it is not an option for you to add the Python distributions in the runner's tool cache, another option is to have some mirror or files repository in your company network. You can define the mirror URL using the input `python_download_base_url`. The mirror must be setup in such a way that the Python distributions are available with the format `<python_download_base_url>/<release version>/<python version tar file>`. For example `<python_download_base_url>/3.10.18-15433209320/python-3.10.18-linux-22.04-x64.tar.gz`



## Allow pre-releases
Expand Down Expand Up @@ -671,4 +676,4 @@ The version of Pip should be specified in the format `major`, `major.minor`, or
```
> The `pip-version` input is supported only with standard Python versions. It is not available when using PyPy or GraalPy.

> Using a specific or outdated version of pip may result in compatibility or security issues and can cause job failures. For best practices and guidance, refer to the official [pip documentation](https://pip.pypa.io/en/stable/).
> Using a specific or outdated version of pip may result in compatibility or security issues and can cause job failures. For best practices and guidance, refer to the official [pip documentation](https://pip.pypa.io/en/stable/).
8 changes: 7 additions & 1 deletion src/install-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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`;
const PYTHON_DOWNLOAD_BASE_URL = core.getInput('python_download_base_url');

export async function findReleaseFromManifest(
semanticVersionSpec: string,
Expand Down Expand Up @@ -124,7 +125,12 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
if (!release.files || release.files.length === 0) {
throw new Error('No files found in the release to download.');
}
const downloadUrl = release.files[0].download_url;
const downloadUrl = !PYTHON_DOWNLOAD_BASE_URL
? release.files[0].download_url
: release.files[0].download_url.replace(
'https://github.com/actions/python-versions/releases/download',
PYTHON_DOWNLOAD_BASE_URL
);

core.info(`Download from "${downloadUrl}"`);
let pythonPath = '';
Expand Down