]> source.dussan.org Git - gitea.git/commit
Improve the handling of `jobs.<job_id>.if` (#31070)
authorZettat123 <zettat123@gmail.com>
Mon, 27 May 2024 06:15:34 +0000 (14:15 +0800)
committerGitHub <noreply@github.com>
Mon, 27 May 2024 06:15:34 +0000 (14:15 +0800)
commit31a0c4dfb4156a7b4d856cceae1e61c7fc1a4a1b
treebab71c171e68a08bda1e8492c60b42f7b05cd377
parente695ba47557ed4c3999c63b28051a449ca4653de
Improve the handling of `jobs.<job_id>.if` (#31070)

Fix #25897
Fix #30322

#29464 cannot handle some complex `if` conditions correctly because it
only checks `always()` literally. In fact, it's not easy to evaluate the
`if` condition on the Gitea side because evaluating it requires a series
of contexts. But act_runner is able to evaluate the `if` condition
before running the job (for more information, see
[`gitea/act`](https://gitea.com/gitea/act/src/commit/517d11c67126bd97c88e2faabda0832fff482258/pkg/runner/run_context.go#L739-L753))
. So we can use act_runner to check the `if` condition.

In this PR, how to handle a blocked job depends on its `needs` and `if`:
- If not all jobs in `needs` completed successfully and the job's `if`
is empty, set the job status to `StatusSkipped`
- In other cases, the job status will be set to `StatusWaiting`, and
then act_runner will check the `if` condition and run the job if the
condition is met
services/actions/job_emitter.go
services/actions/job_emitter_test.go