From 10b840936c03f6890dd9d74e0c83f718bb986306 Mon Sep 17 00:00:00 2001 From: Leon Wright Date: Fri, 15 Jul 2022 14:59:28 +0800 Subject: [PATCH 1/6] docs: Agent Tool Cache This updates and simplies the tool cache documentation to match the implementation in both and Relates #459 --- README.md | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7447c44b5..abb8199c9 100644 --- a/README.md +++ b/README.md @@ -422,27 +422,12 @@ If you are experiencing problems while configuring Python on your self-hosted ru ### Linux -- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable. -- By default runner downloads and install the tools to `/opt/hostedtoolcache`. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location. - - In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. - - A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service. -- Create a directory called `hostedtoolcache` inside `/opt`. -- The user starting the runner must have write permission to the `/opt/hostedtoolcache` directory. It is not possible to start the Linux runner with `sudo` and the `/opt` directory usually requires root privileges to write to. Check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory. -- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques: - - The user starting the runner is the owner, and the owner has write permission. - - The user starting the runner is in the owning group, and the owning group has write permission. - - All users have write permission. -- One quick way to grant access is to change the user and group of `/opt/hostedtoolcache` to be the same as the runners using `chown`. - - `sudo chown runner-user:runner-group /opt/hostedtoolcache/`. -- If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service). +- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source with the [--enable-shared](https://github.com/actions/python-versions/blob/main/builders/ubuntu-python-builder.psm1#L37) flag. +- By default runner downloads and install the tools to the `RUNNER_TOOL_CACHE` directory, however `AGENT_TOOLSDIRECTORY` can be set to override this location. ### Mac -- The same setup that applies to `Linux` also applies to `Mac`, just with a different tools cache directory. -- Create a directory called `/Users/runner/hostedtoolcache`. -- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`. -- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access. - +- The same setup that applies to `Linux` also applies to `Mac` # Using Python without `setup-python` From 9f1915a970ca4e1c3389f899fb4777a3636737d5 Mon Sep 17 00:00:00 2001 From: Leon Wright Date: Fri, 15 Jul 2022 12:57:51 +0800 Subject: [PATCH 2/6] fix: Self-Hosted Tool Cache This fixes the tool cache path for self-hosted runners, along with handling AGENT_TOOLSDIRECTORY for both hosted + self-hosted. Fixes actions#459 --- dist/setup/index.js | 10 +++------- src/setup-python.ts | 12 ++++-------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index f9cb76f10..84778361e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65340,13 +65340,9 @@ function resolveVersionInput() { function run() { var _a; return __awaiter(this, void 0, void 0, function* () { - // According to the README windows binaries do not require to be installed - // in the specific location, but Mac and Linux do - if (!utils_1.IS_WINDOWS && !((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim())) { - if (utils_1.IS_LINUX) - process.env['AGENT_TOOLSDIRECTORY'] = '/opt/hostedtoolcache'; - else - process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; + // When setting AGENT_TOOLSDIRECTORY, the actions/tool-cache function find + // is not able to find the files cached by actions/python-version. + if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) { process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; } core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE=${process.env['RUNNER_TOOL_CACHE']}`); diff --git a/src/setup-python.ts b/src/setup-python.ts index 11ea40569..0be5acfac 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -7,9 +7,7 @@ import fs from 'fs'; import {getCacheDistributor} from './cache-distributions/cache-factory'; import { isCacheFeatureAvailable, - logWarning, - IS_LINUX, - IS_WINDOWS + logWarning } from './utils'; function isPyPyVersion(versionSpec: string) { @@ -68,11 +66,9 @@ function resolveVersionInput(): string { } async function run() { - // According to the README windows binaries do not require to be installed - // in the specific location, but Mac and Linux do - if (!IS_WINDOWS && !process.env.AGENT_TOOLSDIRECTORY?.trim()) { - if (IS_LINUX) process.env['AGENT_TOOLSDIRECTORY'] = '/opt/hostedtoolcache'; - else process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; + // When setting AGENT_TOOLSDIRECTORY, the actions/tool-cache function find + // is not able to find the files cached by actions/python-version. + if (process.env.AGENT_TOOLSDIRECTORY?.trim()) { process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; } core.debug( From 467a9812256033cbdb1dcc41a0be7f40e60cf445 Mon Sep 17 00:00:00 2001 From: Leon Wright Date: Fri, 22 Jul 2022 16:02:07 +0800 Subject: [PATCH 3/6] feat: Add 'IS_MAC' util --- dist/setup/index.js | 3 ++- src/setup-python.ts | 3 ++- src/utils.ts | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 84778361e..739b53f02 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65430,6 +65430,7 @@ const semver = __importStar(__nccwpck_require__(1383)); const exec = __importStar(__nccwpck_require__(1514)); exports.IS_WINDOWS = process.platform === 'win32'; exports.IS_LINUX = process.platform === 'linux'; +exports.IS_MAC = process.platform === 'darwin'; exports.WINDOWS_ARCHS = ['x86', 'x64']; exports.WINDOWS_PLATFORMS = ['win32', 'win64']; const PYPY_VERSION_FILE = 'PYPY_VERSION'; @@ -65761,4 +65762,4 @@ module.exports = JSON.parse('["ac","com.ac","edu.ac","gov.ac","net.ac","mil.ac", /******/ module.exports = __webpack_exports__; /******/ /******/ })() -; \ No newline at end of file +; diff --git a/src/setup-python.ts b/src/setup-python.ts index 0be5acfac..bfecd0705 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -7,7 +7,8 @@ import fs from 'fs'; import {getCacheDistributor} from './cache-distributions/cache-factory'; import { isCacheFeatureAvailable, - logWarning + logWarning, + IS_MAC } from './utils'; function isPyPyVersion(versionSpec: string) { diff --git a/src/utils.ts b/src/utils.ts index 7d4fa02ec..b29c79d69 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,6 +7,7 @@ import * as exec from '@actions/exec'; export const IS_WINDOWS = process.platform === 'win32'; export const IS_LINUX = process.platform === 'linux'; +export const IS_MAC = process.platform === 'darwin'; export const WINDOWS_ARCHS = ['x86', 'x64']; export const WINDOWS_PLATFORMS = ['win32', 'win64']; const PYPY_VERSION_FILE = 'PYPY_VERSION'; From bc8ee4233085c23ff1e173523bb54ce0fd1a6f6b Mon Sep 17 00:00:00 2001 From: Leon Wright Date: Fri, 22 Jul 2022 16:03:42 +0800 Subject: [PATCH 4/6] fix: Mac Toolpath Shared libraries for the Mac python builds are not configured with the relocatable flag, thus must always be configured with the hosted path. Relates #459 --- dist/setup/index.js | 15 +++++++++------ src/setup-python.ts | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 739b53f02..713fc0bd9 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65338,14 +65338,17 @@ function resolveVersionInput() { return version; } function run() { - var _a; + var _a, _b; return __awaiter(this, void 0, void 0, function* () { - // When setting AGENT_TOOLSDIRECTORY, the actions/tool-cache function find - // is not able to find the files cached by actions/python-version. + if (utils_1.IS_MAC) { + process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; + } if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) { process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; } - core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE=${process.env['RUNNER_TOOL_CACHE']}`); + core.debug(`Python is expected to be installed into ${((_b = process.env.AGENT_TOOLSDIRECTORY) === null || _b === void 0 ? void 0 : _b.trim()) + ? process.env['AGENT_TOOLSDIRECTORY'] + : process.env['RUNNER_TOOL_CACHE']}`); try { const version = resolveVersionInput(); const checkLatest = core.getBooleanInput('check-latest'); @@ -65421,7 +65424,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.logWarning = exports.getLinuxOSReleaseInfo = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_LINUX = exports.IS_WINDOWS = void 0; +exports.logWarning = exports.getLinuxOSReleaseInfo = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const fs_1 = __importDefault(__nccwpck_require__(7147)); @@ -65762,4 +65765,4 @@ module.exports = JSON.parse('["ac","com.ac","edu.ac","gov.ac","net.ac","mil.ac", /******/ module.exports = __webpack_exports__; /******/ /******/ })() -; +; \ No newline at end of file diff --git a/src/setup-python.ts b/src/setup-python.ts index bfecd0705..4728d8f01 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -5,11 +5,7 @@ import * as path from 'path'; import * as os from 'os'; import fs from 'fs'; import {getCacheDistributor} from './cache-distributions/cache-factory'; -import { - isCacheFeatureAvailable, - logWarning, - IS_MAC -} from './utils'; +import {isCacheFeatureAvailable, logWarning, IS_MAC} from './utils'; function isPyPyVersion(versionSpec: string) { return versionSpec.startsWith('pypy'); @@ -67,13 +63,20 @@ function resolveVersionInput(): string { } async function run() { - // When setting AGENT_TOOLSDIRECTORY, the actions/tool-cache function find - // is not able to find the files cached by actions/python-version. + if (IS_MAC) { + process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; + } + if (process.env.AGENT_TOOLSDIRECTORY?.trim()) { process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; } + core.debug( - `Python is expected to be installed into RUNNER_TOOL_CACHE=${process.env['RUNNER_TOOL_CACHE']}` + `Python is expected to be installed into ${ + process.env.AGENT_TOOLSDIRECTORY?.trim() + ? process.env['AGENT_TOOLSDIRECTORY'] + : process.env['RUNNER_TOOL_CACHE'] + }` ); try { const version = resolveVersionInput(); From d5d67707d2d169a376918289347a1e2d5487c70b Mon Sep 17 00:00:00 2001 From: Leon Wright Date: Sat, 23 Jul 2022 10:19:13 +0800 Subject: [PATCH 5/6] docs: Mac Tool Path Ensure that the path requirements and reasoning is clear, to reduce confusion when using self-hosted, or attempting to set an 'AGENT_TOOLSDIRECTORY' environment variable. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index abb8199c9..84cd67b6b 100644 --- a/README.md +++ b/README.md @@ -427,7 +427,8 @@ If you are experiencing problems while configuring Python on your self-hosted ru ### Mac -- The same setup that applies to `Linux` also applies to `Mac` +- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source with the [--enable-shared](https://github.com/actions/python-versions/blob/main/builders/macos-python-builder.psm1#L44) flag, however lack the relocatable flag. +- Due to the fixed shared library path, only the hosted tool cache of `/Users/runner/hostedtoolcache` is supported, and the path must be writeable by the runner user. # Using Python without `setup-python` From 7e39d25e3f2e8f324816db4b0dbb6512eabfff92 Mon Sep 17 00:00:00 2001 From: Leon Wright Date: Tue, 26 Jul 2022 20:40:49 +0800 Subject: [PATCH 6/6] refactor: Debug message for Python installation path --- dist/setup/index.js | 6 ++---- src/setup-python.ts | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 713fc0bd9..f77bae2db 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65338,7 +65338,7 @@ function resolveVersionInput() { return version; } function run() { - var _a, _b; + var _a; return __awaiter(this, void 0, void 0, function* () { if (utils_1.IS_MAC) { process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; @@ -65346,9 +65346,7 @@ function run() { if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) { process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; } - core.debug(`Python is expected to be installed into ${((_b = process.env.AGENT_TOOLSDIRECTORY) === null || _b === void 0 ? void 0 : _b.trim()) - ? process.env['AGENT_TOOLSDIRECTORY'] - : process.env['RUNNER_TOOL_CACHE']}`); + core.debug(`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`); try { const version = resolveVersionInput(); const checkLatest = core.getBooleanInput('check-latest'); diff --git a/src/setup-python.ts b/src/setup-python.ts index 4728d8f01..d6e6bdaf0 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -72,11 +72,7 @@ async function run() { } core.debug( - `Python is expected to be installed into ${ - process.env.AGENT_TOOLSDIRECTORY?.trim() - ? process.env['AGENT_TOOLSDIRECTORY'] - : process.env['RUNNER_TOOL_CACHE'] - }` + `Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}` ); try { const version = resolveVersionInput();