fix: Missing job-index and job-total attributes in strategy context#5988
Open
majiayu000 wants to merge 5 commits intonektos:masterfrom
Open
fix: Missing job-index and job-total attributes in strategy context#5988majiayu000 wants to merge 5 commits intonektos:masterfrom
job-index and job-total attributes in strategy context#5988majiayu000 wants to merge 5 commits intonektos:masterfrom
Conversation
This commit adds missing job-index and job-total attributes to the strategy context to match GitHub Actions behavior. - Added MatrixIndex and MatrixCount fields to RunContext - Updated newRunContext to accept and store job index and total count - Added job-index and job-total to strategy context in expression evaluators Fixes nektos#5976 Signed-off-by: majiayu000 <1835304752@qq.com>
Contributor
|
Thank you for taking a look, You missed updating composite action runcontext creation act/pkg/runner/action_composite.go Lines 47 to 82 in b2aee4b We also need tests for both workflow and composite action, so we can ensure this will continue to work in the future. Tests can be workflows in pkg/runner/testdata//push.yml use "act -W /push.yml" in pkg/runner/testdata/ to run them manually. I can help adding entries to runner_test.go I would suggest to try writing test workflows yourself, without the help from AI tooling to learn more about act itself. |
This commit adds comprehensive tests for the job-index and job-total strategy context attributes and fixes a boundary condition: - Added MatrixIndex and MatrixCount to the test RunContext fixture - Created createRunContextWithoutMatrix helper for testing non-matrix jobs - Added TestStrategyContext to verify job-index and job-total values - Added TestStrategyContextInStep to verify values in step evaluator - Fixed boundary condition: job-index and job-total are now only set when there's an actual matrix (MatrixCount > 0) The fix ensures that when a job has a Strategy but no actual matrix combinations (MatrixCount == 0), the job-index and job-total properties are not set in the strategy context, matching GitHub Actions behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This ensures strategy.job-index and strategy.job-total are accessible within composite actions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Author
|
@ChristopherHX Thanks for your review. Added the requested integration tests:
|
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
This PR fixes #5976
Changes
MatrixIndexandMatrixCountfields toRunContextstruct to track the current matrix job index (0-based) and total number of matrix jobsnewRunContextfunction signature to accept and initialize these new fieldsjob-indexandjob-totalattributes to the strategy context in bothNewExpressionEvaluatorWithEnvandnewStepExpressionEvaluatorfunctionsstrategy.job-indexandstrategy.job-totalexpressions in workflows, matching GitHub Actions behaviorThe implementation follows GitHub Actions specification where:
job-index: 0-based index of the current job in the matrix (e.g., 0, 1, 2, 3 for 4 jobs)job-total: Total number of jobs in the matrixGenerated with Claude Code