Actions: re-running an empty matrix fails it again; a re-run keeps its actor

eaf7cde · Gabriel Morell · 2026-10-18 06:11

8 files +43 -2
Message
{commit_body(@commit)}

Files changed

modified lib/git_gud/workflows.ex
+5 −2
@@ -1051,9 +1051,11 @@ defmodule GitGud.Workflows do
1051 1051 do: create_job_leg(run, job, %{}, hold, status: "blocked", definition: job.raw)
1052 1052
1053 1053 # A row standing for a matrix not yet expanded (or that failed to):
1054 − # no combination of its own, an expression for a matrix.
1054 + # no combination of its own, but a matrix to expand — an expression, or
1055 + # a literal one that came out empty, which re-running must fail again
1056 + # rather than hand to a runner with the matrix still in it.
1055 1057 defp placeholder?(%WorkflowJob{matrix: nil, definition: definition}),
1056 − do: Matrix.dynamic?(definition["strategy"])
1058 + do: Matrix.matrix?(definition["strategy"])
1057 1059
1058 1060 defp placeholder?(_job), do: false
1059 1061
@@ -2760,6 +2762,7 @@ defmodule GitGud.Workflows do
2760 2762 head_ref: old.head_ref,
2761 2763 workflow_doc: old.workflow_doc,
2762 2764 event_payload: old.event_payload,
2765 + triggered_by_id: old.triggered_by_id,
2763 2766 pull_request_number: old.pull_request_number,
2764 2767 pr_head_ref: old.pr_head_ref,
2765 2768 pr_base_ref: old.pr_base_ref,
modified test/git_gud/workflows/matrix_dispatch_test.exs
+26 −0
@@ -668,6 +668,32 @@ defmodule GitGud.Workflows.MatrixDispatchTest do
668 668 assert reason =~ "no combinations"
669 669 assert Repo.get!(WorkflowRun, run.id).status == "failure"
670 670 end
671 +
672 + @tag :capture_log
673 + test "re-running one that excludes everything fails it again, unclaimed", %{repo: repo} do
674 + run =
675 + run_workflow(repo, """
676 + name: ci
677 + on: push
678 + jobs:
679 + build:
680 + strategy:
681 + matrix:
682 + os: [a]
683 + exclude:
684 + - os: a
685 + runs-on: self-hosted
686 + steps:
687 + - run: true
688 + """)
689 +
690 + {:ok, _} = Workflows.rerun_job(Repo.get!(WorkflowRun, run.id), "build")
691 +
692 + assert [%{status: "failure", attempt: 2, status_reason: reason}] = jobs(run)
693 + assert reason =~ "no combinations"
694 + assert Workflows.claim_next_job(runner(repo, ["self-hosted"])) == nil
695 + assert Repo.get!(WorkflowRun, run.id).status == "failure"
696 + end
671 697 end
672 698
673 699 describe "max-parallel" do
modified test/git_gud/workflows/rerun_cancel_test.exs
+12 −0
@@ -75,6 +75,18 @@ defmodule GitGud.Workflows.RerunCancelTest do
75 75 assert [%WorkflowJob{attempt: 1}] =
76 76 Repo.all(from j in WorkflowJob, where: j.workflow_run_id == ^new_run.id)
77 77 end
78 +
79 + test "keeps who triggered the run, so github.actor survives a re-run", %{repo: repo} do
80 + old =
81 + repo
82 + |> insert_run("failure")
83 + |> Ecto.Changeset.change(triggered_by_id: repo.owner_id)
84 + |> Repo.update!()
85 +
86 + assert {:ok, new_run} = Workflows.rerun(old)
87 + assert old.triggered_by_id
88 + assert new_run.triggered_by_id == old.triggered_by_id
89 + end
78 90 end
79 91
80 92 describe "rerun_job/2" do

Parents: d1406da