-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect RUNNER_TEMP environment variable #194
Conversation
private static readonly _tmpDir = fs.mkdtempSync(path.join(Context._tryCreateDirctory(process.env.RUNNER_TEMP) || os.tmpdir(), 'docker-actions-toolkit-')); | ||
|
||
private static _tryCreateDirctory(directoryPath: string | undefined): string | undefined { | ||
if (directoryPath !== undefined) { | ||
const createdPath = fs.mkdirSync(directoryPath, {recursive: true}); | ||
if (createdPath !== directoryPath) { | ||
return undefined; | ||
} | ||
} | ||
return directoryPath; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think _tryCreateDirctory
is necessary, can just be:
private static readonly _tmpDir = fs.mkdtempSync(path.join(Context._tryCreateDirctory(process.env.RUNNER_TEMP) || os.tmpdir(), 'docker-actions-toolkit-')); | |
private static _tryCreateDirctory(directoryPath: string | undefined): string | undefined { | |
if (directoryPath !== undefined) { | |
const createdPath = fs.mkdirSync(directoryPath, {recursive: true}); | |
if (createdPath !== directoryPath) { | |
return undefined; | |
} | |
} | |
return directoryPath; | |
} | |
private static readonly _tmpDir = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP || os.tmpdir(), 'docker-actions-toolkit-')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A directory at path RUNNER_TEMP
may not exist, in which case fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, 'docker-actions-toolkit-'))
would throw an exception. Even though the provided string is a prefix, the directory in which the temporary directory would be created must already exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runner worker makes sure temp folder exists from what I see: https://github.com/actions/runner/blob/a4c57f27477077e57545af79851551ff7f5632bd/src/Runner.Worker/TempDirectoryManager.cs#L43-L44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh good point. This means the tests also need to point RUNNER_TEMP
to an existing directory tough.
Will update the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means the tests also need to point
RUNNER_TEMP
to an existing directory tough.
Will update the PR.
This is already set in jest config:
actions-toolkit/jest.config.ts
Line 26 in b525cd9
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'), |
On some (self hosted) runners
os.tmpdir()
cannot be used to communicate between applications. For example when using snap, every snap will get it's own, isolated,os.tmpdir()
.Github already provides us with an environment variable,
RUNNER_TEMP
, that should point to a directory that we can use as a temporary storage location that should be accessible by different applications on the same host. This change will use the directory pointed to byRUNNER_TEMP
as base for tmpDir when the variable is defined and the directory can be created or already existed