Skip to content

[code-simplifier] refactor: extract getActionInput() helper for hyphen/underscore input normalization (#24823)#24836

Merged
pelikhan merged 1 commit intomainfrom
simplify/action-input-utils-helper-849a738082de94eb
Apr 6, 2026
Merged

[code-simplifier] refactor: extract getActionInput() helper for hyphen/underscore input normalization (#24823)#24836
pelikhan merged 1 commit intomainfrom
simplify/action-input-utils-helper-849a738082de94eb

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 6, 2026

The two-key lookup pattern for normalizing GitHub Actions inputs (handling both INPUT_X and INPUT_X-HYPHEN forms) was introduced in PR #24823 and duplicated across three files: index.js, action_setup_otlp.cjs, and action_conclusion_otlp.cjs.

Files Simplified

  • actions/setup/js/action_input_utils.cjs (new) — shared getActionInput(name) helper that checks both underscore and hyphen env var forms and trims the result
  • actions/setup/js/action_input_utils.test.cjs (new) — unit tests for the helper
  • actions/setup/js/action_setup_otlp.cjs — replaced two verbose inline normalization blocks with getActionInput("TRACE_ID") and getActionInput("JOB_NAME")
  • actions/setup/js/action_conclusion_otlp.cjs — replaced inline normalization block with getActionInput("JOB_NAME")
  • actions/setup/index.js — replaced three separate multi-line normalization blocks with three getActionInput() calls

Improvements Made

  1. Reduced duplication — the normalization logic and its explanation now live in one place (action_input_utils.cjs) instead of being repeated at every call site
  2. Removed repetitive comments — each caller no longer needs to explain the underscore/hyphen ambiguity
  3. Easier to extend — adding a new input with the same normalization is now a one-liner

Changes Based On

Recent changes from:

Testing

  • ✅ New unit tests for getActionInput (5 tests, all pass)
  • ✅ Existing tests for action_conclusion_otlp.cjs pass (21 tests)
  • ✅ Existing tests for action_setup_otlp.cjs pass (20 tests, 1 pre-existing timing flake unrelated to this change)
  • ✅ Linting passes (make lint-cjs)
  • ✅ No functional changes — behavior is identical

Review Focus

Please verify:

  • Functionality is preserved (all three callers resolve inputs identically to before)
  • The getActionInput helper is a clean, well-named abstraction
  • No unintended side effects from the .trim() now being applied uniformly (previously index.js did not trim — whitespace in input values would be unusual but .trim() aligns with GitHub Actions conventions)

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

Generated by Code Simplifier · ● 2.4M ·

  • expires on Apr 7, 2026, 6:22 AM UTC

… normalization

The two-key lookup pattern for normalizing GitHub Actions inputs (handling both
INPUT_X and INPUT_X-HYPHEN forms) was introduced in PR #24823 and repeated in
three places: index.js, action_setup_otlp.cjs, and action_conclusion_otlp.cjs.

Extract a getActionInput(name) helper in action_input_utils.cjs that:
- Checks both the underscore (standard) and hyphen (some runner versions) forms
- Trims whitespace from the result (aligning with GitHub Actions conventions)
- Documents the rationale once, rather than repeating it at each call site

This reduces code duplication, removes repetitive comments, and makes it easy
to add new inputs with the same normalization in the future.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot mentioned this pull request Apr 6, 2026
@pelikhan pelikhan marked this pull request as ready for review April 6, 2026 10:51
Copilot AI review requested due to automatic review settings April 6, 2026 10:51
@pelikhan pelikhan merged commit d36f392 into main Apr 6, 2026
52 checks passed
@pelikhan pelikhan deleted the simplify/action-input-utils-helper-849a738082de94eb branch April 6, 2026 10:51
Copy link
Copy Markdown
Contributor

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

Refactors duplicated GitHub Actions input env-var normalization (underscore vs hyphen forms) into a shared helper to keep behavior consistent across setup/conclusion OTLP scripts and the setup action entrypoint.

Changes:

  • Added shared getActionInput(name) helper for underscore/hyphen lookup with trimming.
  • Added unit tests covering lookup precedence and trimming behavior.
  • Replaced duplicated inline normalization logic in index.js, action_setup_otlp.cjs, and action_conclusion_otlp.cjs with helper calls.
Show a summary per file
File Description
actions/setup/js/action_input_utils.cjs New helper to read INPUT_* values across underscore/hyphen variants.
actions/setup/js/action_input_utils.test.cjs New vitest unit coverage for helper behavior (fallback, precedence, trim).
actions/setup/js/action_setup_otlp.cjs Uses helper for TRACE_ID and JOB_NAME normalization before span export/env propagation.
actions/setup/js/action_conclusion_otlp.cjs Uses helper for JOB_NAME normalization when constructing conclusion span name.
actions/setup/index.js Uses helper for three inputs and centralizes the runner hyphen-variant explanation.

Copilot's findings

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 1


/**
* Read a GitHub Actions input value, handling both the standard underscore form
* (INPUT_<NAME>) and the hyphen form (INPUT_<NAM-E>) preserved by some runner versions.
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

Doc comment uses the placeholder INPUT_<NAM-E>, which looks like a typo and is confusing (it suggests a character was dropped). Consider rewording to something like INPUT_<NAME-WITH-HYPHENS> or giving a concrete example (e.g. INPUT_JOB-NAME) so the underscore vs hyphen forms are unambiguous.

Suggested change
* (INPUT_<NAME>) and the hyphen form (INPUT_<NAM-E>) preserved by some runner versions.
* (INPUT_<NAME>) and the hyphen form (INPUT_<NAME-WITH-HYPHENS>) preserved by some runner versions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants