Files
Actions/with-post-step/main.js
Unai Martinez-Corral 9faa1459c9 with-post-step: use option 'shell: true' by default and do not split args
This fixes a breaking change introduced in #46.
'exec' executes commands on the shell by default, while 'spawn' does not.
2022-11-08 03:15:19 +01:00

45 lines
3.6 KiB
JavaScript

/* ================================================================================================================== *
* Authors: *
* Unai Martinez-Corral *
* *
* ================================================================================================================== *
* Copyright 2021 Unai Martinez-Corral <unai.martinezcorral@ehu.eus> *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
* SPDX-License-Identifier: Apache-2.0 *
* ================================================================================================================== *
* *
* Context: *
* * https://github.com/docker/login-action/issues/72 *
* * https://github.com/actions/runner/issues/1478 *
* ================================================================================================================== */
const { spawn } = require("child_process");
const fs = require('fs');
function run(cmd) {
const subprocess = spawn(cmd, { stdio: "inherit", shell: true });
subprocess.on("exit", (exitCode) => {
process.exitCode = exitCode;
});
}
const key = process.env.INPUT_KEY.toUpperCase();
if ( process.env[`STATE_${key}`] !== undefined ) { // Are we in the 'post' step?
run(process.env.INPUT_POST);
} else { // Otherwise, this is the main step
fs.appendFileSync(process.env.GITHUB_STATE, `${key}=true`);
run(process.env.INPUT_MAIN);
}