I made my test.bat to be executed from GitHub Actions. The issue I have is that GitHub Actions completes job as success even it receives non-zero exit code from the test.bat.
Here is the YAML file for GitHub Actions.
jobs:
run_test:
runs-on: [self-hosted,Windows]
steps:
- run: ./test.bat
Here is the test.bat file that executes test.
REM This runs test and returns non-zero exit code when test fails.
test.exe -fail
REM Now, assume test failed, and it retruns exit code 4.
echo %error_level%
Now, GitHub Actions completes the job as success even it receves non-zero exit code (which is 4).
If I remove echo %error_level% then GitHub Action completes the job as fail, properly.
Why?
>Solution :
The echo command succeeds sucessfully and returns an exit code of 0.
Make sure you either capture the ERRORLEVEL:
REM This runs test and returns non-zero exit code when test fails.
test.exe -fail
set return_code=%ERRORLEVEL%
REM Now, assume test failed, and it returns exit code 4.
echo %return_code%
exit %return_code%
Or do an if statement and return your own exit code.
REM This runs test and returns non-zero exit code when test fails.
test.exe -fail
IF NOT %ERRORLEVEL% == 0 (
echo %ERRORLEVEL%
exit 1
)