mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b96b3c58c7 | ||
|
|
529e404063 | ||
|
|
c058208ce4 | ||
|
|
b3b97b7328 | ||
|
|
5f72720698 | ||
|
|
bc0c1263f0 | ||
|
|
82a4ca9a6b |
10
.github/workflows/release.yml
vendored
10
.github/workflows/release.yml
vendored
@@ -101,11 +101,11 @@ jobs:
|
|||||||
working-directory: src
|
working-directory: src
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
- name: L0
|
# - name: L0
|
||||||
run: |
|
# run: |
|
||||||
${{ matrix.devScript }} test
|
# ${{ matrix.devScript }} test
|
||||||
working-directory: src
|
# working-directory: src
|
||||||
if: matrix.runtime != 'linux-arm64' && matrix.runtime != 'linux-arm'
|
# if: matrix.runtime != 'linux-arm64' && matrix.runtime != 'linux-arm'
|
||||||
|
|
||||||
# Create runner package tar.gz/zip
|
# Create runner package tar.gz/zip
|
||||||
- name: Package Release
|
- name: Package Release
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<Update to ./src/runnerversion when creating release>
|
2.289.3
|
||||||
|
|||||||
12
src/Misc/expressionFunc/hashFiles/package-lock.json
generated
12
src/Misc/expressionFunc/hashFiles/package-lock.json
generated
@@ -1823,9 +1823,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/minimist": {
|
"node_modules/minimist": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||||
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
|
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
@@ -3808,9 +3808,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||||
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
|
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
@echo off
|
|
||||||
|
|
||||||
"%~dp0\bin\Runner.Listener.exe" run %*
|
|
||||||
|
|
||||||
rem using `if %ERRORLEVEL% EQU N` insterad of `if ERRORLEVEL N`
|
|
||||||
rem `if ERRORLEVEL N` means: error level is N or MORE
|
|
||||||
|
|
||||||
if %ERRORLEVEL% EQU 0 (
|
|
||||||
echo "Runner listener exit with 0 return code, stop the service, no retry needed."
|
|
||||||
exit /b 0
|
|
||||||
)
|
|
||||||
|
|
||||||
if %ERRORLEVEL% EQU 1 (
|
|
||||||
echo "Runner listener exit with terminated error, stop the service, no retry needed."
|
|
||||||
exit /b 0
|
|
||||||
)
|
|
||||||
|
|
||||||
if %ERRORLEVEL% 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 (
|
|
||||||
rem Sleep 5 seconds to wait for the runner update process finish
|
|
||||||
echo "Runner listener exit because of updating, re-launch runner in 5 seconds"
|
|
||||||
ping 127.0.0.1 -n 6 -w 1000 >NUL
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
if %ERRORLEVEL% EQU 4 (
|
|
||||||
rem Sleep 5 seconds to wait for the ephemeral runner update process finish
|
|
||||||
echo "Runner listener exit because of updating, re-launch ephemeral runner in 5 seconds"
|
|
||||||
ping 127.0.0.1 -n 6 -w 1000 >NUL
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "Exiting after unknown error code: %ERRORLEVEL%"
|
|
||||||
exit /b 0
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Validate not sudo
|
|
||||||
user_id=`id -u`
|
|
||||||
if [ $user_id -eq 0 -a -z "$RUNNER_ALLOW_RUNASROOT" ]; then
|
|
||||||
echo "Must not run interactively with sudo"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run
|
|
||||||
shopt -s nocasematch
|
|
||||||
|
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
|
||||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
||||||
SOURCE="$(readlink "$SOURCE")"
|
|
||||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
|
||||||
done
|
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
||||||
"$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 [[ $returnCode == 1 ]]; then
|
|
||||||
echo "Runner listener exit with terminated error, stop the service, no retry needed."
|
|
||||||
exit 0
|
|
||||||
elif [[ $returnCode == 2 ]]; then
|
|
||||||
echo "Runner listener exit with retryable error, re-launch runner in 5 seconds."
|
|
||||||
"$DIR"/safe_sleep.sh 5
|
|
||||||
exit 2
|
|
||||||
elif [[ $returnCode == 3 ]]; then
|
|
||||||
# Sleep 5 seconds to wait for the runner update process finish
|
|
||||||
echo "Runner listener exit because of updating, re-launch runner in 5 seconds"
|
|
||||||
"$DIR"/safe_sleep.sh 5
|
|
||||||
exit 2
|
|
||||||
elif [[ $returnCode == 4 ]]; then
|
|
||||||
# Sleep 5 seconds to wait for the ephemeral runner update process finish
|
|
||||||
echo "Runner listener exit because of updating, re-launch ephemeral runner in 5 seconds"
|
|
||||||
"$DIR"/safe_sleep.sh 5
|
|
||||||
exit 2
|
|
||||||
else
|
|
||||||
echo "Exiting with unknown error code: ${returnCode}"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
@@ -13,19 +13,21 @@ if defined VERBOSE_ARG (
|
|||||||
rem Unblock files in the root of the layout folder. E.g. .cmd files.
|
rem Unblock files in the root of the layout folder. E.g. .cmd files.
|
||||||
powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "$VerbosePreference = %VERBOSE_ARG% ; Get-ChildItem -LiteralPath '%~dp0' | ForEach-Object { Write-Verbose ('Unblock: {0}' -f $_.FullName) ; $_ } | Unblock-File | Out-Null"
|
powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "$VerbosePreference = %VERBOSE_ARG% ; Get-ChildItem -LiteralPath '%~dp0' | ForEach-Object { Write-Verbose ('Unblock: {0}' -f $_.FullName) ; $_ } | Unblock-File | Out-Null"
|
||||||
|
|
||||||
|
if /i "%~1" equ "localRun" (
|
||||||
|
rem ********************************************************************************
|
||||||
|
rem Local run.
|
||||||
|
rem ********************************************************************************
|
||||||
|
"%~dp0bin\Runner.Listener.exe" %*
|
||||||
|
) else (
|
||||||
|
rem ********************************************************************************
|
||||||
|
rem Run.
|
||||||
|
rem ********************************************************************************
|
||||||
|
"%~dp0bin\Runner.Listener.exe" run %*
|
||||||
|
|
||||||
rem ********************************************************************************
|
rem Return code 4 means the run once runner received an update message.
|
||||||
rem Run.
|
rem Sleep 5 seconds to wait for the update process finish and run the runner again.
|
||||||
rem ********************************************************************************
|
if ERRORLEVEL 4 (
|
||||||
|
timeout /t 5 /nobreak > NUL
|
||||||
:launch_helper
|
"%~dp0bin\Runner.Listener.exe" run %*
|
||||||
copy "%~dp0run-helper.cmd.template" "%~dp0run-helper.cmd" /Y
|
)
|
||||||
call "%~dp0run-helper.cmd" %*
|
|
||||||
|
|
||||||
if %ERRORLEVEL% EQU 1 (
|
|
||||||
echo "Restarting runner..."
|
|
||||||
goto :launch_helper
|
|
||||||
) else (
|
|
||||||
echo "Exiting runner..."
|
|
||||||
exit /b 0
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,24 +1,64 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Validate not sudo
|
||||||
|
user_id=`id -u`
|
||||||
|
if [ $user_id -eq 0 -a -z "$RUNNER_ALLOW_RUNASROOT" ]; then
|
||||||
|
echo "Must not run interactively with sudo"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Change directory to the script root directory
|
# Change directory to the script root directory
|
||||||
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
|
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
SOURCE="$(readlink "$SOURCE")"
|
SOURCE="$(readlink "$SOURCE")"
|
||||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||||
done
|
done
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
cp -f "$DIR"/run-helper.sh.template "$DIR"/run-helper.sh
|
|
||||||
# run the helper process which keep the listener alive
|
# Do not "cd $DIR". For localRun, the current directory is expected to be the repo location on disk.
|
||||||
while :;
|
|
||||||
do
|
# Run
|
||||||
"$DIR"/run-helper.sh $*
|
shopt -s nocasematch
|
||||||
|
if [[ "$1" == "localRun" ]]; then
|
||||||
|
"$DIR"/bin/Runner.Listener $*
|
||||||
|
else
|
||||||
|
"$DIR"/bin/Runner.Listener run $*
|
||||||
|
|
||||||
|
# Return code 3 means the run once runner received an update message.
|
||||||
|
# Sleep 5 seconds to wait for the update process finish
|
||||||
returnCode=$?
|
returnCode=$?
|
||||||
if [[ $returnCode -eq 2 ]]; then
|
if [[ $returnCode == 3 ]]; then
|
||||||
echo "Restarting runner..."
|
if [ ! -x "$(command -v sleep)" ]; then
|
||||||
|
if [ ! -x "$(command -v ping)" ]; then
|
||||||
|
COUNT="0"
|
||||||
|
while [[ $COUNT != 5000 ]]; do
|
||||||
|
echo "SLEEP" > /dev/null
|
||||||
|
COUNT=$[$COUNT+1]
|
||||||
|
done
|
||||||
|
else
|
||||||
|
ping -c 5 127.0.0.1 > /dev/null
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
sleep 5
|
||||||
|
fi
|
||||||
|
elif [[ $returnCode == 4 ]]; then
|
||||||
|
if [ ! -x "$(command -v sleep)" ]; then
|
||||||
|
if [ ! -x "$(command -v ping)" ]; then
|
||||||
|
COUNT="0"
|
||||||
|
while [[ $COUNT != 5000 ]]; do
|
||||||
|
echo "SLEEP" > /dev/null
|
||||||
|
COUNT=$[$COUNT+1]
|
||||||
|
done
|
||||||
|
else
|
||||||
|
ping -c 5 127.0.0.1 > /dev/null
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
sleep 5
|
||||||
|
fi
|
||||||
|
"$DIR"/bin/Runner.Listener run $*
|
||||||
else
|
else
|
||||||
echo "Exiting runner..."
|
exit $returnCode
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
done
|
fi
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ namespace GitHub.Runner.Common
|
|||||||
public static class Features
|
public static class Features
|
||||||
{
|
{
|
||||||
public static readonly string DiskSpaceWarning = "runner.diskspace.warning";
|
public static readonly string DiskSpaceWarning = "runner.diskspace.warning";
|
||||||
public static readonly string Node12Warning = "DistributedTask.AddWarningToNode12Action";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly string InternalTelemetryIssueDataKey = "_internal_telemetry";
|
public static readonly string InternalTelemetryIssueDataKey = "_internal_telemetry";
|
||||||
@@ -159,7 +158,6 @@ namespace GitHub.Runner.Common
|
|||||||
public static readonly string UnsupportedCommandMessageDisabled = "The `{0}` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/";
|
public static readonly string UnsupportedCommandMessageDisabled = "The `{0}` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/";
|
||||||
public static readonly string UnsupportedStopCommandTokenDisabled = "You cannot use a endToken that is an empty string, the string 'pause-logging', or another workflow command. For more information see: https://docs.github.com/actions/learn-github-actions/workflow-commands-for-github-actions#example-stopping-and-starting-workflow-commands or opt into insecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS` environment variable to `true`.";
|
public static readonly string UnsupportedStopCommandTokenDisabled = "You cannot use a endToken that is an empty string, the string 'pause-logging', or another workflow command. For more information see: https://docs.github.com/actions/learn-github-actions/workflow-commands-for-github-actions#example-stopping-and-starting-workflow-commands or opt into insecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS` environment variable to `true`.";
|
||||||
public static readonly string UnsupportedSummarySize = "$GITHUB_STEP_SUMMARY upload aborted, supports content up to a size of {0}k, got {1}k. For more information see: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary";
|
public static readonly string UnsupportedSummarySize = "$GITHUB_STEP_SUMMARY upload aborted, supports content up to a size of {0}k, got {1}k. For more information see: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary";
|
||||||
public static readonly string Node12DetectedAfterEndOfLife = "Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: {0}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RunnerEvent
|
public static class RunnerEvent
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ using GitHub.DistributedTask.WebApi;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -12,7 +10,6 @@ using System.Threading.Tasks;
|
|||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
using GitHub.Services.Common;
|
using GitHub.Services.Common;
|
||||||
using GitHub.Services.WebApi;
|
using GitHub.Services.WebApi;
|
||||||
using GitHub.Services.WebApi.Utilities.Internal;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace GitHub.Runner.Common
|
namespace GitHub.Runner.Common
|
||||||
@@ -174,11 +171,6 @@ namespace GitHub.Runner.Common
|
|||||||
Trace.Info($"Creating websocket client ..." + feedStreamUrl);
|
Trace.Info($"Creating websocket client ..." + feedStreamUrl);
|
||||||
this._websocketClient = new ClientWebSocket();
|
this._websocketClient = new ClientWebSocket();
|
||||||
this._websocketClient.Options.SetRequestHeader("Authorization", $"Bearer {accessToken}");
|
this._websocketClient.Options.SetRequestHeader("Authorization", $"Bearer {accessToken}");
|
||||||
var userAgentValues = new List<ProductInfoHeaderValue>();
|
|
||||||
userAgentValues.AddRange(UserAgentUtility.GetDefaultRestUserAgent());
|
|
||||||
userAgentValues.AddRange(HostContext.UserAgents);
|
|
||||||
this._websocketClient.Options.SetRequestHeader("User-Agent", string.Join(" ", userAgentValues.Select(x=>x.ToString())));
|
|
||||||
|
|
||||||
this._websocketConnectTask = ConnectWebSocketClient(feedStreamUrl, delay);
|
this._websocketConnectTask = ConnectWebSocketClient(feedStreamUrl, delay);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using GitHub.DistributedTask.Pipelines;
|
|
||||||
using GitHub.DistributedTask.WebApi;
|
|
||||||
using GitHub.Runner.Common.Util;
|
|
||||||
using GitHub.Runner.Sdk;
|
|
||||||
using GitHub.Services.Common;
|
|
||||||
using GitHub.Services.WebApi;
|
|
||||||
|
|
||||||
namespace GitHub.Runner.Common
|
|
||||||
{
|
|
||||||
[ServiceLocator(Default = typeof(RunServer))]
|
|
||||||
public interface IRunServer : IRunnerService
|
|
||||||
{
|
|
||||||
Task ConnectAsync(Uri serverUrl, VssCredentials credentials);
|
|
||||||
|
|
||||||
Task<AgentJobRequestMessage> GetJobMessageAsync(string id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RunServer : RunnerService, IRunServer
|
|
||||||
{
|
|
||||||
private bool _hasConnection;
|
|
||||||
private VssConnection _connection;
|
|
||||||
private TaskAgentHttpClient _taskAgentClient;
|
|
||||||
|
|
||||||
public async Task ConnectAsync(Uri serverUrl, VssCredentials credentials)
|
|
||||||
{
|
|
||||||
_connection = await EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(100));
|
|
||||||
_taskAgentClient = _connection.GetClient<TaskAgentHttpClient>();
|
|
||||||
_hasConnection = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<VssConnection> EstablishVssConnection(Uri serverUrl, VssCredentials credentials, TimeSpan timeout)
|
|
||||||
{
|
|
||||||
Trace.Info($"EstablishVssConnection");
|
|
||||||
Trace.Info($"Establish connection with {timeout.TotalSeconds} seconds timeout.");
|
|
||||||
int attemptCount = 5;
|
|
||||||
while (attemptCount-- > 0)
|
|
||||||
{
|
|
||||||
var connection = VssUtil.CreateConnection(serverUrl, credentials, timeout: timeout);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await connection.ConnectAsync();
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
catch (Exception ex) when (attemptCount > 0)
|
|
||||||
{
|
|
||||||
Trace.Info($"Catch exception during connect. {attemptCount} attempt left.");
|
|
||||||
Trace.Error(ex);
|
|
||||||
|
|
||||||
await HostContext.Delay(TimeSpan.FromMilliseconds(100), CancellationToken.None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// should never reach here.
|
|
||||||
throw new InvalidOperationException(nameof(EstablishVssConnection));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckConnection()
|
|
||||||
{
|
|
||||||
if (!_hasConnection)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"SetConnection");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<AgentJobRequestMessage> GetJobMessageAsync(string id)
|
|
||||||
{
|
|
||||||
CheckConnection();
|
|
||||||
return _taskAgentClient.GetJobMessageAsync(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -54,7 +54,7 @@ namespace GitHub.Runner.Listener.Configuration
|
|||||||
Trace.Info(nameof(LoadSettings));
|
Trace.Info(nameof(LoadSettings));
|
||||||
if (!IsConfigured())
|
if (!IsConfigured())
|
||||||
{
|
{
|
||||||
throw new NonRetryableException("Not configured. Run config.(sh/cmd) to configure the runner.");
|
throw new InvalidOperationException("Not configured. Run config.(sh/cmd) to configure the runner.");
|
||||||
}
|
}
|
||||||
|
|
||||||
RunnerSettings settings = _store.GetSettings();
|
RunnerSettings settings = _store.GetSettings();
|
||||||
@@ -624,12 +624,9 @@ namespace GitHub.Runner.Listener.Configuration
|
|||||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("basic", base64EncodingToken);
|
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("basic", base64EncodingToken);
|
||||||
httpClient.DefaultRequestHeaders.UserAgent.AddRange(HostContext.UserAgents);
|
httpClient.DefaultRequestHeaders.UserAgent.AddRange(HostContext.UserAgents);
|
||||||
httpClient.DefaultRequestHeaders.Accept.ParseAdd("application/vnd.github.v3+json");
|
httpClient.DefaultRequestHeaders.Accept.ParseAdd("application/vnd.github.v3+json");
|
||||||
|
|
||||||
var responseStatus = System.Net.HttpStatusCode.OK;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await httpClient.PostAsync(githubApiUrl, new StringContent(string.Empty));
|
var response = await httpClient.PostAsync(githubApiUrl, new StringContent(string.Empty));
|
||||||
responseStatus = response.StatusCode;
|
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
@@ -637,6 +634,11 @@ namespace GitHub.Runner.Listener.Configuration
|
|||||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||||
return StringUtil.ConvertFromJson<GitHubRunnerRegisterToken>(jsonResponse);
|
return StringUtil.ConvertFromJson<GitHubRunnerRegisterToken>(jsonResponse);
|
||||||
}
|
}
|
||||||
|
else if(response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
// It doesn't make sense to retry in this case, so just stop
|
||||||
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_term.WriteError($"Http response code: {response.StatusCode} from 'POST {githubApiUrl}'");
|
_term.WriteError($"Http response code: {response.StatusCode} from 'POST {githubApiUrl}'");
|
||||||
@@ -645,15 +647,15 @@ namespace GitHub.Runner.Listener.Configuration
|
|||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex) when (retryCount < 2 && responseStatus != System.Net.HttpStatusCode.NotFound)
|
catch(Exception ex) when (retryCount < 2)
|
||||||
{
|
{
|
||||||
retryCount++;
|
retryCount++;
|
||||||
Trace.Error($"Failed to get JIT runner token -- Atempt: {retryCount}");
|
Trace.Error($"Failed to get JIT runner token -- Atempt: {retryCount}");
|
||||||
Trace.Error(ex);
|
Trace.Error(ex);
|
||||||
|
Trace.Info("Retrying in 5 seconds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5));
|
var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5));
|
||||||
Trace.Info($"Retrying in {backOff.Seconds} seconds");
|
|
||||||
await Task.Delay(backOff);
|
await Task.Delay(backOff);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -687,11 +689,9 @@ namespace GitHub.Runner.Listener.Configuration
|
|||||||
{"runner_event", runnerEvent}
|
{"runner_event", runnerEvent}
|
||||||
};
|
};
|
||||||
|
|
||||||
var responseStatus = System.Net.HttpStatusCode.OK;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await httpClient.PostAsync(githubApiUrl, new StringContent(StringUtil.ConvertToJson(bodyObject), null, "application/json"));
|
var response = await httpClient.PostAsync(githubApiUrl, new StringContent(StringUtil.ConvertToJson(bodyObject), null, "application/json"));
|
||||||
responseStatus = response.StatusCode;
|
|
||||||
|
|
||||||
if(response.IsSuccessStatusCode)
|
if(response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
@@ -699,23 +699,29 @@ namespace GitHub.Runner.Listener.Configuration
|
|||||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||||
return StringUtil.ConvertFromJson<GitHubAuthResult>(jsonResponse);
|
return StringUtil.ConvertFromJson<GitHubAuthResult>(jsonResponse);
|
||||||
}
|
}
|
||||||
|
else if(response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
// It doesn't make sense to retry in this case, so just stop
|
||||||
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_term.WriteError($"Http response code: {response.StatusCode} from 'POST {githubApiUrl}'");
|
_term.WriteError($"Http response code: {response.StatusCode} from 'POST {githubApiUrl}'");
|
||||||
var errorResponse = await response.Content.ReadAsStringAsync();
|
var errorResponse = await response.Content.ReadAsStringAsync();
|
||||||
_term.WriteError(errorResponse);
|
_term.WriteError(errorResponse);
|
||||||
|
// Something else bad happened, let's go to our retry logic
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex) when (retryCount < 2 && responseStatus != System.Net.HttpStatusCode.NotFound)
|
catch(Exception ex) when (retryCount < 2)
|
||||||
{
|
{
|
||||||
retryCount++;
|
retryCount++;
|
||||||
Trace.Error($"Failed to get tenant credentials -- Atempt: {retryCount}");
|
Trace.Error($"Failed to get tenant credentials -- Atempt: {retryCount}");
|
||||||
Trace.Error(ex);
|
Trace.Error(ex);
|
||||||
|
Trace.Info("Retrying in 5 seconds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5));
|
var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5));
|
||||||
Trace.Info($"Retrying in {backOff.Seconds} seconds");
|
|
||||||
await Task.Delay(backOff);
|
await Task.Delay(backOff);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ using GitHub.Runner.Sdk;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using GitHub.Runner.Listener.Check;
|
using GitHub.Runner.Listener.Check;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
|
|
||||||
namespace GitHub.Runner.Listener
|
namespace GitHub.Runner.Listener
|
||||||
{
|
{
|
||||||
@@ -434,7 +430,7 @@ namespace GitHub.Runner.Listener
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
var selfUpdater = HostContext.GetService<ISelfUpdater>();
|
var selfUpdater = HostContext.GetService<ISelfUpdater>();
|
||||||
selfUpdateTask = selfUpdater.SelfUpdate(runnerUpdateMessage, jobDispatcher, false, HostContext.RunnerShutdownToken);
|
selfUpdateTask = selfUpdater.SelfUpdate(runnerUpdateMessage, jobDispatcher, !runOnce && HostContext.StartupType != StartupType.Service, HostContext.RunnerShutdownToken);
|
||||||
Trace.Info("Refresh message received, kick-off selfupdate background process.");
|
Trace.Info("Refresh message received, kick-off selfupdate background process.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -461,35 +457,6 @@ namespace GitHub.Runner.Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Broker flow
|
|
||||||
else if (string.Equals(message.MessageType, JobRequestMessageTypes.RunnerJobRequest, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
if (autoUpdateInProgress || runOnceJobReceived)
|
|
||||||
{
|
|
||||||
skipMessageDeletion = true;
|
|
||||||
Trace.Info($"Skip message deletion for job request message '{message.MessageId}'.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var messageRef = StringUtil.ConvertFromJson<RunnerJobRequestRef>(message.Body);
|
|
||||||
|
|
||||||
// Create connection
|
|
||||||
var credMgr = HostContext.GetService<ICredentialManager>();
|
|
||||||
var creds = credMgr.LoadCredentials();
|
|
||||||
|
|
||||||
// todo: add retries
|
|
||||||
var runServer = HostContext.CreateService<IRunServer>();
|
|
||||||
await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds);
|
|
||||||
var jobMessage = await runServer.GetJobMessageAsync(messageRef.RunnerRequestId);
|
|
||||||
|
|
||||||
jobDispatcher.Run(jobMessage, runOnce);
|
|
||||||
if (runOnce)
|
|
||||||
{
|
|
||||||
Trace.Info("One time used runner received job message.");
|
|
||||||
runOnceJobReceived = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (string.Equals(message.MessageType, JobCancelMessage.MessageType, StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(message.MessageType, JobCancelMessage.MessageType, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var cancelJobMessage = JsonUtility.FromString<JobCancelMessage>(message.Body);
|
var cancelJobMessage = JsonUtility.FromString<JobCancelMessage>(message.Body);
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace GitHub.Runner.Listener
|
|
||||||
{
|
|
||||||
[DataContract]
|
|
||||||
public sealed class RunnerJobRequestRef
|
|
||||||
{
|
|
||||||
[DataMember(Name = "id")]
|
|
||||||
public string Id { get; set; }
|
|
||||||
[DataMember(Name = "runner_request_id")]
|
|
||||||
public string RunnerRequestId { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -57,7 +57,6 @@ namespace GitHub.Runner.Sdk
|
|||||||
settings.SendTimeout = TimeSpan.FromSeconds(Math.Min(Math.Max(httpRequestTimeoutSeconds, 100), 1200));
|
settings.SendTimeout = TimeSpan.FromSeconds(Math.Min(Math.Max(httpRequestTimeoutSeconds, 100), 1200));
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.AllowAutoRedirect = true;
|
|
||||||
|
|
||||||
// Remove Invariant from the list of accepted languages.
|
// Remove Invariant from the list of accepted languages.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using GitHub.DistributedTask.Expressions2;
|
using GitHub.DistributedTask.Expressions2;
|
||||||
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
|
||||||
using GitHub.DistributedTask.Pipelines;
|
using GitHub.DistributedTask.Pipelines;
|
||||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
using GitHub.DistributedTask.Pipelines.ContextData;
|
||||||
using GitHub.DistributedTask.Pipelines.ObjectTemplating;
|
using GitHub.DistributedTask.Pipelines.ObjectTemplating;
|
||||||
@@ -110,12 +109,7 @@ namespace GitHub.Runner.Worker
|
|||||||
void ForceTaskComplete();
|
void ForceTaskComplete();
|
||||||
void RegisterPostJobStep(IStep step);
|
void RegisterPostJobStep(IStep step);
|
||||||
void PublishStepTelemetry();
|
void PublishStepTelemetry();
|
||||||
|
|
||||||
void ApplyContinueOnError(TemplateToken continueOnError);
|
|
||||||
void UpdateGlobalStepsContext();
|
|
||||||
|
|
||||||
void WriteWebhookPayload();
|
void WriteWebhookPayload();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
||||||
@@ -445,19 +439,14 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
_logger.End();
|
_logger.End();
|
||||||
|
|
||||||
UpdateGlobalStepsContext();
|
|
||||||
|
|
||||||
return Result.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateGlobalStepsContext()
|
|
||||||
{
|
|
||||||
// Skip if generated context name. Generated context names start with "__". After 3.2 the server will never send an empty context name.
|
// Skip if generated context name. Generated context names start with "__". After 3.2 the server will never send an empty context name.
|
||||||
if (!string.IsNullOrEmpty(ContextName) && !ContextName.StartsWith("__", StringComparison.Ordinal))
|
if (!string.IsNullOrEmpty(ContextName) && !ContextName.StartsWith("__", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
Global.StepsContext.SetOutcome(ScopeName, ContextName, (Outcome ?? Result ?? TaskResult.Succeeded).ToActionResult());
|
Global.StepsContext.SetOutcome(ScopeName, ContextName, (Outcome ?? Result ?? TaskResult.Succeeded).ToActionResult());
|
||||||
Global.StepsContext.SetConclusion(ScopeName, ContextName, (Result ?? TaskResult.Succeeded).ToActionResult());
|
Global.StepsContext.SetConclusion(ScopeName, ContextName, (Result ?? TaskResult.Succeeded).ToActionResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Result.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRunnerContext(string name, string value)
|
public void SetRunnerContext(string name, string value)
|
||||||
@@ -1075,36 +1064,6 @@ namespace GitHub.Runner.Worker
|
|||||||
var newGuid = Guid.NewGuid();
|
var newGuid = Guid.NewGuid();
|
||||||
return CreateChild(newGuid, displayName, newGuid.ToString("N"), null, null, ActionRunStage.Post, intraActionState, _childTimelineRecordOrder - Root.PostJobSteps.Count, siblingScopeName: siblingScopeName);
|
return CreateChild(newGuid, displayName, newGuid.ToString("N"), null, null, ActionRunStage.Post, intraActionState, _childTimelineRecordOrder - Root.PostJobSteps.Count, siblingScopeName: siblingScopeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyContinueOnError(TemplateToken continueOnErrorToken)
|
|
||||||
{
|
|
||||||
if (Result != TaskResult.Failed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var continueOnError = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var templateEvaluator = this.ToPipelineTemplateEvaluator();
|
|
||||||
continueOnError = templateEvaluator.EvaluateStepContinueOnError(continueOnErrorToken, ExpressionValues, ExpressionFunctions);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Trace.Info("The step failed and an error occurred when attempting to determine whether to continue on error.");
|
|
||||||
Trace.Error(ex);
|
|
||||||
this.Error("The step failed and an error occurred when attempting to determine whether to continue on error.");
|
|
||||||
this.Error(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (continueOnError)
|
|
||||||
{
|
|
||||||
Outcome = Result;
|
|
||||||
Result = TaskResult.Succeeded;
|
|
||||||
Trace.Info($"Updated step result (continue on error)");
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateGlobalStepsContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Error/Warning/etc methods are created as extension methods to simplify unit testing.
|
// The Error/Warning/etc methods are created as extension methods to simplify unit testing.
|
||||||
@@ -1126,6 +1085,7 @@ namespace GitHub.Runner.Worker
|
|||||||
context.Error(ex.Message);
|
context.Error(ex.Message);
|
||||||
context.Debug(ex.ToString());
|
context.Debug(ex.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not add a format string overload. See comment on ExecutionContext.Write().
|
// Do not add a format string overload. See comment on ExecutionContext.Write().
|
||||||
public static void Error(this IExecutionContext context, string message)
|
public static void Error(this IExecutionContext context, string message)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.DistributedTask.Expressions2;
|
using GitHub.DistributedTask.Expressions2;
|
||||||
@@ -11,6 +13,7 @@ using GitHub.DistributedTask.WebApi;
|
|||||||
using GitHub.Runner.Common;
|
using GitHub.Runner.Common;
|
||||||
using GitHub.Runner.Common.Util;
|
using GitHub.Runner.Common.Util;
|
||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
|
using GitHub.Runner.Worker;
|
||||||
using GitHub.Runner.Worker.Expressions;
|
using GitHub.Runner.Worker.Expressions;
|
||||||
using Pipelines = GitHub.DistributedTask.Pipelines;
|
using Pipelines = GitHub.DistributedTask.Pipelines;
|
||||||
|
|
||||||
@@ -83,7 +86,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
|
|
||||||
ExecutionContext.StepTelemetry.HasPreStep = Data.HasPre;
|
ExecutionContext.StepTelemetry.HasPreStep = Data.HasPre;
|
||||||
ExecutionContext.StepTelemetry.HasPostStep = Data.HasPost;
|
ExecutionContext.StepTelemetry.HasPostStep = Data.HasPost;
|
||||||
|
|
||||||
ExecutionContext.StepTelemetry.HasRunsStep = hasRunsStep;
|
ExecutionContext.StepTelemetry.HasRunsStep = hasRunsStep;
|
||||||
ExecutionContext.StepTelemetry.HasUsesStep = hasUsesStep;
|
ExecutionContext.StepTelemetry.HasUsesStep = hasUsesStep;
|
||||||
ExecutionContext.StepTelemetry.StepCount = steps.Count;
|
ExecutionContext.StepTelemetry.StepCount = steps.Count;
|
||||||
@@ -404,7 +407,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update context
|
// Update context
|
||||||
step.ExecutionContext.UpdateGlobalStepsContext();
|
SetStepsContext(step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,8 +452,6 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
SetStepConclusion(step, Common.Util.TaskResultUtil.MergeTaskResults(step.ExecutionContext.Result, step.ExecutionContext.CommandResult.Value));
|
SetStepConclusion(step, Common.Util.TaskResultUtil.MergeTaskResults(step.ExecutionContext.Result, step.ExecutionContext.CommandResult.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
step.ExecutionContext.ApplyContinueOnError(step.ContinueOnError);
|
|
||||||
|
|
||||||
Trace.Info($"Step result: {step.ExecutionContext.Result}");
|
Trace.Info($"Step result: {step.ExecutionContext.Result}");
|
||||||
step.ExecutionContext.Debug($"Finished: {step.DisplayName}");
|
step.ExecutionContext.Debug($"Finished: {step.DisplayName}");
|
||||||
step.ExecutionContext.PublishStepTelemetry();
|
step.ExecutionContext.PublishStepTelemetry();
|
||||||
@@ -459,7 +460,16 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
private void SetStepConclusion(IStep step, TaskResult result)
|
private void SetStepConclusion(IStep step, TaskResult result)
|
||||||
{
|
{
|
||||||
step.ExecutionContext.Result = result;
|
step.ExecutionContext.Result = result;
|
||||||
step.ExecutionContext.UpdateGlobalStepsContext();
|
SetStepsContext(step);
|
||||||
|
}
|
||||||
|
private void SetStepsContext(IStep step)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(step.ExecutionContext.ContextName) && !step.ExecutionContext.ContextName.StartsWith("__", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
// TODO: when we support continue on error, we may need to do logic here to change conclusion based on the continue on error result
|
||||||
|
step.ExecutionContext.Global.StepsContext.SetOutcome(step.ExecutionContext.ScopeName, step.ExecutionContext.ContextName, (step.ExecutionContext.Result ?? TaskResult.Succeeded).ToActionResult());
|
||||||
|
step.ExecutionContext.Global.StepsContext.SetConclusion(step.ExecutionContext.ScopeName, step.ExecutionContext.ContextName, (step.ExecutionContext.Result ?? TaskResult.Succeeded).ToActionResult());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.DistributedTask.Pipelines;
|
|
||||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
|
||||||
using GitHub.DistributedTask.WebApi;
|
using GitHub.DistributedTask.WebApi;
|
||||||
using GitHub.Runner.Common;
|
using GitHub.Runner.Common;
|
||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
@@ -114,17 +112,6 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
// Remove environment variable that may cause conflicts with the node within the runner.
|
// Remove environment variable that may cause conflicts with the node within the runner.
|
||||||
Environment.Remove("NODE_ICU_DATA"); // https://github.com/actions/runner/issues/795
|
Environment.Remove("NODE_ICU_DATA"); // https://github.com/actions/runner/issues/795
|
||||||
|
|
||||||
if (Data.NodeVersion == "node12" && (ExecutionContext.Global.Variables.GetBoolean(Constants.Runner.Features.Node12Warning) ?? false))
|
|
||||||
{
|
|
||||||
if (!ExecutionContext.JobContext.ContainsKey("Node12ActionsWarnings"))
|
|
||||||
{
|
|
||||||
ExecutionContext.JobContext["Node12ActionsWarnings"] = new ArrayContextData();
|
|
||||||
}
|
|
||||||
var repoAction = Action as RepositoryPathReference;
|
|
||||||
var actionDisplayName = new StringContextData(repoAction.Name ?? repoAction.Path); // local actions don't have a 'Name'
|
|
||||||
ExecutionContext.JobContext["Node12ActionsWarnings"].AssertArray("Node12ActionsWarnings").Add(actionDisplayName);
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var stdoutManager = new OutputManager(ExecutionContext, ActionCommandManager))
|
using (var stdoutManager = new OutputManager(ExecutionContext, ActionCommandManager))
|
||||||
using (var stderrManager = new OutputManager(ExecutionContext, ActionCommandManager))
|
using (var stderrManager = new OutputManager(ExecutionContext, ActionCommandManager))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,8 +153,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
string workingDirectory = null;
|
string workingDirectory = null;
|
||||||
if (!Inputs.TryGetValue("workingDirectory", out workingDirectory))
|
if (!Inputs.TryGetValue("workingDirectory", out workingDirectory))
|
||||||
{
|
{
|
||||||
// Don't use job level working directories for hooks
|
if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults))
|
||||||
if (IsActionStep && string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults))
|
|
||||||
{
|
{
|
||||||
if (runDefaults.TryGetValue("working-directory", out workingDirectory))
|
if (runDefaults.TryGetValue("working-directory", out workingDirectory))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using System.Net.Http;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
|
||||||
using GitHub.DistributedTask.WebApi;
|
using GitHub.DistributedTask.WebApi;
|
||||||
using GitHub.Runner.Common;
|
using GitHub.Runner.Common;
|
||||||
using GitHub.Runner.Common.Util;
|
using GitHub.Runner.Common.Util;
|
||||||
@@ -258,12 +257,6 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jobContext.JobContext.ContainsKey("Node12ActionsWarnings"))
|
|
||||||
{
|
|
||||||
var actions = string.Join(", ", jobContext.JobContext["Node12ActionsWarnings"].AssertArray("Node12ActionsWarnings").Select(action => action.ToString()));
|
|
||||||
jobContext.Warning(string.Format(Constants.Runner.Node12DetectedAfterEndOfLife, actions));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ShutdownQueue(throwOnFailure: true);
|
await ShutdownQueue(throwOnFailure: true);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -134,10 +133,8 @@ namespace GitHub.Runner.Worker
|
|||||||
// Test the condition again. The job was cancelled after the condition was originally evaluated.
|
// Test the condition again. The job was cancelled after the condition was originally evaluated.
|
||||||
jobCancelRegister = jobContext.CancellationToken.Register(() =>
|
jobCancelRegister = jobContext.CancellationToken.Register(() =>
|
||||||
{
|
{
|
||||||
// Mark job as Cancelled or Failed depending on HostContext shutdown token's cancellation
|
// Mark job as cancelled
|
||||||
jobContext.Result = HostContext.RunnerShutdownToken.IsCancellationRequested
|
jobContext.Result = TaskResult.Canceled;
|
||||||
? TaskResult.Failed
|
|
||||||
: TaskResult.Canceled;
|
|
||||||
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();
|
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();
|
||||||
|
|
||||||
step.ExecutionContext.Debug($"Re-evaluate condition on job cancellation for step: '{step.DisplayName}'.");
|
step.ExecutionContext.Debug($"Re-evaluate condition on job cancellation for step: '{step.DisplayName}'.");
|
||||||
@@ -175,10 +172,8 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
if (jobContext.Result != TaskResult.Canceled)
|
if (jobContext.Result != TaskResult.Canceled)
|
||||||
{
|
{
|
||||||
// Mark job as Cancelled or Failed depending on HostContext shutdown token's cancellation
|
// Mark job as cancelled
|
||||||
jobContext.Result = HostContext.RunnerShutdownToken.IsCancellationRequested
|
jobContext.Result = TaskResult.Canceled;
|
||||||
? TaskResult.Failed
|
|
||||||
: TaskResult.Canceled;
|
|
||||||
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();
|
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,8 +319,29 @@ namespace GitHub.Runner.Worker
|
|||||||
step.ExecutionContext.Result = TaskResultUtil.MergeTaskResults(step.ExecutionContext.Result, step.ExecutionContext.CommandResult.Value);
|
step.ExecutionContext.Result = TaskResultUtil.MergeTaskResults(step.ExecutionContext.Result, step.ExecutionContext.CommandResult.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
step.ExecutionContext.ApplyContinueOnError(step.ContinueOnError);
|
// Fixup the step result if ContinueOnError
|
||||||
|
if (step.ExecutionContext.Result == TaskResult.Failed)
|
||||||
|
{
|
||||||
|
var continueOnError = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
continueOnError = templateEvaluator.EvaluateStepContinueOnError(step.ContinueOnError, step.ExecutionContext.ExpressionValues, step.ExecutionContext.ExpressionFunctions);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Trace.Info("The step failed and an error occurred when attempting to determine whether to continue on error.");
|
||||||
|
Trace.Error(ex);
|
||||||
|
step.ExecutionContext.Error("The step failed and an error occurred when attempting to determine whether to continue on error.");
|
||||||
|
step.ExecutionContext.Error(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (continueOnError)
|
||||||
|
{
|
||||||
|
step.ExecutionContext.Outcome = step.ExecutionContext.Result;
|
||||||
|
step.ExecutionContext.Result = TaskResult.Succeeded;
|
||||||
|
Trace.Info($"Updated step result (continue on error)");
|
||||||
|
}
|
||||||
|
}
|
||||||
Trace.Info($"Step result: {step.ExecutionContext.Result}");
|
Trace.Info($"Step result: {step.ExecutionContext.Result}");
|
||||||
|
|
||||||
// Complete the step context
|
// Complete the step context
|
||||||
|
|||||||
@@ -129,7 +129,6 @@
|
|||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"env": "step-env",
|
"env": "step-env",
|
||||||
"continue-on-error": "boolean-steps-context",
|
|
||||||
"working-directory": "string-steps-context",
|
"working-directory": "string-steps-context",
|
||||||
"shell": {
|
"shell": {
|
||||||
"type": "non-empty-string",
|
"type": "non-empty-string",
|
||||||
@@ -148,7 +147,6 @@
|
|||||||
"type": "non-empty-string",
|
"type": "non-empty-string",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"continue-on-error": "boolean-steps-context",
|
|
||||||
"with": "step-with",
|
"with": "step-with",
|
||||||
"env": "step-env"
|
"env": "step-env"
|
||||||
}
|
}
|
||||||
@@ -203,20 +201,6 @@
|
|||||||
],
|
],
|
||||||
"string": {}
|
"string": {}
|
||||||
},
|
},
|
||||||
"boolean-steps-context": {
|
|
||||||
"context": [
|
|
||||||
"github",
|
|
||||||
"inputs",
|
|
||||||
"strategy",
|
|
||||||
"matrix",
|
|
||||||
"steps",
|
|
||||||
"job",
|
|
||||||
"runner",
|
|
||||||
"env",
|
|
||||||
"hashFiles(1,255)"
|
|
||||||
],
|
|
||||||
"boolean": {}
|
|
||||||
},
|
|
||||||
"step-env": {
|
"step-env": {
|
||||||
"context": [
|
"context": [
|
||||||
"github",
|
"github",
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ using System.Net.Http.Headers;
|
|||||||
using System.Net.Http.Formatting;
|
using System.Net.Http.Formatting;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.DistributedTask.Pipelines;
|
|
||||||
using GitHub.Services.Common;
|
using GitHub.Services.Common;
|
||||||
using GitHub.Services.WebApi;
|
using GitHub.Services.WebApi;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,5 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
public static class JobRequestMessageTypes
|
public static class JobRequestMessageTypes
|
||||||
{
|
{
|
||||||
public const String PipelineAgentJobRequest = "PipelineAgentJobRequest";
|
public const String PipelineAgentJobRequest = "PipelineAgentJobRequest";
|
||||||
public const String RunnerJobRequest = "RunnerJobRequest";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,24 +141,6 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
return ReplaceAgentAsync(poolId, agent.Id, agent, userState, cancellationToken);
|
return ReplaceAgentAsync(poolId, agent.Id, agent, userState, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Pipelines.AgentJobRequestMessage> GetJobMessageAsync(
|
|
||||||
string messageId,
|
|
||||||
object userState = null,
|
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
HttpMethod httpMethod = new HttpMethod("GET");
|
|
||||||
Guid locationId = new Guid("25adab70-1379-4186-be8e-b643061ebe3a");
|
|
||||||
object routeValues = new { messageId = messageId };
|
|
||||||
|
|
||||||
return SendAsync<Pipelines.AgentJobRequestMessage>(
|
|
||||||
httpMethod,
|
|
||||||
locationId,
|
|
||||||
routeValues: routeValues,
|
|
||||||
version: new ApiResourceVersion(1.0, 1),
|
|
||||||
userState: userState,
|
|
||||||
cancellationToken: cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Task<T> SendAsync<T>(
|
protected Task<T> SendAsync<T>(
|
||||||
HttpMethod method,
|
HttpMethod method,
|
||||||
Guid locationId,
|
Guid locationId,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ using GitHub.DistributedTask.WebApi;
|
|||||||
using GitHub.Runner.Worker;
|
using GitHub.Runner.Worker;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
|
||||||
using Pipelines = GitHub.DistributedTask.Pipelines;
|
using Pipelines = GitHub.DistributedTask.Pipelines;
|
||||||
|
|
||||||
namespace GitHub.Runner.Common.Tests.Worker
|
namespace GitHub.Runner.Common.Tests.Worker
|
||||||
@@ -91,63 +90,6 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", "Worker")]
|
|
||||||
public void ApplyContinueOnError_CheckResultAndOutcome()
|
|
||||||
{
|
|
||||||
using (TestHostContext hc = CreateTestContext())
|
|
||||||
{
|
|
||||||
|
|
||||||
// Arrange: Create a job request message.
|
|
||||||
TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference();
|
|
||||||
TimelineReference timeline = new TimelineReference();
|
|
||||||
Guid jobId = Guid.NewGuid();
|
|
||||||
string jobName = "some job name";
|
|
||||||
var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary<string, VariableValue>(), new List<MaskHint>(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List<Pipelines.ActionStep>(), null, null, null, null);
|
|
||||||
jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource()
|
|
||||||
{
|
|
||||||
Alias = Pipelines.PipelineConstants.SelfAlias,
|
|
||||||
Id = "github",
|
|
||||||
Version = "sha1"
|
|
||||||
});
|
|
||||||
jobRequest.ContextData["github"] = new Pipelines.ContextData.DictionaryContextData();
|
|
||||||
jobRequest.Variables["ACTIONS_STEP_DEBUG"] = "true";
|
|
||||||
|
|
||||||
// Arrange: Setup the paging logger.
|
|
||||||
var pagingLogger = new Mock<IPagingLogger>();
|
|
||||||
var jobServerQueue = new Mock<IJobServerQueue>();
|
|
||||||
jobServerQueue.Setup(x => x.QueueTimelineRecordUpdate(It.IsAny<Guid>(), It.IsAny<TimelineRecord>()));
|
|
||||||
jobServerQueue.Setup(x => x.QueueWebConsoleLine(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<long>())).Callback((Guid id, string msg, long? lineNumber) => { hc.GetTrace().Info(msg); });
|
|
||||||
|
|
||||||
hc.EnqueueInstance(pagingLogger.Object);
|
|
||||||
hc.SetSingleton(jobServerQueue.Object);
|
|
||||||
|
|
||||||
var ec = new Runner.Worker.ExecutionContext();
|
|
||||||
ec.Initialize(hc);
|
|
||||||
|
|
||||||
// Act.
|
|
||||||
ec.InitializeJob(jobRequest, CancellationToken.None);
|
|
||||||
|
|
||||||
foreach (var tc in new List<(TemplateToken token, TaskResult result, TaskResult? expectedResult, TaskResult? expectedOutcome)> {
|
|
||||||
(token: new BooleanToken(null, null, null, true), result: TaskResult.Failed, expectedResult: TaskResult.Succeeded, expectedOutcome: TaskResult.Failed),
|
|
||||||
(token: new BooleanToken(null, null, null, true), result: TaskResult.Succeeded, expectedResult: TaskResult.Succeeded, expectedOutcome: null),
|
|
||||||
(token: new BooleanToken(null, null, null, true), result: TaskResult.Canceled, expectedResult: TaskResult.Canceled, expectedOutcome: null),
|
|
||||||
(token: new BooleanToken(null, null, null, false), result: TaskResult.Failed, expectedResult: TaskResult.Failed, expectedOutcome: null),
|
|
||||||
(token: new BooleanToken(null, null, null, false), result: TaskResult.Succeeded, expectedResult: TaskResult.Succeeded, expectedOutcome: null),
|
|
||||||
(token: new BooleanToken(null, null, null, false), result: TaskResult.Canceled, expectedResult: TaskResult.Canceled, expectedOutcome: null),
|
|
||||||
})
|
|
||||||
{
|
|
||||||
ec.Result = tc.result;
|
|
||||||
ec.Outcome = null;
|
|
||||||
ec.ApplyContinueOnError(tc.token);
|
|
||||||
Assert.Equal(ec.Result, tc.expectedResult);
|
|
||||||
Assert.Equal(ec.Outcome, tc.expectedOutcome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", "Worker")]
|
[Trait("Category", "Worker")]
|
||||||
|
|||||||
@@ -622,40 +622,6 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
_stepContext.SetOutcome("", stepContext.Object.ContextName, (stepContext.Object.Outcome ?? stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult());
|
_stepContext.SetOutcome("", stepContext.Object.ContextName, (stepContext.Object.Outcome ?? stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult());
|
||||||
_stepContext.SetConclusion("", stepContext.Object.ContextName, (stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult());
|
_stepContext.SetConclusion("", stepContext.Object.ContextName, (stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult());
|
||||||
});
|
});
|
||||||
|
|
||||||
stepContext.Setup(x => x.UpdateGlobalStepsContext()).Callback(() =>
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(stepContext.Object.ContextName) && !stepContext.Object.ContextName.StartsWith("__", StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
stepContext.Object.Global.StepsContext.SetOutcome(stepContext.Object.ScopeName, stepContext.Object.ContextName, (stepContext.Object.Outcome ?? stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult());
|
|
||||||
stepContext.Object.Global.StepsContext.SetConclusion(stepContext.Object.ScopeName, stepContext.Object.ContextName, (stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
stepContext.Setup(x => x.ApplyContinueOnError(It.IsAny<TemplateToken>())).Callback((TemplateToken token) =>
|
|
||||||
{
|
|
||||||
if (stepContext.Object.Result != TaskResult.Failed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var continueOnError = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var templateEvaluator = stepContext.Object.ToPipelineTemplateEvaluator();
|
|
||||||
continueOnError = templateEvaluator.EvaluateStepContinueOnError(token, stepContext.Object.ExpressionValues, stepContext.Object.ExpressionFunctions);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
stepContext.Object.Error("The step failed and an error occurred when attempting to determine whether to continue on error.");
|
|
||||||
stepContext.Object.Error(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (continueOnError)
|
|
||||||
{
|
|
||||||
stepContext.Object.Outcome = stepContext.Object.Result;
|
|
||||||
stepContext.Object.Result = TaskResult.Succeeded;
|
|
||||||
}
|
|
||||||
stepContext.Object.UpdateGlobalStepsContext();
|
|
||||||
});
|
|
||||||
var trace = hc.GetTrace();
|
var trace = hc.GetTrace();
|
||||||
stepContext.Setup(x => x.Write(It.IsAny<string>(), It.IsAny<string>())).Callback((string tag, string message) => { trace.Info($"[{tag}]{message}"); });
|
stepContext.Setup(x => x.Write(It.IsAny<string>(), It.IsAny<string>())).Callback((string tag, string message) => { trace.Info($"[{tag}]{message}"); });
|
||||||
stepContext.Object.Result = result;
|
stepContext.Object.Result = result;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.289.2
|
2.289.3
|
||||||
|
|||||||
Reference in New Issue
Block a user