Allow repeated invocation (#37)

* Workaround for repeated invocations

As noted in the comment, repeated invocations of this action might have
caused environment variables to overflow. This cute hack avoid this,
allowing to reconfigure environment.

* Note caveats in README

While this approach mostly works, I still have reservations so let's
leave some cautionary notes.

* Test repeated reconfiguration on CI

Well, let's build our "Hello, world!" four times, for four different
architectures, because why not.
This commit is contained in:
Alexei Lozovsky
2021-05-08 17:54:58 +09:00
committed by GitHub
parent ff72ae9ce3
commit 08b850b4d0
3 changed files with 97 additions and 4 deletions
+24 -2
View File
@@ -55,6 +55,21 @@ function findVcvarsall() {
throw new Error('Microsoft Visual Studio not found')
}
function isPathVariable(name) {
const pathLikeVariables = ['PATH', 'INCLUDE', 'LIB', 'LIBPATH']
return pathLikeVariables.indexOf(name.toUpperCase()) != -1
}
function filterPathValue(path) {
let paths = path.split(';')
// Remove duplicates by keeping the first occurance and preserving order.
// This keeps path shadowing working as intended.
function unique(value, index, self) {
return self.indexOf(value) === index
}
return paths.filter(unique).join(';')
}
function main() {
if (process.platform != 'win32') {
core.info('This is not a Windows virtual environment, bye!')
@@ -139,11 +154,18 @@ function main() {
if (!string.includes('=')) {
continue;
}
const [name, new_value] = string.split('=')
const old_value = old_env_vars[name]
let [name, new_value] = string.split('=')
let old_value = old_env_vars[name]
// For new variables "old_value === undefined".
if (new_value !== old_value) {
core.info(`Setting ${name}`)
// Special case for a bunch of PATH-like variables: vcvarsall.bat
// just prepends its stuff without checking if its already there.
// This makes repeated invocations of this action fail after some
// point, when the environment variable overflows. Avoid that.
if (isPathVariable(name)) {
new_value = filterPathValue(new_value)
}
core.exportVariable(name, new_value)
}
}