From 0ecc6ef632417de8b492134adac1e91d32c5ce9a Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Fri, 5 Dec 2025 17:17:37 +0100 Subject: [PATCH] fix(actions): improve errors when `${{ needs... }}` is used in `strategy.matrix` incorrectly (#10298) Three fixes are presented together in this PR: - When a `strategy.matrix` entry in an Action job contains `${{ needs.some-job.outputs.some-output }}`, if that output *never* becomes available, different error messages will be presented if `some-job` isn't found or if `some-output` isn't found. This clarifies an error message that was previously "it could be this, or it could be this". - In the error case described in the previous point, other jobs in the workflow could continue running or could be left "blocked" forever. A centralized `FailRunPreExecutionError` function ensures that all incomplete jobs in the run are failed in this case. - In a rare error case when a job referenced another job in `strategy.matrix` but no other jobs were defined in the workflow, the job would be marked as blocked forever because the `job_emitter` code would never be invoked to detect this case. A new `consistencyCheckRun` function for a newly created `ActionRun` adds a location to perform a pre-execution check for this case so that the run can be failed. These fixes are all interconnected around the refactor for the `FailRunPreExecutionError`, causing them to be bundled rather than individual PRs. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] I do not want this change to show in the release notes. - These are fixes to an unreleased feature and don't require release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10298 Reviewed-by: Earl Warren Co-authored-by: Mathieu Fenniak Co-committed-by: Mathieu Fenniak --- models/actions/pre_execution_errors.go | 6 + models/actions/pre_execution_errors_test.go | 16 +++ models/actions/run_job.go | 33 ++++- models/actions/run_job_test.go | 8 +- options/locale_next/locale_en-US.json | 2 + .../action_run.yml | 54 +++++++++ .../action_run_job.yml | 113 ++++++++++++++++++ .../action_run.yml | 19 +++ .../action_run_job.yml | 41 +++++++ services/actions/commit_status.go | 2 +- services/actions/commit_status_test.go | 5 +- services/actions/job_emitter.go | 50 +++++--- services/actions/job_emitter_test.go | 10 +- services/actions/notifier_helper.go | 28 ++++- services/actions/notifier_helper_test.go | 1 + services/actions/run.go | 98 ++++++++++++++- services/actions/run_test.go | 42 +++++++ services/actions/schedule_tasks.go | 4 + services/actions/workflows.go | 6 +- 19 files changed, 497 insertions(+), 41 deletions(-) create mode 100644 services/actions/TestActions_consistencyCheckRun/action_run.yml create mode 100644 services/actions/TestActions_consistencyCheckRun/action_run_job.yml diff --git a/models/actions/pre_execution_errors.go b/models/actions/pre_execution_errors.go index 0ba8f8f362..59976cde6e 100644 --- a/models/actions/pre_execution_errors.go +++ b/models/actions/pre_execution_errors.go @@ -19,6 +19,8 @@ const ( ErrorCodeEventDetectionError PreExecutionError = iota + 1 ErrorCodeJobParsingError ErrorCodePersistentIncompleteMatrix + ErrorCodeIncompleteMatrixMissingJob + ErrorCodeIncompleteMatrixMissingOutput ) func TranslatePreExecutionError(lang translation.Locale, run *ActionRun) string { @@ -36,6 +38,10 @@ func TranslatePreExecutionError(lang translation.Locale, run *ActionRun) string return lang.TrString("actions.workflow.job_parsing_error", run.PreExecutionErrorDetails...) case ErrorCodePersistentIncompleteMatrix: return lang.TrString("actions.workflow.persistent_incomplete_matrix", run.PreExecutionErrorDetails...) + case ErrorCodeIncompleteMatrixMissingJob: + return lang.TrString("actions.workflow.incomplete_matrix_missing_job", run.PreExecutionErrorDetails...) + case ErrorCodeIncompleteMatrixMissingOutput: + return lang.TrString("actions.workflow.incomplete_matrix_missing_output", run.PreExecutionErrorDetails...) } return fmt.Sprintf("