diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-03-14 03:42:14 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-03-14 03:42:14 +0300 |
commit | 203b15ee12f9b6f18de4f6575873d698be313557 (patch) | |
tree | cd8b9209042139c325aa142864e45ad20f52597c /clean.js | |
parent | add .gitattributes (diff) | |
download | cleanup-path-203b15ee12f9b6f18de4f6575873d698be313557.tar.gz cleanup-path-203b15ee12f9b6f18de4f6575873d698be313557.zip |
make it into a JavaScript action
This is a huge step back IMO, but I needed to be able to restore the
original PATH back as a "post" step. Currently, composite actions don't
support post-actions, but JavaScript ones do. I needed this due to a
bug: actions/cache wouldn't find Git's tar on windows-2016 (the one in
System32 would get used on windows-2019) if the PATH was cleaned up.
Diffstat (limited to '')
-rw-r--r-- | clean.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/clean.js b/clean.js new file mode 100644 index 0000000..22dfdff --- /dev/null +++ b/clean.js @@ -0,0 +1,39 @@ +const os = require('os'); +const path = require('path'); +const process = require('process'); + +const core = require('@actions/core'); + +try { + if (os.platform != 'win32') { + core.warning('Not going to clean up PATH variable on ${os.platform}'); + process.exit(); + } + + let custom_paths = core.getInput('dirs'); + custom_paths = custom_paths.split(path.delimiter).filter(function(p) { + return p.length != 0; + }); + + // This seems to be the default on new installations. + // Also, MSYS2 does this. + const default_paths = [ + 'C:\\Windows\\system32', + 'C:\\Windows', + 'C:\\Windows\\System32\\Wbem', + 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\', + ]; + + const add_default = core.getInput('default') == '1'; + + let new_path = custom_paths; + if (add_default) { + new_path = new_path.concat(default_paths); + } + new_path = new_path.join(path.delimiter); + + core.exportVariable('ORIG_PATH', process.env.PATH); + core.exportVariable('PATH', new_path); +} catch (error) { + core.setFailed(error.message); +} |