Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Azure/cli action fail when executed on a non-Linux-based OS #123

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

MoChilia
Copy link
Member

Description

Azure/cli should terminate with a failure on a non-Linux-based OS; however, it currently doesn't exit with code 1 but merely outputs an error message.

Former:
image
Expected:
image

@MoChilia MoChilia requested a review from jiasli November 21, 2023 08:14
@@ -16,8 +16,7 @@ export async function main() {
const CONTAINER_NAME = `MICROSOFT_AZURE_CLI_${getCurrentTime()}_CONTAINER`;
try {
if (process.env.RUNNER_OS != 'Linux') {
core.setFailed('Please use Linux based OS as a runner.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't core.setFailed cause failure?

Copy link
Member Author

@MoChilia MoChilia Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of core.setFailed is "Sets the action status to failed. When the action exits it will be with an exit code of 1.". See https://docs.github.com/en/actions/creating-actions/setting-exit-codes-for-actions.
However, in the previous code, it returned after setFailed.

cli/src/main.ts

Lines 18 to 20 in 1828f1c

if (process.env.RUNNER_OS != 'Linux') {
core.setFailed('Please use Linux based OS as a runner.');
return;

This would cause main() didn't catch the error.

cli/src/main.ts

Lines 77 to 80 in 1828f1c

catch (error) {
core.error(error);
throw error;
}

Then, main() exited with 0.

cli/src/entrypoint.ts

Lines 4 to 10 in 1828f1c

main()
.then(() => {
process.exit(0)
})
.catch((err: Error) => {
setFailed(err.message);
process.exit(1);

This is why core.setFailed doesn't cause failure in previous code.

@@ -16,8 +16,7 @@ export async function main() {
const CONTAINER_NAME = `MICROSOFT_AZURE_CLI_${getCurrentTime()}_CONTAINER`;
try {
if (process.env.RUNNER_OS != 'Linux') {
core.setFailed('Please use Linux based OS as a runner.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Git Blame, this line was added as early as 9932b03. Later, 548c3ec added src/entrypoint.ts which overrides core.setFailed with

process.exit(0)

@MoChilia MoChilia merged commit 49022ee into Azure:master Nov 24, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants