-
Notifications
You must be signed in to change notification settings - Fork 509
[code-simplifier] Simplify action_setup_otlp.cjs: dedupe conditional writeEnvLine calls #52622
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
Closed
github-actions
wants to merge
2
commits into
main
from
code-simplifier/otlp-setup-dedup-e2426191b330fb97
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,17 +171,30 @@ async function run() { | |
| const githubOutput = process.env.GITHUB_OUTPUT; | ||
| const githubEnv = process.env.GITHUB_ENV; | ||
|
|
||
| /** | ||
| * Write a key=value line to filePath only if isValid(value) holds. | ||
| * @param {string | undefined} filePath | ||
| * @param {string} key | ||
| * @param {string} value | ||
| * @param {string} logLabel - Label used in the confirmation log message | ||
| * @param {string} fileLabel | ||
| * @param {(value: string) => boolean} isValid | ||
| */ | ||
| const writeIfValid = (filePath, key, value, logLabel, fileLabel, isValid) => { | ||
| if (isValid(value)) writeEnvLine(filePath, key, value, logLabel, fileLabel); | ||
| }; | ||
|
|
||
| // Always expose trace ID as a step output for cross-job correlation, even | ||
| // when OTLP is not configured. This ensures needs.*.outputs.setup-trace-id | ||
| // is populated for downstream jobs regardless of observability configuration. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L179-189: yagni: 11-line helper (6 params + 8-line JSDoc) replacing 5 near-identical one-line |
||
| if (isValidTraceId(traceId)) writeEnvLine(githubOutput, "trace-id", traceId, `trace-id=${traceId}`, "GITHUB_OUTPUT"); | ||
| if (isValidSpanId(spanId)) writeEnvLine(githubOutput, "span-id", spanId, `span-id=${spanId}`, "GITHUB_OUTPUT"); | ||
| if (isValidSpanId(parentSpanId)) writeEnvLine(githubOutput, "parent-span-id", parentSpanId, `parent-span-id=${parentSpanId}`, "GITHUB_OUTPUT"); | ||
| writeIfValid(githubOutput, "trace-id", traceId, `trace-id=${traceId}`, "GITHUB_OUTPUT", isValidTraceId); | ||
| writeIfValid(githubOutput, "span-id", spanId, `span-id=${spanId}`, "GITHUB_OUTPUT", isValidSpanId); | ||
| writeIfValid(githubOutput, "parent-span-id", parentSpanId, `parent-span-id=${parentSpanId}`, "GITHUB_OUTPUT", isValidSpanId); | ||
|
|
||
| // Always propagate trace/span context to subsequent steps in this job so | ||
| // that the conclusion span can find the same trace ID. | ||
| if (isValidTraceId(traceId)) writeEnvLine(githubEnv, "GITHUB_AW_OTEL_TRACE_ID", traceId, "GITHUB_AW_OTEL_TRACE_ID", "GITHUB_ENV"); | ||
| if (isValidSpanId(spanId)) writeEnvLine(githubEnv, "GITHUB_AW_OTEL_PARENT_SPAN_ID", spanId, "GITHUB_AW_OTEL_PARENT_SPAN_ID", "GITHUB_ENV"); | ||
| writeIfValid(githubEnv, "GITHUB_AW_OTEL_TRACE_ID", traceId, "GITHUB_AW_OTEL_TRACE_ID", "GITHUB_ENV", isValidTraceId); | ||
| writeIfValid(githubEnv, "GITHUB_AW_OTEL_PARENT_SPAN_ID", spanId, "GITHUB_AW_OTEL_PARENT_SPAN_ID", "GITHUB_ENV", isValidSpanId); | ||
| // Propagate setup-end timestamp so the conclusion span can measure actual | ||
| // job execution duration (setup-end → conclusion-start). | ||
| if (githubEnv) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[/codebase-design] The JSDoc types
valueasstring, but environment variables (process.env.*) arestring | undefined. The helper already passesvaluestraight towriteEnvLineafter the guard, so the practical risk is low — but the type annotation is misleading.💡 Suggested fix
Change the
@paramannotation:This makes it clear to future readers why the
isValidguard is necessary.@copilot please address this.