Skip to content

Commit a93d541

Browse files
Merge pull request #466 from techman83/fix/tool_path
Fix Tool Path handling for self-hosted runners
2 parents 5df6377 + 7e39d25 commit a93d541

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

README.md

+4-18
Original file line numberDiff line numberDiff line change
@@ -422,27 +422,13 @@ If you are experiencing problems while configuring Python on your self-hosted ru
422422

423423
### Linux
424424

425-
- 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.
426-
- By default runner downloads and install the tools to `/opt/hostedtoolcache`. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location.
427-
- In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`.
428-
- 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.
429-
- Create a directory called `hostedtoolcache` inside `/opt`.
430-
- 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.
431-
- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques:
432-
- The user starting the runner is the owner, and the owner has write permission.
433-
- The user starting the runner is in the owning group, and the owning group has write permission.
434-
- All users have write permission.
435-
- 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`.
436-
- `sudo chown runner-user:runner-group /opt/hostedtoolcache/`.
437-
- 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).
425+
- 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.
426+
- By default runner downloads and install the tools to the `RUNNER_TOOL_CACHE` directory, however `AGENT_TOOLSDIRECTORY` can be set to override this location.
438427

439428
### Mac
440429

441-
- The same setup that applies to `Linux` also applies to `Mac`, just with a different tools cache directory.
442-
- Create a directory called `/Users/runner/hostedtoolcache`.
443-
- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`.
444-
- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access.
445-
430+
- 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.
431+
- 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.
446432

447433
# Using Python without `setup-python`
448434

dist/setup/index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -65340,16 +65340,13 @@ function resolveVersionInput() {
6534065340
function run() {
6534165341
var _a;
6534265342
return __awaiter(this, void 0, void 0, function* () {
65343-
// According to the README windows binaries do not require to be installed
65344-
// in the specific location, but Mac and Linux do
65345-
if (!utils_1.IS_WINDOWS && !((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim())) {
65346-
if (utils_1.IS_LINUX)
65347-
process.env['AGENT_TOOLSDIRECTORY'] = '/opt/hostedtoolcache';
65348-
else
65349-
process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
65343+
if (utils_1.IS_MAC) {
65344+
process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
65345+
}
65346+
if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) {
6535065347
process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY'];
6535165348
}
65352-
core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE=${process.env['RUNNER_TOOL_CACHE']}`);
65349+
core.debug(`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`);
6535365350
try {
6535465351
const version = resolveVersionInput();
6535565352
const checkLatest = core.getBooleanInput('check-latest');
@@ -65425,7 +65422,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6542565422
return (mod && mod.__esModule) ? mod : { "default": mod };
6542665423
};
6542765424
Object.defineProperty(exports, "__esModule", ({ value: true }));
65428-
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;
65425+
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;
6542965426
const cache = __importStar(__nccwpck_require__(7799));
6543065427
const core = __importStar(__nccwpck_require__(2186));
6543165428
const fs_1 = __importDefault(__nccwpck_require__(7147));
@@ -65434,6 +65431,7 @@ const semver = __importStar(__nccwpck_require__(1383));
6543465431
const exec = __importStar(__nccwpck_require__(1514));
6543565432
exports.IS_WINDOWS = process.platform === 'win32';
6543665433
exports.IS_LINUX = process.platform === 'linux';
65434+
exports.IS_MAC = process.platform === 'darwin';
6543765435
exports.WINDOWS_ARCHS = ['x86', 'x64'];
6543865436
exports.WINDOWS_PLATFORMS = ['win32', 'win64'];
6543965437
const PYPY_VERSION_FILE = 'PYPY_VERSION';

src/setup-python.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import * as path from 'path';
55
import * as os from 'os';
66
import fs from 'fs';
77
import {getCacheDistributor} from './cache-distributions/cache-factory';
8-
import {
9-
isCacheFeatureAvailable,
10-
logWarning,
11-
IS_LINUX,
12-
IS_WINDOWS
13-
} from './utils';
8+
import {isCacheFeatureAvailable, logWarning, IS_MAC} from './utils';
149

1510
function isPyPyVersion(versionSpec: string) {
1611
return versionSpec.startsWith('pypy');
@@ -68,15 +63,16 @@ function resolveVersionInput(): string {
6863
}
6964

7065
async function run() {
71-
// According to the README windows binaries do not require to be installed
72-
// in the specific location, but Mac and Linux do
73-
if (!IS_WINDOWS && !process.env.AGENT_TOOLSDIRECTORY?.trim()) {
74-
if (IS_LINUX) process.env['AGENT_TOOLSDIRECTORY'] = '/opt/hostedtoolcache';
75-
else process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
66+
if (IS_MAC) {
67+
process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
68+
}
69+
70+
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
7671
process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY'];
7772
}
73+
7874
core.debug(
79-
`Python is expected to be installed into RUNNER_TOOL_CACHE=${process.env['RUNNER_TOOL_CACHE']}`
75+
`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`
8076
);
8177
try {
8278
const version = resolveVersionInput();

src/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as exec from '@actions/exec';
77

88
export const IS_WINDOWS = process.platform === 'win32';
99
export const IS_LINUX = process.platform === 'linux';
10+
export const IS_MAC = process.platform === 'darwin';
1011
export const WINDOWS_ARCHS = ['x86', 'x64'];
1112
export const WINDOWS_PLATFORMS = ['win32', 'win64'];
1213
const PYPY_VERSION_FILE = 'PYPY_VERSION';

0 commit comments

Comments
 (0)