Skip to content

Add an environment variable to indicate which repository the currently running Action came from. - #585

Merged
TingluoHuang merged 6 commits into
actions:mainfrom
chrisgavin:action-repository-environment-variable
Nov 3, 2020
Merged

Add an environment variable to indicate which repository the currently running Action came from.#585
TingluoHuang merged 6 commits into
actions:mainfrom
chrisgavin:action-repository-environment-variable

Conversation

@chrisgavin

Copy link
Copy Markdown
Contributor

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 corresponding GITHUB_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.

Comment thread 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);

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Contributor Author

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.

@chrisgavin

Copy link
Copy Markdown
Contributor Author

@joshhale Do you know what the best way is to get this reviewed?

@joshhale

joshhale commented Aug 4, 2020

Copy link
Copy Markdown

@TingluoHuang do you have time to review this PR?

Comment thread src/Runner.Worker/StepsRunner.cs Outdated
private readonly HashSet<string> _contextEnvWhitelist = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"action",
"action_ref",

Copy link
Copy Markdown
Member

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?

Comment thread src/Runner.Worker/ActionRunner.cs Outdated
}

// Set GITHUB_ACTION_REPOSITORY if this Action is from a repository
if (Action.Reference is Pipelines.RepositoryPathReference repoPathReferenceAction)

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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?

Copy link
Copy Markdown
Member

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
}

@chrisgavin
chrisgavin changed the base branch from master to main November 3, 2020 16:18
@chrisgavin

Copy link
Copy Markdown
Contributor Author

It looks like retargeting from master to main has brought in the commit a711bd9 (it's on master but not on main). Would you like me to rebase to take this commit out?

@TingluoHuang

Copy link
Copy Markdown
Member

@chrisgavin

It looks like retargeting from master to main has brought in the commit a711bd9 (it's on master but not on main). Would you like me to rebase to take this commit out?

it fine to include that commit. :)

@TingluoHuang
TingluoHuang merged commit 95e2158 into actions:main Nov 3, 2020
AdamOlech pushed a commit to antmicro/runner that referenced this pull request Jan 28, 2021
…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>
TingluoHuang added a commit that referenced this pull request Apr 21, 2021
…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>
ckoryom added a commit to ckoryom/podman-actions-runner that referenced this pull request Jul 11, 2026
…, DinD, GitHub App auth)

- Multi-arch (amd64/arm64) Dockerfile based on Ubuntu 24.04 LTS, running the
  official actions/runner with an internal Docker-in-Docker daemon.
- entrypoint.sh + scripts/generate-installation-token.sh +
  scripts/register-and-run.sh: mint a GitHub App installation token and a
  fresh runner registration token on every start/stop (repo/org/enterprise
  scope), configure the runner as --ephemeral, run one job, then deregister
  via a trap on SIGTERM/SIGINT/EXIT so nothing ever shows up "offline".
- CI/CD: hadolint + shellcheck + build smoke-test on PR; multi-arch
  build/publish to GHCR with Trivy scan gate, cosign keyless signing, SBOM
  and provenance attestation on push/tag; CodeQL and OpenSSF Scorecard for
  trust badges; Dependabot for base image and Actions version bumps.
- docs/github-app-setup.md walks through creating/installing the App.
- README.md, SECURITY.md, CONTRIBUTING.md, CODE_OF_CONDUCT.md, MIT LICENSE.

Note: an Alpine-based variant was evaluated and rejected — the official
actions/runner release binaries fail at ./config.sh on musl libc even with
gcompat installed (known upstream limitation, actions/runner#585), so
Ubuntu 24.04 LTS is used as the officially supported platform.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants