Skip to content

refactor: replace execSync with @actions/exec.getExecOutput#318

Open
amondnet wants to merge 9 commits intomasterfrom
amondnet/best-countess
Open

refactor: replace execSync with @actions/exec.getExecOutput#318
amondnet wants to merge 9 commits intomasterfrom
amondnet/best-countess

Conversation

@amondnet
Copy link
Copy Markdown
Owner

@amondnet amondnet commented Mar 29, 2026

Summary

  • Replace execSync from node:child_process in getGitCommitMessage() with @actions/exec.getExecOutput()
  • Remove node:child_process dependency from production code
  • All 117 tests pass, no behavior change

Test plan

  • All existing tests pass (pnpm test → 117 passed)
  • No child_process imports in src/ (verified with grep)
  • Build succeeds (pnpm run build)
  • Lint passes (0 errors)

Closes #317


Summary by cubic

Replaced execSync with @actions/exec.getExecOutput to read the latest git commit message and removed node:child_process from production code. Behavior is unchanged; errors now include stderr/exit codes, tests cover error paths, and the build uses @vercel/ncc with --transpile-only; rebuilt dist/ and addresses #317.

  • Refactors
    • Made getGitCommitMessage() async via getExecOutput with { silent: true, ignoreReturnCode: true }, explicit exitCode checks, and stderr in errors; awaited in getDeploymentContext().
    • Updated tests to mock getExecOutput and cover thrown and non-zero exit cases; added track docs under .please/docs/tracks/active/use-actions-exec-20260329/.
    • Updated the build script to pass --transpile-only to @vercel/ncc to resolve TypeScript compatibility.

Written for commit 156631e. Summary will update on new commits.

Verification Checklist

Automated Tests

  • All existing tests pass (pnpm test)
  • No node:child_process imports in src/index.ts

Observable Outcomes

  • Running grep -r 'child_process' src/ returns no matches in production code
  • Running pnpm test shows all tests passing
  • Running pnpm run build succeeds without errors

Acceptance Criteria

  • SC-1: No node:child_process imports in production source
  • SC-2: All existing tests pass
  • SC-3: getGitCommitMessage() produces identical output
  • SC-4: Error handling preserves same error message format

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 29, 2026

Deploy preview for team-scope-test ready!

Project:team-scope-test
Status: ✅  Deploy successful!
Preview URL:https://team-scope-test-8l6lnz1jx-dietfriends.vercel.app
Latest Commit:156631e

Deployed with vercel-action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 29, 2026

Deploy preview for zeit-now-deployment-action-example-angular ready!

Project:zeit-now-deployment-action-example-angular
Status: ✅  Deploy successful!
Preview URL:https://zeit-now-deployment-action-example-angular-dcrwj2atk.vercel.app
Latest Commit:d23b16c
Alias:https://staging.angular.vercel-action.amond.dev
Alias:https://pr-318.angular.vercel-action.amond.dev

Deployed with vercel-action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 29, 2026

Deploy preview for express-basic-auth ready!

Project:express-basic-auth
Status: ✅  Deploy successful!
Preview URL:https://express-basic-auth-a9jm9wu6u-minsu-lees-projects-b1e388b7.vercel.app
Latest Commit:d23b16c

Deployed with vercel-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the use of node:child_process's execSync with @actions/exec's getExecOutput in src/index.ts to unify command execution. This change involves converting getGitCommitMessage to an asynchronous function and updating its callers. Feedback suggests improving test coverage by adding a test case for the error handling path in getGitCommitMessage.

@amondnet amondnet marked this pull request as ready for review March 29, 2026 08:22
Copilot AI review requested due to automatic review settings March 29, 2026 08:22
@amondnet amondnet mentioned this pull request Mar 29, 2026
4 tasks
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

Requires human review: This is a code refactor that changes a synchronous core utility function to an asynchronous one, which the instructions define as high-impact and requiring human review.

Architecture diagram
sequenceDiagram
    participant Main as Action Main Loop
    participant Context as getDeploymentContext()
    participant GitMsg as getGitCommitMessage()
    participant Exec as @actions/exec (Toolkit)
    participant Git as Git CLI

    Main->>Context: Initialize deployment context
    
    Note over Context,GitMsg: Control flow is now asynchronous
    Context->>GitMsg: CHANGED: await getGitCommitMessage()
    
    GitMsg->>Exec: NEW: getExecOutput("git", ["log", "-1", ...])
    
    rect rgb(240, 240, 240)
        Note right of Exec: Replaces node:child_process.execSync
        Exec->>Git: Spawn git process
        Git-->>Exec: stdout: commit message
    end

    alt Execution Success
        Exec-->>GitMsg: { stdout, exitCode: 0 }
        GitMsg-->>Context: Return trimmed stdout string
    else Execution Failure
        Exec-->>GitMsg: Throw Error or non-zero exitCode
        Note over GitMsg: Catch error and format string
        GitMsg-->>Context: Return "Unknown (error message)"
    end

    Context-->>Main: Return DeploymentContext object
Loading

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Auto-approved: Safe refactor replacing node:child_process with @actions/exec. All call sites were correctly updated to async, and existing tests were updated to reflect the mock changes.

Copy link
Copy Markdown

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 the Action’s git commit message retrieval to use the GitHub Actions toolkit exec utilities instead of Node’s child_process, aligning command execution patterns across the codebase and removing execSync usage.

Changes:

  • Replaced execSync('git log ...') with async @actions/exec.getExecOutput() in getGitCommitMessage() and awaited it in getDeploymentContext().
  • Updated integration tests to mock @actions/exec.getExecOutput() and removed the node:child_process mock.
  • Added/registered a .please track (spec/plan/metadata) documenting the work.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/index.ts Switches git commit message collection to getExecOutput() and makes it async.
src/tests/index.test.ts Updates mocks to support getExecOutput() instead of execSync.
dist/index.js Rebuild output reflecting the new exec approach and removal of node:child_process.
.please/docs/tracks/index.md Registers the new refactor track in the active tracks list.
.please/docs/tracks/active/use-actions-exec-20260329/spec.md Adds track specification for the refactor.
.please/docs/tracks/active/use-actions-exec-20260329/plan.md Adds implementation plan and verification notes for the refactor.
.please/docs/tracks/active/use-actions-exec-20260329/metadata.json Adds track metadata (status, timestamps, issue link).

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

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: This is a code refactor that converts a core function from sync to async and modifies error handling logic. Per instructions, refactors and logic changes require human review.

amondnet and others added 9 commits March 29, 2026 19:21
Replace node:child_process execSync in getGitCommitMessage() with
@actions/exec getExecOutput for consistent command execution across
the codebase. No behavior change.
…ling

- Use ignoreReturnCode: true in getExecOutput call and check exitCode
  explicitly, incorporating stderr into the thrown error for better
  diagnostics (copilot suggestion)
- Add try/catch around getExecOutput call to wrap thrown errors with
  descriptive message (covers the throw-path for gemini/copilot suggestions)
- Add tests for error path where getExecOutput throws (gemini suggestion)
- Add tests for error path where getExecOutput returns non-zero exit code
  (copilot suggestion)
ncc 0.36.1 bundles TypeScript 4.3.4 which does not support ES2022
target/lib. Using --transpile-only skips ncc's internal type checking
(handled separately by `pnpm typecheck`) and resolves the build failure.
@amondnet amondnet force-pushed the amondnet/best-countess branch from d23b16c to 156631e Compare March 29, 2026 10:22
@sonarqubecloud
Copy link
Copy Markdown

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.

track: use-actions-exec-20260329

3 participants