From b82c468c3c08b3bf8489c2dd5657b3b09573d00b Mon Sep 17 00:00:00 2001 From: Gable Date: Wed, 23 Aug 2023 15:29:55 -0700 Subject: [PATCH 1/4] Add support for locally hosted GHES instances to reduce rate limiting --- action.yml | 8 +++++++- dist/setup/index.js | 15 ++++++++++----- docs/advanced-usage.md | 10 ++++++++++ src/install-python.ts | 11 ++++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 3a6531c88..f769231d5 100644 --- a/action.yml +++ b/action.yml @@ -15,9 +15,15 @@ inputs: check-latest: description: "Set this option if you want the action to check for the latest available version that satisfies the version spec." default: false + github_api_url: + description: "The url you wish to gather Python distributions from. Useful when running on GHES when you have a local instance of actions/python-versions and actions/setup-python installed" + default: "https://api.github.com" + github_raw_url: + description: "The endpoint you wish to use as the raw url" + default: "https://raw.githubusercontent.com" token: description: "The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting." - default: ${{ github.server_url == 'https://github.com' && github.token || '' }} + default: ${{ github.github_api_url == github_api_url && github.token || '' }} cache-dependency-path: description: "Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies." update-environment: diff --git a/dist/setup/index.js b/dist/setup/index.js index 37b247905..ee56573ce 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -10957,10 +10957,10 @@ function findAllVersions(toolName, arch) { return versions; } exports.findAllVersions = findAllVersions; -function getManifestFromRepo(owner, repo, auth, branch = 'master') { +function getManifestFromRepo(owner, repo, auth, branch = 'master', serverUrl = "https://api.github.com") { return __awaiter(this, void 0, void 0, function* () { let releases = []; - const treeUrl = `https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}`; + const treeUrl = `${serverUrl}/repos/${owner}/${repo}/git/trees/${branch}`; const http = new httpm.HttpClient('tool-cache'); const headers = {}; if (auth) { @@ -69685,7 +69685,12 @@ const AUTH = !TOKEN ? undefined : `token ${TOKEN}`; 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 API_URL = core.getInput('github_api_url'); +const GITHUB_API_URL = API_URL ? "https://api.github.com" : API_URL; +const RAW_URL = core.getInput('github_raw_url'); +const GITHUB_RAW_URL = RAW_URL ? "https://raw.githubusercontent.com" : RAW_URL; +exports.MANIFEST_URL = `${GITHUB_RAW_URL}/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`; + function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) { return __awaiter(this, void 0, void 0, function* () { if (!manifest) { @@ -69697,8 +69702,8 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) { } exports.findReleaseFromManifest = findReleaseFromManifest; function getManifest() { - 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); + core.debug(`Getting manifest from ${GITHUB_API_URL}/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`); + return tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH, GITHUB_API_URL); } exports.getManifest = getManifest; function installPython(workingDirectory) { diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 2dcb0efc7..5b6cfba03 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -591,6 +591,16 @@ Requests should now be authenticated. To verify that you are getting the higher ### 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. +### Other no access solutions +You can internally host a copy of [`actions/python-versions`](https://github.com/actions/python-versions) and manually point actions/setup-python to your internal endpoint with `github_api_url` and `github_raw_url` +```yml +- name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.8 + github_api_url: api.github.YOUR_COMPANY.com + github_raw_url: raw.github.YOUR_COMPANY.com +``` ## Allow pre-releases diff --git a/src/install-python.ts b/src/install-python.ts index 2af61291d..abe5ee5c0 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -10,7 +10,11 @@ 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`; +const API_URL = core.getInput('github_api_url'); +const GITHUB_API_URL = API_URL ? "https://api.github.com" : API_URL; +const RAW_URL = core.getInput('github_raw_url'); +const GITHUB_RAW_URL = RAW_URL ? "https://raw.githubusercontent.com" : RAW_URL; +export const MANIFEST_URL = `${GITHUB_RAW_URL}/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`; export async function findReleaseFromManifest( semanticVersionSpec: string, @@ -33,13 +37,14 @@ export async function findReleaseFromManifest( export function getManifest(): Promise { core.debug( - `Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}` + `Getting manifest from ${GITHUB_API_URL}/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}` ); return tc.getManifestFromRepo( MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, - MANIFEST_REPO_BRANCH + MANIFEST_REPO_BRANCH, + GITHUB_API_URL ); } From 3910d2645d0eb30c0169e12af4557dfa1d5809f8 Mon Sep 17 00:00:00 2001 From: Gable Brown <13039858+C1ARKGABLE@users.noreply.github.com> Date: Thu, 24 Aug 2023 00:04:56 -0700 Subject: [PATCH 2/4] Get from inputs --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f769231d5..277463704 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: default: "https://raw.githubusercontent.com" token: description: "The token used to authenticate when fetching Python distributions from https://github.com/actions/python-versions. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting." - default: ${{ github.github_api_url == github_api_url && github.token || '' }} + default: ${{ github.github_api_url == inputs.github_api_url && github.token || '' }} cache-dependency-path: description: "Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies." update-environment: From 17f8fc08c2aaa40227af0cc827455a71ec662400 Mon Sep 17 00:00:00 2001 From: Gable Date: Thu, 24 Aug 2023 00:12:54 -0700 Subject: [PATCH 3/4] npm run build --- dist/setup/index.js | 9 ++++----- src/install-python.ts | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ee56573ce..d25966017 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -10957,10 +10957,10 @@ function findAllVersions(toolName, arch) { return versions; } exports.findAllVersions = findAllVersions; -function getManifestFromRepo(owner, repo, auth, branch = 'master', serverUrl = "https://api.github.com") { +function getManifestFromRepo(owner, repo, auth, branch = 'master', serverUrl = 'https://api.github.com') { return __awaiter(this, void 0, void 0, function* () { let releases = []; - const treeUrl = `${serverUrl}/repos/${owner}/${repo}/git/trees/${branch}`; + const treeUrl = `${serverUrl}/${owner}/${repo}/git/trees/${branch}`; const http = new httpm.HttpClient('tool-cache'); const headers = {}; if (auth) { @@ -69686,11 +69686,10 @@ const MANIFEST_REPO_OWNER = 'actions'; const MANIFEST_REPO_NAME = 'python-versions'; const MANIFEST_REPO_BRANCH = 'main'; const API_URL = core.getInput('github_api_url'); -const GITHUB_API_URL = API_URL ? "https://api.github.com" : API_URL; +const GITHUB_API_URL = API_URL ? 'https://api.github.com' : API_URL; const RAW_URL = core.getInput('github_raw_url'); -const GITHUB_RAW_URL = RAW_URL ? "https://raw.githubusercontent.com" : RAW_URL; +const GITHUB_RAW_URL = RAW_URL ? 'https://raw.githubusercontent.com' : RAW_URL; exports.MANIFEST_URL = `${GITHUB_RAW_URL}/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`; - function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) { return __awaiter(this, void 0, void 0, function* () { if (!manifest) { diff --git a/src/install-python.ts b/src/install-python.ts index abe5ee5c0..155f60d2c 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -11,9 +11,9 @@ const MANIFEST_REPO_OWNER = 'actions'; const MANIFEST_REPO_NAME = 'python-versions'; const MANIFEST_REPO_BRANCH = 'main'; const API_URL = core.getInput('github_api_url'); -const GITHUB_API_URL = API_URL ? "https://api.github.com" : API_URL; +const GITHUB_API_URL = API_URL ? 'https://api.github.com' : API_URL; const RAW_URL = core.getInput('github_raw_url'); -const GITHUB_RAW_URL = RAW_URL ? "https://raw.githubusercontent.com" : RAW_URL; +const GITHUB_RAW_URL = RAW_URL ? 'https://raw.githubusercontent.com' : RAW_URL; export const MANIFEST_URL = `${GITHUB_RAW_URL}/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`; export async function findReleaseFromManifest( From 23e715c78e7c4870b8437b7105eeb5f54ad640f0 Mon Sep 17 00:00:00 2001 From: Gable Date: Thu, 24 Aug 2023 00:25:29 -0700 Subject: [PATCH 4/4] typo removed repos --- dist/setup/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index d25966017..b65db93f4 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -10960,7 +10960,7 @@ exports.findAllVersions = findAllVersions; function getManifestFromRepo(owner, repo, auth, branch = 'master', serverUrl = 'https://api.github.com') { return __awaiter(this, void 0, void 0, function* () { let releases = []; - const treeUrl = `${serverUrl}/${owner}/${repo}/git/trees/${branch}`; + const treeUrl = `${serverUrl}/repos/${owner}/${repo}/git/trees/${branch}`; const http = new httpm.HttpClient('tool-cache'); const headers = {}; if (auth) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy