feat: add base-sha input for exact commit comparison#72
Closed
tatusamel wants to merge 1 commit into
Closed
Conversation
Add an optional `base-sha` input that allows specifying an explicit base commit SHA to compare coverage and test results against. When provided, the action first looks for workflow runs matching that SHA, then falls back to branch-based lookup if no matching runs are found. This is useful for comparing against a specific known-good commit rather than whatever the latest run on the base branch happens to be.
Comment on lines
203
to
+211
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fetch valid completed workflow runs, optionally trying a specific commit | ||
| * SHA first and falling back to the base branch. | ||
| */ | ||
| private async fetchValidWorkflowRuns( | ||
| baseBranch: string, |
There was a problem hiding this comment.
Bug: Artifact download fails silently if baseSha is from a different branch than baseBranch because the artifact name is constructed using the wrong branch.
Severity: MEDIUM
Suggested Fix
The code should be updated to handle this case. One option is to extract the actual branch from the workflow run metadata associated with the baseSha and use that branch name to construct the artifact name for downloading. Alternatively, the action's documentation could be updated to explicitly state that baseSha must be a commit that exists on the baseBranch, or a warning could be displayed when this mismatch is detected.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/utils/artifact-manager.ts#L203-L211
Potential issue: When a `baseSha` is provided that points to a commit on a different
branch than the `baseBranch`, the artifact download will silently fail. The artifact
upload process uses the branch name at the time of the run (e.g., `feature-x`) to name
the artifact. However, the download logic in `downloadBaseResults()` and
`downloadBaseCoverageResults()` constructs the artifact name using the `baseBranch`
(e.g., `main`). This mismatch causes the artifact lookup to find nothing, leading to a
silent failure where no comparison is performed, which is incorrect behavior for the
feature.
Did we get this right? 👍 / 👎 to inform future reviews.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
base-shainput that allows specifying an explicit base commit SHA to compare coverage and test results againstfetchValidWorkflowRuns()helper to avoid duplication between test and coverage download pathsMotivation
Currently the action always compares against the latest successful run on the base branch. This doesn't work well when you need to compare against a specific known-good commit — for example, when the base branch has moved forward but you want to compare against the actual merge base of your PR.
Changes
action.yml: Addedbase-shainput definitionsrc/utils/artifact-manager.ts: AddedfetchValidWorkflowRuns()private method that handles SHA-first-then-branch lookup; addedbaseShaparameter todownloadBaseResults()anddownloadBaseCoverageResults()src/index.ts: Reads thebase-shainput and threads it throughprocessTestResults()andprocessCoverage()src/__tests__/artifact-manager.test.ts: 8 tests covering SHA hit (no fallback), SHA miss (fallback to branch), no SHA (branch only), invalid conclusion filtering, and coverage equivalentsTest plan
dist/index.jsrebuilt successfullybase-shapointing to a commit with a successful workflow runbase-shapointing to a commit with no runs (verify fallback to branch)base-sha(verify existing behavior unchanged)