Skip to content

Commit

Permalink
windows runner fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyaven committed Apr 25, 2024
1 parent f67f901 commit a2f4bd8
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function setupAuth(core) {

// Check if any authentication method is provided
if (!checkEnvVarValid(fileName) && !checkEnvVarValid(authStr)) {
core.info("Using default provider environment variable variables as AUTH_FILE_PATH or AUTH_STR are not set...");
core.info("using default provider environment variable variables as AUTH_FILE_PATH or AUTH_STR are not set...");
return;
}

Expand All @@ -24,7 +24,7 @@ function setupAuth(core) {
auth = fs.readFileSync(fileName, "utf-8");
} catch (error) {
core.error(error);
core.setFailed(`Cannot find auth file ${fileName}`);
core.setFailed(`cannot find auth file ${fileName}`);
return;
}
}
Expand All @@ -33,7 +33,7 @@ function setupAuth(core) {
auth = authStr;
}

core.info("Setting AUTH environment variable...");
core.info("setting AUTH environment variable...");
core.exportVariable("AUTH", auth);
}

Expand All @@ -50,12 +50,12 @@ async function getStackqlCommand(core) {

// output supports: json, csv, table, text only, fail if not supported
if (!["json", "csv", "table", "text"].includes(output)) {
core.setFailed(`Output format not supported: ${output}`);
core.setFailed(`output format not supported: ${output}`);
return;
}

if (!checkEnvVarValid(query) && !checkEnvVarValid(queryFilePath)) {
core.setFailed("Either query or query_file_path need to be set");
core.setFailed("either query or query_file_path need to be set");
return;
}

Expand All @@ -68,7 +68,7 @@ async function getStackqlCommand(core) {
];
} else if (queryFilePath) {
if (!fs.existsSync(queryFilePath)) {
core.setFailed(`Query file path does not exist: ${queryFilePath}`);
core.setFailed(`query file path does not exist: ${queryFilePath}`);
return;
}
args = [
Expand All @@ -80,7 +80,7 @@ async function getStackqlCommand(core) {

if (checkEnvVarValid(dataFilePath)) {
if (!fs.existsSync(dataFilePath)) {
core.setFailed(`Data file path does not exist: ${dataFilePath}`);
core.setFailed(`data file path does not exist: ${dataFilePath}`);
return;
}
args.push(`--iqldata "${dataFilePath}"`);
Expand All @@ -98,19 +98,20 @@ async function getStackqlCommand(core) {

let stackQLExecutable = "stackql"; // Default for non-Windows systems
const isWindows = process.platform === "win32";
isWindows ? core.info("running on Windows") : null;
if (isWindows) {
(async () => {
try {
const { stdout } = await execAsync('dir "stackql.exe" /S /B /A-D C:\\');
const lines = stdout.split('\n').filter(line => line.trim() !== '');
if (lines.length > 0) {
stackQLExecutable = lines[0].trim(); // Take the first result
console.log(`Found stackql.exe at: ${stackQLExecutable}`);
core.info(`found stackql.exe at: ${stackQLExecutable}`);
} else {
console.error('stackql.exe not found on the filesystem.');
core.error('stackql.exe not found on the filesystem.');
}
} catch (error) {
console.error('Error searching for stackql.exe:', error.message);
core.error('error searching for stackql.exe:', error.message);
}
})();
}
Expand All @@ -121,7 +122,7 @@ async function getStackqlCommand(core) {
core.info(`STACKQL_COMMAND: ${stackQLCommand}`);
} catch (error) {
core.error(error);
core.setFailed("Error when executing stackql");
core.setFailed("error when executing stackql");
}
}

Expand All @@ -136,7 +137,7 @@ const checkEnvVarValid = (variable) => {
* @param {boolean} isCommand - Indicates if the operation is a command (true) or query (false).
*/
function execStackQLQuery(core, command, isCommand) {
core.info(`Executing StackQL query (isCommand : ${isCommand}): ${command}`);
core.info(`executing StackQL query (isCommand : ${isCommand}): ${command}`);

exec(command, (error, stdout, stderr) => {
if (stdout) {
Expand All @@ -147,23 +148,23 @@ function execStackQLQuery(core, command, isCommand) {
}

if (error) {
core.error(`Error executing StackQL command: ${stderr}`);
core.error(`error executing StackQL command: ${stderr}`);
if (!isCommand) {
core.setFailed(`StackQL command failed with error: ${error.message}`);
core.setFailed(`stackql command failed with error: ${error.message}`);
}
return;
}

core.exportVariable('STACKQL_COMMAND_OUTPUT', stdout);

if (isCommand) {
core.info(`Command output: ${stdout}`);
core.info(`command output: ${stdout}`);
} else {
if (stderr) {
core.setFailed(`StackQL command reported an error: ${stderr}`);
core.setFailed(`stackql command reported an error: ${stderr}`);
core.exportVariable('STACKQL_COMMAND_ERROR', stderr);
} else {
core.info(`Query output: ${stdout}`);
core.info(`query output: ${stdout}`);
}
}
});
Expand Down

0 comments on commit a2f4bd8

Please sign in to comment.