Skip to content

Commit

Permalink
Remove unused variable, clean up report file -- #143
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Dec 30, 2024
1 parent 4689836 commit 804134e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 26 deletions.
6 changes: 2 additions & 4 deletions config/wp.config.sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const {
WP_SSH_USERNAME = '',
WP_SSH_ADDRESS = '',
WP_SSH_KEY = '',
WP_SSH_ROOT_DIR = '',
GITHUB_PAT = ''
WP_SSH_ROOT_DIR = ''
} = process.env;

/**
Expand Down Expand Up @@ -99,6 +98,5 @@ export {
WP_SSH_ADDRESS,
WP_SSH_KEY,
WP_SSH_ROOT_DIR,
SCENARIO_URLS,
GITHUB_PAT
SCENARIO_URLS
};
96 changes: 74 additions & 22 deletions report.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,82 @@
import path from "path";
import {execFile} from "child_process";
import { execFile } from "child_process";
import {promises as fs} from "fs";

const scriptPath = path.resolve('move_report.sh');
/**
* Get the script path and arguments for moving the report.
*
* @return {Promise<{ scriptPath: string; args: string[] }>}
*/
async function initialization(): Promise<{ scriptPath: string; args: string[] }> {
const scriptPath = path.resolve('move_report.sh');
const destination = process.argv[2];
const newName = process.argv[3];

const destination = process.argv[2];
const newName = process.argv[3];
if (!destination) {
console.error('Usage: npm run push-report <destination_directory> [new_name]');
process.exit(1);
if (!destination) {
console.error('Usage: npm run push-report <destination_directory> [new_name]');
process.exit(1);
}

// Prepare the arguments for the script
const args = [destination];
if (newName) {
args.push(newName);
}

return { scriptPath, args };
}
/**
* Check if script has permission and if not add the right permission, so it can be executed.
* @param {string} scriptPath The script path.
*
* @return {Promise<void>}
*/
export async function checkScriptPermission(scriptPath: string): Promise<void> {
try {
await fs.access(scriptPath, fs.constants.X_OK);
console.log(`Script already has execute permission: ${scriptPath}`);
} catch (err) {
console.log(`Adding execute permission to ${scriptPath}`);
try {
await fs.chmod(scriptPath, 0o755);
console.log(`Execute permission added successfully: ${scriptPath}`);
} catch (chmodErr) {
console.error(`Failed to set execute permission: ${chmodErr.message}`);
throw chmodErr;
}
}
}

// Prepare the arguments for the script
const args = [destination];
if (newName) {
args.push(newName);
/**
* Move the test-results directory to the given directory.
* @param {string} scriptPath The script path.
* @param args Script argument.
*
* @return {Promise<void>}
*/
export async function moveTestReport(scriptPath: string, args: readonly string[]): Promise<void> {
execFile(scriptPath, args, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(`Output: ${stdout}`);
});
}

// Execute the bash script
execFile(scriptPath, args, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
(async (): Promise<void> => {
try {
const { scriptPath, args } = await initialization();
await checkScriptPermission(scriptPath);
await moveTestReport(scriptPath, args);
} catch (err) {
console.error(`Failed to execute the script: ${err.message}`);
process.exit(1);
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(`Output: ${stdout}`);
});

process.exit(0);
})();

0 comments on commit 804134e

Please sign in to comment.