From 95e2158dc6e1d8bdc10112a66c5353c5acdff687 Mon Sep 17 00:00:00 2001 From: Chris Gavin Date: Tue, 3 Nov 2020 19:39:17 +0000 Subject: [PATCH] Add an environment variable to indicate which repository the currently running Action came from. (#585) * add `workflow_dispatch` * Add an environment variable to indicate which repository the currently running Action came from. * Expose the Action ref as well. * Move setting `github.action_repository` and `github.action_ref` to `ActionRunner.cs`. * Don't set `action_repository` and `action_ref` for local Actions. Co-authored-by: Tingluo Huang --- src/Runner.Worker/ActionRunner.cs | 8 ++++++++ src/Runner.Worker/GitHubContext.cs | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index d9387286a..f2962c17f 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -135,6 +135,14 @@ namespace GitHub.Runner.Worker ExecutionContext.SetGitHubContext("event_path", workflowFile); } + // Set GITHUB_ACTION_REPOSITORY if this Action is from a repository + if (Action.Reference is Pipelines.RepositoryPathReference repoPathReferenceAction && + !string.Equals(repoPathReferenceAction.RepositoryType, Pipelines.PipelineConstants.SelfAlias, StringComparison.OrdinalIgnoreCase)) + { + ExecutionContext.SetGitHubContext("action_repository", repoPathReferenceAction.Name); + ExecutionContext.SetGitHubContext("action_ref", repoPathReferenceAction.Ref); + } + // Setup container stephost for running inside the container. if (ExecutionContext.Global.Container != null) { diff --git a/src/Runner.Worker/GitHubContext.cs b/src/Runner.Worker/GitHubContext.cs index 741545c89..cd22773a6 100644 --- a/src/Runner.Worker/GitHubContext.cs +++ b/src/Runner.Worker/GitHubContext.cs @@ -10,6 +10,8 @@ namespace GitHub.Runner.Worker { "action", "action_path", + "action_ref", + "action_repository", "actor", "api_url", "base_ref", @@ -55,4 +57,4 @@ namespace GitHub.Runner.Worker return copy; } } -} \ No newline at end of file +}