-
Notifications
You must be signed in to change notification settings - Fork 989
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
Add an environment variable to indicate which repository the currently running Action came from. #585
Add an environment variable to indicate which repository the currently running Action came from. #585
Conversation
src/Runner.Worker/StepsRunner.cs
Outdated
// Set GITHUB_ACTION_REPOSITORY if this Action is from a repository | ||
if (actionStep.Action.Reference is Pipelines.RepositoryPathReference repositoryReference) | ||
{ | ||
step.ExecutionContext.SetGitHubContext("action_repository", repositoryReference.Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice the RepositoryPathReference
also has a Ref
field. Would it be ok to also make that available, perhaps as a action_ref
var? That would be very useful for code scanning as we've been wanting to include that data in our status reports, but couldn't work out how to get it. Doesn't have to be in this PR if the extra change would slow it down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure. I've added that field as well.
…y running Action came from.
@joshhale Do you know what the best way is to get this reviewed? |
@TingluoHuang do you have time to review this PR? |
@@ -9,6 +9,8 @@ public sealed class GitHubContext : DictionaryContextData, IEnvironmentContextDa | |||
private readonly HashSet<string> _contextEnvWhitelist = new HashSet<string>(StringComparer.OrdinalIgnoreCase) | |||
{ | |||
"action", | |||
"action_ref", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrispat any objection to adding these 2 new environment variables?
…ctionRunner.cs`.
src/Runner.Worker/ActionRunner.cs
Outdated
@@ -135,6 +135,13 @@ public async Task RunAsync() | |||
ExecutionContext.SetGitHubContext("event_path", workflowFile); | |||
} | |||
|
|||
// Set GITHUB_ACTION_REPOSITORY if this Action is from a repository | |||
if (Action.Reference is Pipelines.RepositoryPathReference repoPathReferenceAction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the value would be if i use the action from the checkout repo.
ex:
- use: ./localaction
with:
foo: bar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like currently they are both set to the empty string. Do you think that's reasonable or should they just not be set at all in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just not set.
if (Action.Reference is Pipelines.RepositoryPathReference repoPathReferenceAction &&
!string.Equals(repoPathReferenceAction.RepositoryType, Pipelines.PipelineConstants.SelfAlias, StringComparison.OrdinalIgnoreCase))
{
// set action_repo/action_ref
}
It looks like retargeting from |
it fine to include that commit. :) |
…y running Action came from. (actions#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 <tingluohuang@github.com>
…y 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 <tingluohuang@github.com>
For certain types of Actions, it can be useful for the Action to know what repository it came from. For example the github/codeql-action needs to access binary files stored in GitHub Releases artifacts on its own repository.
Currently if this Action is mirrored on GitHub Enterprise Server under a different name it will be unable to locate its release artifacts as it always expects them to be in the
github/codeql-action
repository.This change adds a
github.action_repository
context variable (and correspondingGITHUB_ACTION_REPOSITORY
environment variable) that is set to the NWO of the repository which the Action came from. It is not set for script or Container Registry Actions. It is set to the empty string if the Action reference is relative to the checkout repository.This allows Actions to be aware of their own source repository and therefore reach back out to them to do things like downloading extra artifacts.
Apologies if I've missed an existing way of getting this information, but I couldn't find one other than looking at the path which the Action is checked out to; I wasn't sure that this was a stable interface to rely on.