Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/Misc/layoutroot/run-helper.cmd.template
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
@echo off
SET UPDATEFILE=update.finished
"%~dp0\bin\Runner.Listener.exe" run %*
SET RETURNCODE=%ERRORLEVEL%
SET OUTDATED_EXIT_CODE_NUM=

if not "%ACTIONS_RUNNER_OUTDATED_EXIT_CODE%"=="" (
set /a OUTDATED_EXIT_CODE_NUM=%ACTIONS_RUNNER_OUTDATED_EXIT_CODE% >NUL 2>NUL
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
if errorlevel 1 SET OUTDATED_EXIT_CODE_NUM=
)

if not "%OUTDATED_EXIT_CODE_NUM%"=="" (
if %OUTDATED_EXIT_CODE_NUM% LEQ 5 SET OUTDATED_EXIT_CODE_NUM=
Comment thread
TingluoHuang marked this conversation as resolved.
Outdated
)

rem using `if %ERRORLEVEL% EQU N` instead of `if ERRORLEVEL N`
rem `if ERRORLEVEL N` means: error level is N or MORE

if %ERRORLEVEL% EQU 0 (
if %RETURNCODE% EQU 0 (
echo "Runner listener exit with 0 return code, stop the service, no retry needed."
exit /b 0
)

if %ERRORLEVEL% EQU 1 (
if not "%OUTDATED_EXIT_CODE_NUM%"=="" (
if "%RETURNCODE%"=="%OUTDATED_EXIT_CODE_NUM%" (
echo "Runner listener exit with outdated error code: %RETURNCODE%."
exit /b %RETURNCODE%
)
)

if %RETURNCODE% EQU 1 (
echo "Runner listener exit with terminated error, stop the service, no retry needed."
exit /b 0
)

if %ERRORLEVEL% EQU 2 (
if %RETURNCODE% EQU 2 (
echo "Runner listener exit with retryable error, re-launch runner in 5 seconds."
ping 127.0.0.1 -n 6 -w 1000 >NUL
exit /b 1
)

if %ERRORLEVEL% EQU 3 (
if %RETURNCODE% EQU 3 (
rem Wait for 30 seconds or for flag file to exists for the ephemeral runner update process finish
echo "Runner listener exit because of updating, re-launch runner after successful update"
FOR /L %%G IN (1,1,30) DO (
Expand All @@ -35,7 +53,7 @@ if %ERRORLEVEL% EQU 3 (
exit /b 1
)

if %ERRORLEVEL% EQU 4 (
if %RETURNCODE% EQU 4 (
rem Wait for 30 seconds or for flag file to exists for the runner update process finish
echo "Runner listener exit because of updating, re-launch runner after successful update"
FOR /L %%G IN (1,1,30) DO (
Expand All @@ -49,10 +67,10 @@ if %ERRORLEVEL% EQU 4 (
exit /b 1
)

if %ERRORLEVEL% EQU 5 (
if %RETURNCODE% EQU 5 (
echo "Runner listener exit with Session Conflict error, stop the service, no retry needed."
exit /b 0
)

echo "Exiting after unknown error code: %ERRORLEVEL%"
echo "Exiting after unknown error code: %RETURNCODE%"
exit /b 0
6 changes: 4 additions & 2 deletions src/Misc/layoutroot/run-helper.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ fi

updateFile="update.finished"
"$DIR"/bin/Runner.Listener run $*

returnCode=$?
if [[ $returnCode == 0 ]]; then
echo "Runner listener exit with 0 return code, stop the service, no retry needed."
exit 0
elif [[ "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" =~ ^[0-9]+$ && "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" -gt 5 && "$returnCode" -eq "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; then
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
echo "Runner listener exit with outdated error code: ${returnCode}."
exit "$returnCode"
elif [[ $returnCode == 1 ]]; then
echo "Runner listener exit with terminated error, stop the service, no retry needed."
exit 0
Expand Down Expand Up @@ -74,6 +76,6 @@ elif [[ $returnCode == 5 ]]; then
echo "Runner listener exit with Session Conflict error, stop the service, no retry needed."
exit 0
else
echo "Exiting with unknown error code: ${returnCode}"
echo "NOO Exiting with unknown error code: ${returnCode}"
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
exit 0
fi
26 changes: 22 additions & 4 deletions src/Misc/layoutroot/run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,29 @@ rem ****************************************************************************
:launch_helper
copy "%~dp0run-helper.cmd.template" "%~dp0run-helper.cmd" /Y
call "%~dp0run-helper.cmd" %*
set RETURNCODE=%ERRORLEVEL%
set OUTDATED_EXIT_CODE_NUM=

if not "%ACTIONS_RUNNER_OUTDATED_EXIT_CODE%"=="" (
set /a OUTDATED_EXIT_CODE_NUM=%ACTIONS_RUNNER_OUTDATED_EXIT_CODE% >NUL 2>NUL
if errorlevel 1 set OUTDATED_EXIT_CODE_NUM=
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
)

if not "%OUTDATED_EXIT_CODE_NUM%"=="" (
if %OUTDATED_EXIT_CODE_NUM% LEQ 5 set OUTDATED_EXIT_CODE_NUM=
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
)

if %ERRORLEVEL% EQU 1 (
if %RETURNCODE% EQU 1 (
echo "Restarting runner..."
goto :launch_helper
) else (
echo "Exiting runner..."
exit /b 0
)

if not "%OUTDATED_EXIT_CODE_NUM%"=="" (
if "%RETURNCODE%"=="%OUTDATED_EXIT_CODE_NUM%" (
echo "Exiting runner with outdated error code: %RETURNCODE%"
exit /b %RETURNCODE%
)
)

echo "Exiting runner..."
exit /b 0
6 changes: 6 additions & 0 deletions src/Misc/layoutroot/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ run() {
returnCode=$?
if [[ $returnCode -eq 2 ]]; then
echo "Restarting runner..."
elif [[ -n "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" && "$returnCode" == "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; then
echo "Exiting runner..."
exit "$returnCode"
Comment thread
TingluoHuang marked this conversation as resolved.
else
echo "Exiting runner..."
exit 0
Expand All @@ -42,6 +45,9 @@ runWithManualTrap() {
returnCode=$?
if [[ $returnCode -eq 2 ]]; then
echo "Restarting runner..."
elif [[ -n "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" && "$returnCode" == "$ACTIONS_RUNNER_OUTDATED_EXIT_CODE" ]]; then
echo "Exiting runner..."
exit "$returnCode"
Comment thread
nikola-jokic marked this conversation as resolved.
else
echo "Exiting runner..."
# Unregister signal handling before exit
Expand Down
1 change: 1 addition & 0 deletions src/Runner.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public static class Actions
public static readonly string AllowUnsupportedStopCommandTokens = "ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS";
public static readonly string RequireJobContainer = "ACTIONS_RUNNER_REQUIRE_JOB_CONTAINER";
public static readonly string RunnerDebug = "ACTIONS_RUNNER_DEBUG";
public static readonly string RunnerOutdatedExitCode = "ACTIONS_RUNNER_OUTDATED_EXIT_CODE";
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
public static readonly string StepDebug = "ACTIONS_STEP_DEBUG";
}

Expand Down
14 changes: 13 additions & 1 deletion src/Runner.Listener/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private async static Task<int> MainAsync(IHostContext context, string[] args)
{
terminal.WriteError($"An error occured: {e.Message}");
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
trace.Error(e);
return Constants.Runner.ReturnCode.TerminatedError;
return GetRunnerOutdatedExitCode();
}
catch (RunnerNotFoundException e)
{
Expand All @@ -159,6 +159,18 @@ private async static Task<int> MainAsync(IHostContext context, string[] args)
}
}

private static int GetRunnerOutdatedExitCode()
{
var configuredExitCode = Environment.GetEnvironmentVariable(Constants.Variables.Actions.RunnerOutdatedExitCode);
if (int.TryParse(configuredExitCode, NumberStyles.Integer, CultureInfo.InvariantCulture, out int exitCode) &&
exitCode > 5)
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
{
return exitCode;
}

return Constants.Runner.ReturnCode.TerminatedError;
Comment thread
nikola-jokic marked this conversation as resolved.
Outdated
}

private static void LoadAndSetEnv()
{
var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Expand Down
Loading