Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conditionally stub libraries #170

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

Merged
merged 2 commits into from
Mar 27, 2025
Merged

Conditionally stub libraries #170

merged 2 commits into from
Mar 27, 2025

Conversation

ncalteen
Copy link
Collaborator

See #168

The issue appears to arise because @github/local-action is attempting to stub all of the supported @actions/toolkit libraries, regardless of whether or not they are installed in the action's package.json. This PR updates the logic to only stub libraries that are actually present in the project.

@ncalteen ncalteen self-assigned this Mar 27, 2025
@Copilot Copilot AI review requested due to automatic review settings March 27, 2025 14:56
Copy link

@Copilot 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 updates the logic for conditionally stubbing the @actions/toolkit libraries so that only the libraries declared in package.json are stubbed.

  • Updated ESM branch logic to remove fallback values when resolving stubs.
  • Adjusted commonJS branch to include conditional stubbing for each library.
Files not reviewed (1)
  • package.json: Language not supported
Comments suppressed due to low confidence (3)

src/commands/run.ts:340

  • [nitpick] Since the if-condition already ensures that stubs['@actions/github'].base is defined, the fallback operator (?? '') is redundant; consider removing it for consistency with the ESM branch.
stubs['@actions/github'].base ?? ''

src/commands/run.ts:349

  • [nitpick] Removing the fallback (?? '') here would align the commonJS branch with the ESM branch, as the presence of a non-null base is already checked.
stubs['@actions/core'].base ?? ''

src/commands/run.ts:358

  • [nitpick] For consistency, eliminate the fallback operator (?? '') as the corresponding if-condition guarantees that stubs['@actions/artifact'].base is defined.
stubs['@actions/artifact'].base ?? ''

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

Copy link

github-actions bot commented Mar 27, 2025

πŸ¦™ MegaLinter status: ❌ ERROR

Descriptor Linter Files Fixed Errors Warnings Elapsed time
βœ… ACTION actionlint 4 0 0 0.2s
βœ… JAVASCRIPT prettier 11 0 0 1.32s
βœ… JSON npm-package-json-lint yes no no 1.21s
βœ… JSON prettier 26 0 0 3.59s
βœ… MARKDOWN markdownlint 9 0 0 0.93s
βœ… REPOSITORY checkov yes no no 27.56s
βœ… REPOSITORY gitleaks yes no no 1.28s
βœ… REPOSITORY git_diff yes no no 0.01s
βœ… REPOSITORY grype yes no no 42.2s
βœ… REPOSITORY secretlint yes no no 1.26s
βœ… REPOSITORY syft yes no no 8.56s
❌ REPOSITORY trivy yes 1 no 13.94s
βœ… REPOSITORY trivy-sbom yes no no 1.43s
βœ… REPOSITORY trufflehog yes no no 28.29s
βœ… TYPESCRIPT prettier 71 0 0 2.72s
βœ… YAML prettier 22 0 0 0.95s
βœ… YAML yamllint 22 0 0 0.46s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

@ncalteen ncalteen requested a review from Copilot March 27, 2025 15:06
Copy link

@Copilot 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 updates the stubbing logic so that only the stubs associated with installed libraries are loaded. Key changes include:

  • Adding conditional checks for each @actions/* stub (GitHub, Core, Artifact) before stubbing.
  • Removing the fallback value (using the nullish coalescing operator) in the path resolution for each stub.
  • Applying the same conditional logic for both ESM and non-ESM action types.
Files not reviewed (1)
  • package.json: Language not supported
Comments suppressed due to low confidence (1)

src/commands/run.ts:297

  • Ensure that stubs['@actions/github'].base always contains a valid string value. If it may be an empty string, the condition check might inadvertently skip the stubbing logic.
stubs['@actions/github'].base,

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

@ncalteen ncalteen merged commit 3b50e13 into main Mar 27, 2025
8 of 9 checks passed
@ncalteen ncalteen deleted the ncalteen/base branch March 27, 2025 15:08
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.

1 participant