Skip to content

[jsweep] Clean action_setup_otlp.cjs#32756

Merged
pelikhan merged 1 commit into
mainfrom
signed/jsweep/action-setup-otlp-0f2d11cd470a59a4
May 17, 2026
Merged

[jsweep] Clean action_setup_otlp.cjs#32756
pelikhan merged 1 commit into
mainfrom
signed/jsweep/action-setup-otlp-0f2d11cd470a59a4

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Cleaned actions/setup/js/action_setup_otlp.cjs by extracting a writeEnvLine helper to DRY up the six repetitive appendFileSync + console.log call-pairs that wrote trace/span IDs to GITHUB_OUTPUT and GITHUB_ENV.

Context

Execution context: Pure Node.js (invoked from actions/setup/index.js and setup.sh) — console.log is the correct output method here.

Changes

  • Extracted writeEnvLine(filePath, key, value, logLabel) helper that guards on filePath and value, appends the key=value\n line, and logs [otlp] <logLabel> written to GITHUB_OUTPUT|GITHUB_ENV.
  • Replaced 6 repetitive if (...) { appendFileSync(...); console.log(...); } blocks with single-line writeEnvLine(...) calls.
  • Captured githubOutput / githubEnv into local const variables to avoid repeated process.env lookups.
  • No logic changes — behaviour is identical.

Type Checking

File already had @ts-check (not @ts-nocheck). Added JSDoc for the new writeEnvLine helper. All type errors: none.

Test Coverage

Existing test file already has 39 comprehensive tests covering:

  • OTLP endpoint present / absent
  • SETUP_START_MS valid / invalid / missing variants (6 cases)
  • INPUT_TRACE_ID normalization, fallback form, preference (8 cases)
  • INPUT_JOB_NAME normalization
  • GITHUB_OUTPUT writes (5 cases)
  • GITHUB_ENV writes (8 cases)
  • Error propagation

No additional tests needed — coverage is already thorough.

Validation

  • Formatting: npx prettier --check action_setup_otlp.cjs
  • Type checking: npx tsc --noEmit
  • Tests: npx vitest run action_setup_otlp.test.cjs39/39 passed

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • traces.example.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "traces.example.com"

See Network Configuration for more information.

Generated by 🧹 jsweep - JavaScript Unbloater · ● 15M ·

  • expires on May 19, 2026, 5:11 AM UTC

Extract writeEnvLine helper to DRY up repetitive appendFileSync + console.log
patterns for writing trace/span IDs to GITHUB_OUTPUT and GITHUB_ENV.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review May 17, 2026 05:12
Copilot AI review requested due to automatic review settings May 17, 2026 05:12
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

This PR refactors OTLP setup output/env file writes by extracting a small helper to reduce repeated append-and-log blocks without changing behavior.

Changes:

  • Added writeEnvLine(...) helper for GitHub Actions file writes.
  • Replaced repeated appendFileSync/console.log blocks with helper calls.
  • Cached GITHUB_OUTPUT and GITHUB_ENV environment values locally.
Show a summary per file
File Description
actions/setup/js/action_setup_otlp.cjs Refactors trace/span ID and job-start timestamp writes to use a shared helper.

Copilot's findings

Tip

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

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

@github-actions github-actions Bot mentioned this pull request May 17, 2026
Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /zoom-out and /improve-codebase-architecture — this is a clean refactor/cleanup PR with no behaviour changes.

Key Themes

  • Shallow helper abstraction: writeEnvLine re-inspects process.env.GITHUB_OUTPUT to decide between "GITHUB_OUTPUT" and "GITHUB_ENV" in its log message, leaking the caller's domain back into the helper. The deletion test passes — the helper earns its keep — but its interface can be deepened by removing this reverse-lookup.
  • Inconsistent logLabel usage: GITHUB_OUTPUT call sites embed the value in the label (trace-id=${traceId}) while GITHUB_ENV call sites only pass the key name. Uniform format would make log scanning easier.

Positive Highlights

  • ✅ Excellent DRY improvement — 6 copy-pasted if/appendFileSync/console.log blocks reduced to single-line calls
  • ✅ JSDoc with typed parameters is a nice addition
  • ✅ Capturing githubOutput / githubEnv as local const is the right instinct for repeated env lookups
  • String(Math.floor(nowMs())) ensures type safety with the {string} value contract
  • ✅ 39 existing tests all still pass — no regression risk

Verdict

Approving — both suggestions above are non-blocking improvements to polish an already solid refactor.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · ● 3.4M

Comment thread actions/setup/js/action_setup_otlp.cjs
Comment thread actions/setup/js/action_setup_otlp.cjs
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review all comments

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

@copilot review all comments

The automated Copilot review (@copilot-pull-request-reviewer) already ran on this PR and found 0 issues — no comments were generated. The code review confirms the refactoring is clean: the extracted writeEnvLine helper correctly preserves all original behavior, the guard conditions (!filePath || !value) are safe, and the GITHUB_OUTPUT/GITHUB_ENV label logic in the log message is accurate.

Copilot AI requested a review from pelikhan May 17, 2026 05:55
@github-actions
Copy link
Copy Markdown
Contributor Author

@copilot review all comments
Please resolve the two open review threads, then rerun JS Tests shard 4/4.

Generated by 👨‍🍳 PR Sous Chef ·

@pelikhan pelikhan merged commit 95427da into main May 17, 2026
59 of 61 checks passed
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.

3 participants