Skip to content

Commit

Permalink
Improve catchup script 2 (#237)
Browse files Browse the repository at this point in the history
* use error code 9 to exit with invalid argument

* replace console.error with console.warn when the error is not rethrow
  • Loading branch information
BlueCutOfficial authored Jan 10, 2024
1 parent f2d1cea commit 7b001a9
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions scripts/catchup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const argv = minimist(process.argv.slice(2), { string: ['from', 'to'] });
const currentEmberVersion = `${argv.from}`;
if (currentEmberVersion.match(/\d+[.]\d+/g)?.[0] !== currentEmberVersion) {
console.error('Error: please provide the current Ember version under translation to option --from (e.g. --from=5.1)');
process.exit(2);
process.exit(9);
}
console.log(`Ember version under translation: ${currentEmberVersion}`);

// Read new Ember version (documented by the English guides)
const newEmberVersion = `${argv.to}`;
if (newEmberVersion.match(/\d+[.]\d+/g)?.[0] !== newEmberVersion) {
console.error('Error: please provide the new Ember version documented on upstream to option --to (e.g. --to=5.4)');
process.exit(2);
process.exit(9);
}
console.log(`New Ember version documented on upstream: ${newEmberVersion}`);

Expand Down Expand Up @@ -133,7 +133,7 @@ const writeDiffFiles = async () => {
try {
diffName = createDiff(filename, index);
} catch (error) {
console.error(error);
console.warn(error);
resolve(1);
}
// Read the created diff file, we need to access its content to adjust it to our Guidemaker scaffolding
Expand All @@ -148,7 +148,7 @@ ACTION REQUIRED: The patch paths could not be edited for ${diffName} because the
If the command fails, open a GitHub issue and copy the diff using the provided issue template.
`);
console.error(`Failed to read ${diffName} to edit the patch path. This was caused by: ${err}`);
console.warn(`Failed to read ${diffName} to edit the patch path. This was caused by: ${err}`);
resolve(1);
}

Expand All @@ -167,7 +167,7 @@ ACTION REQUIRED: The patch paths could not be edited for ${diffName} because the
If the command fails, open a GitHub issue and copy the diff using the provided issue template.
`);
console.error(`Failed to write ${diffName} to edit the patch path. This was caused by: ${err}`);
console.warn(`Failed to write ${diffName} to edit the patch path. This was caused by: ${err}`);
resolve(1);
}
console.log(`Path in ${diffName} updated`);
Expand All @@ -183,7 +183,7 @@ ACTION REQUIRED: The patch paths could not be edited for ${diffName} because the
// Remove the file if the apply was successfull
fs.unlink(diffName, function(err) {
if (err) {
console.error(err);
console.warn(err);
} else {
console.log(`${diffName} handled and deleted`);
}
Expand All @@ -194,7 +194,6 @@ ACTION REQUIRED: The patch paths could not be edited for ${diffName} because the
filesToPost.push({ filename: unversionedFileName, diffName });
resolve(2);
}
resolve(0);
});
});
});
Expand All @@ -204,7 +203,7 @@ ACTION REQUIRED: The patch paths could not be edited for ${diffName} because the
const hasErrors = result.some((status) => status === 1);
if (hasErrors) {
hasPendingDiff = true;
console.log('Writing operations have been completed with errors. Some of the patch files are applied or stored in scripts/patches/, and manual actions have been added to the warning list.');
console.warn('Writing operations have been completed with errors. Some of the patch files are applied or stored in scripts/patches/, and manual actions have been added to the warning list.');
} else {
console.log('All writing operations have been completed without errors, patch files are applied or stored in scripts/patches/');
}
Expand Down Expand Up @@ -300,7 +299,7 @@ const postAllIssues = async () => {
const jsonResponse = await response.json();
console.log('Server responded with:', jsonResponse);
} catch (error) {
console.error('Issue posting has failed:', error);
console.warn('Issue posting has failed:', error);
warnings.push(`
ACTION REQUIRED: The issue for file ${file.filename} (${file.diffName}) couldn't be opened automatically.
-> Open it manually using the dedicated issue template.
Expand All @@ -314,14 +313,14 @@ ACTION REQUIRED: The issue for file ${file.filename} (${file.diffName}) couldn't

// If one of the post failed, we keep the diff files so we can easily open the issue manually
if (issuePostingError) {
console.error("At least one Github issue was not posted, scripts/patches folder won't be deleted so missing issues can be posted manually");
console.warn("At least one Github issue was not posted, scripts/patches folder won't be deleted so missing issues can be posted manually");
} else {
try {
// If and once the issues are posted, delete patches folder and files
fs.rmSync('scripts/patches', { recursive: true, force: true });
console.log('scripts/patches folder and files did their job, deleted');
} catch(error) {
console.error('Failed to delete the folder scripts/patches and its content.')
console.warn('Failed to delete the folder scripts/patches and its content.')
}
}
}
Expand Down Expand Up @@ -353,7 +352,7 @@ const switchToMaster = () => {
try {
runShell('git switch master');
} catch (error) {
console.error('The process is complete, but failed to switch back to master');
console.warn('The process is complete, but failed to switch back to master');
}
}

Expand All @@ -367,7 +366,7 @@ const switchToCatchup = () => {
runShell(`git switch ${catchupBranch}`);
console.log('Stay on the catchup branch at the end of the process, so non-posted issues can be handled.');
} catch (error) {
console.error(`The process is complete, but failed to switch back to ${catchupBranch}`);
console.warn(`The process is complete, but failed to switch back to ${catchupBranch}`);
warnings.push(`
ACTION REQUIRED: The process failed to switch back to ${catchupBranch}.
-> Switch manually to ${catchupBranch} then complete the other required actions.
Expand Down Expand Up @@ -452,7 +451,7 @@ try {
files = data.split(/[\n\r]/).filter(name => name.length);
fs.unlink('list.diff', function(err) {
if (err) {
console.error('Failed to delete list.diff');
console.warn('Failed to delete list.diff');
} else {
console.log('list.diff did its job, deleted');
}
Expand Down Expand Up @@ -485,7 +484,7 @@ try {
const jsonPrResponse = await prResponse.json();
console.log('Server responded with:', jsonPrResponse);
} catch (error) {
console.error(`Failed to post the catchup PR. This was caused by: ${error}`);
console.warn(`Failed to post the catchup PR. This was caused by: ${error}`);
warnings.push(`
ACTION REQUIRED: The catchup PR was not opened automatically on GitHub.
-> Chack what's the issue, then open the PR on GitHub manually.
Expand All @@ -494,7 +493,7 @@ ACTION REQUIRED: The catchup PR was not opened automatically on GitHub.
}

} catch (error) {
console.error('Failed to push the catchup branch.');
console.warn('Failed to push the catchup branch.');
}
}

Expand Down

0 comments on commit 7b001a9

Please sign in to comment.