Skip to content

fix: pass github-token input to APM subprocess as GITHUB_TOKEN#15

Merged
danielmeppiel merged 1 commit intomainfrom
fix/github-token-passthrough
Mar 19, 2026
Merged

fix: pass github-token input to APM subprocess as GITHUB_TOKEN#15
danielmeppiel merged 1 commit intomainfrom
fix/github-token-passthrough

Conversation

@danielmeppiel
Copy link
Collaborator

Problem

The action declares a github-token input (defaults to ${{ github.token }}) but never reads it or exports it to the subprocess environment. GitHub Actions does not auto-export input values as environment variables, so APM runs unauthenticated.

Impact:

  • Private repo dependencies fail silently (no GITHUB_TOKEN in subprocess)
  • GitHub API rate limits hit the unauthenticated ceiling (60 req/hr vs 5,000/hr)
  • Users who set github-token expect it to work — it doesn't

Found during microsoft/apm#356 which fixed APM itself to be resilient to missing tokens, but noted this action-side bug needed a separate fix.

Fix

Read the github-token input with core.getInput(), mask it with core.setSecret(), and set process.env.GITHUB_TOKEN before any APM subprocess calls. Since runApm() passes { ...process.env } to child processes, the token propagates automatically.

const githubToken = core.getInput('github-token');
if (githubToken) {
  core.setSecret(githubToken);
  process.env.GITHUB_TOKEN = githubToken;
}

Tests

  • passes github-token input as GITHUB_TOKEN env var — verifies token is set in env and masked
  • does not set GITHUB_TOKEN when github-token input is empty — verifies no-op when empty

All 44 tests pass.

The action declares a github-token input (defaulting to github.token)
but never reads it or exports it to the subprocess environment. GitHub
Actions does not auto-export input values as env vars, so APM runs
unauthenticated — hitting rate limits (60/hr) and failing on private
repo dependencies.

Fix: read the input with core.getInput, mask it with core.setSecret,
and set process.env.GITHUB_TOKEN before any APM subprocess calls.

Ref: microsoft/apm#356

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 00:25
@danielmeppiel danielmeppiel merged commit 7907fb1 into main Mar 19, 2026
13 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the action’s github-token input not being propagated to APM subprocesses by exporting it as GITHUB_TOKEN (and masking it) before any APM CLI invocations, ensuring authenticated GitHub API/dependency access.

Changes:

  • Read github-token, mask it via core.setSecret(), and set process.env.GITHUB_TOKEN for subprocess inheritance.
  • Add unit tests validating GITHUB_TOKEN propagation and no-op behavior when the input is empty.
  • Regenerate dist/index.js to include the runtime changes.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/runner.ts Exports github-token input to process.env.GITHUB_TOKEN and masks it before running APM.
src/__tests__/runner.test.ts Adds coverage for token propagation/masking and empty-input behavior.
dist/index.js Updates bundled output to reflect the source changes (ncc build artifact).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const githubToken = core.getInput('github-token');
if (githubToken) {
core.setSecret(githubToken);
process.env.GITHUB_TOKEN = githubToken;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in #16. Changed = to ??= so an existing GITHUB_TOKEN (e.g., a PAT from job-level env:) is preserved. Added a test for the non-clobber case.

danielmeppiel added a commit that referenced this pull request Mar 19, 2026
Use nullish-coalescing assignment (??=) so a GITHUB_TOKEN already
present in the environment (e.g., a PAT set via job-level env:) is
not clobbered by the action's default github.token input.

Addresses review feedback on #15.

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.

2 participants