-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unused variable, clean up report file -- #143
- Loading branch information
Showing
2 changed files
with
76 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |