actions / toolkit

The GitHub ToolKit for developing GitHub Actions.
https://github.com/features/actions
MIT License
4.92k stars 1.4k forks source link

Add support for getting a temporary directory #518

Open konradpabjan opened 4 years ago

konradpabjan commented 4 years ago

The runner has a temporary directory that gets cleaned up after each job. You can access it by doing process.env['RUNNER_TEMP'], this can be used for a lot of things such as creating temporary files for tests or during a job and users don't need to worry about this being cleaned up.

A lot of first party actions and third party actions could use this. A lot of first party actions are in-fact using the temp directory currently:

A method should be added to either @actions/io or @actions/core that will allow users to quickly get a temporary directory.

There should also be documentation added that mentions when this gets cleaned up, and under what circumstances it won't (runner crashes)

bbqsrc commented 3 years ago

This is reasonably important for sensitive things such as temporary secrets on self-hosted runners on macOS or Windows where containers are not possible.

koppor commented 3 years ago

For the googlers coming here: In the case of a Docker-based action, one CANNOT access that. See https://github.community/t/how-can-i-access-the-current-repo-context-and-files-from-a-docker-container-action/17711/8 for details.

minherz commented 1 year ago

What about using the runner's temporary directory runner.temp?

nelsonic commented 7 months ago

runner.temp doesn't appear to be writeable. is there a usage example that demonstrates creating & deleting files in the runner.temp directory?

gionn commented 1 month ago

runner.temp doesn't appear to be writeable. is there a usage example that demonstrates creating & deleting files in the runner.temp directory?

https://docs.github.com/en/actions/learn-github-actions/contexts#example-usage-of-the-runner-context