mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
feat(release): park an original whose dependency never reaches its line, and hold one whose dependency is pending
On 1.6, the fix in #5071 conflicts on every run: it modifies files that the feat in #3940 added on main, and that feat never reaches the line. The fix in #5082 builds on #5071 and on code that never comes either. Trying them on each run says nothing a maintainer can act on, and a conflict reads as work to do. Edges come from the dependencies the previous commit reads. One whose prerequisite the line or the open batch carries, whatever its rule or label, that this run picked or found empty, or whose evidence is present at the branch head once earlier picks moved it, is satisfied and dropped first. A direct push, an original rules 2-4, the start, a skip label or a drop keep out, or one itself parked never comes and parks the original. A prerequisite still to come (a conflict, a deferral, a workflow wait, rule 6) holds it as deferred{needs}, the strongest kind deciding: missing, workflow, deferred, rule 6; a chain inherits. run, check and the metadata operations share one order: partial unit on the batch, a direct reason, an unpicked partial, the workflow exception, a dependency park, a wait, then the original's own state. In the scheduled mode a workflow original whose remaining never-dependencies are only tests or docs waits for a maintainer instead of parking, which is the case of the release fix in #5142. check takes the mode the open record saved, and the scheduled one with no batch open, where a closed record's workflow waits wait on nothing any more and the original is judged as the scheduled run judges it. check and the record-only operations keep a partial park the open record holds while the batch head still shows it, since only the run's picker sees it after the picks before it. Records refuse waits and parks that form cycles, point at later merges or contradict each other. notify lists a wait after what decides it, from the record alone. backport/include lifts neither park nor wait. Assisted-By: LLM Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
20 files changed
+1583
-58
No files matched your search
@@ -39,6 +39,8 @@ The pull request body goes to stdout, built from the line's own `.github/PULL_RE
|
||||
|
||||
A clean pick can still carry only part of its original: git deletes a file the line never had without a word, and leaves alone a file the line lacks. So every path the original modifies or deletes, `M` or `D` in `git diff --name-status --no-renames M^1 M`, is judged at its counterpart on the line: the path itself, or the one a rename `git diff -M` finds between the line's fork point and `M^1` on `main`, between the fork point and the line, or both in turn. A modified path counts as left without effect when its counterpart exists neither before nor after the pick; when the pick leaves an existing file as it was, the file counts as there only when its blob is the original's, binary files included, or when `git merge-file` of the original's preimage, the line's file and the original's postimage merges cleanly back into the line's file. A deleted path counts as left without effect when its counterpart is absent before a pick that changes something, a deletion the line already made being no change of that pick, or still there after it, whatever the pick changed in it; when the original adds that path itself, as when the line made the same rename, it is judged as a modified file against what the original makes of that path. Picks that change nothing carry the original only when the line already has what it does to every file it modifies or deletes, so a change made where its branch merged `main`, which no pick brings, is still missing. What cannot be judged, a mode or type change, content `merge-file` refuses, or a rename git skipped looking for, is shown with the original and never counts against it. An original whose net merge onto the line, `git merge-tree --merge-base=M^1`, leaves something without effect is not tried, and one whose picks do is taken back off the branch: either is parked as partial, listed under "Parked" with those paths, and its release note stays out of the body. A conflict is never called partial. `backport/include` lifts no park.
|
||||
|
||||
Before it tries an original, `run` looks at what the original [builds on](#what-an-original-builds-on) that the branch lacks, in merge order, so what became of each prerequisite in this run is known. A prerequisite the line or the open batch carries, or that this run picked or found empty, counts as there; once earlier picks moved the branch, the original is judged at the branch's head, so a line another unit brought counts too. Of what is left, a direct push, an original rules 2 to 4, the line's start, `backport/skip` or a drop keep out, and one that is itself parked never come: the original is parked, not tried, and listed under "Parked" with what it builds on. In the scheduled mode an original that changes a workflow, whose missing dependencies that never come are only tests or docs and whose workflow lines build on nothing missing, waits for a maintainer instead, with a note saying so. Prerequisites still to come, a conflict, a deferral, a wait for a maintainer, one rule 6 holds, make the original wait: it is listed under "Waiting on another original", recorded with `needs`, the prerequisites of the kind that decides, in the order not on the line, waiting for a maintainer, deferred, rule 6, and tried again by a later run. A reason given with `--defer` comes before all of this, and a partial park before any of it.
|
||||
|
||||
`--defer N[,N] --reason TEXT` takes originals out of the open batch pull request, usually the ones a failing check was pinned on. It builds the batch branch again off `origin/<line>` without their units: while the batch still sits on the line's head, the units before the first one it drops stay as they are, and every later one, a pushed resolution included, is picked again in its own shape, a merge's picks one by one and then the merge with its message. When dropping one leaves a later commit that no longer applies, the run stops and names that commit's original, to defer as well. It adds no new original. It also takes out an original that got `backport/skip` after the batch picked it, which a run never removes on its own and the body lists as still on the branch. The body records each deferred original with the reason in the `backport-batch` block; a run that continues this batch keeps them out, and the next batch tries them again. A batch that carries a merge commit other than an original's, as GitHub's update-branch button makes, is refused, since picking such a merge again would lose what it resolved. When it takes out everything the batch carries, there is nothing left to push, and `--push` closes the batch pull request instead, as [the line's record](#the-lines-record-and-reports) describes.
|
||||
|
||||
`--drop N[,N] --reason TEXT` drops originals from the line: where `--defer` holds one out of this batch, a drop keeps it out of every later batch of the line too, until `--undrop N[,N]` withdraws it. A drop is recorded in the [line's record](#the-lines-record-and-reports), so both need an open batch pull request that carries one, and exit 2 without it; once a batch merges, its drops are carried into the next batch's record. A dropped original the open batch carries is taken off it as `--defer` would, and the rebuild is pushed the same way; any other drop or undrop changes only the record, so the batch stays as it is even when the line moved since. An undropped original is missing until the next run tries it. A drop names the original's merge commit on `main` as well as its number, and a record whose drop does not match what that merge commit merged stops every command with exit 2. An original the line already carries cannot be dropped, and neither can a number that merged into `main` before the line branched. The order is the rules', then the drop: what `backport/skip`, rules 2 to 4 or the line itself decide comes first, with the drop kept on record beside it, and `backport/include` does not lift a drop. The body lists dropped originals under their own heading among the skipped ones, `check` prints a note for each, and `fold` refuses one.
|
||||
@@ -53,11 +55,13 @@ Exits 1 and prints the URL of every pull request the rules take that is neither
|
||||
|
||||
An original with `backport/skip` that the open batch picked before the label came prints a warning in either mode, naming the batch and `run --defer`, which takes it out; it fails neither.
|
||||
|
||||
A unit on the open batch that leaves part of its original without effect, judged as [`run`](#run) judges a pick, at the unit's own first parent and whatever its original's rule, label or drop, prints a warning naming what it leaves out, and fails `--cut` ahead of any skip, drop or stale warning: take it out with `run --defer`. An original that is parked as partial prints as a note, `#N is parked: only part of it applies`, and fails neither.
|
||||
Every other original the policy takes that neither the line nor the open batch carries is decided in merge order, as [`run`](#run) decides it, with the open batch's found picks counting as there and the mode the open record saved, the scheduled run's when no batch is open, whose workflow waits on a closed record wait on nothing any more, so the original is judged as the scheduled run judges it: deferred for a reason, a warning; parked, a note naming what it builds on; in the scheduled mode a workflow original whose tests alone build on what never comes, waiting as the open batch lists it, or missing with none; and one that waits on other originals by the prerequisite that decides it: missing, which fails both modes, waiting for a maintainer, which warns and fails `--cut`, deferred, which warns, or held by rule 6, a note. A wait on one that waits itself inherits what decides that one.
|
||||
|
||||
A unit on the open batch that leaves part of its original without effect, judged as [`run`](#run) judges a pick, at the unit's own first parent and whatever its original's rule, label or drop, prints a warning naming what it leaves out, and fails `--cut` ahead of any skip, drop or stale warning: take it out with `run --defer`. An original that is parked as partial prints as a note, `#N is parked: only part of it applies`, and fails neither. That includes one the open record parks as partial that the net merge at the line's head finds whole, since `run`'s picker found it after the picks before it: `check` and the operations that only change the record keep it parked while its net merge onto what the batch carries now still leaves something without effect, and call it missing once that went, as when the pick that made it partial was taken off. A park only the commit-by-commit replay sees, which no net merge shows, reads as missing in `check` until the next run.
|
||||
|
||||
### fold
|
||||
|
||||
Checks a hand-made resolution of a deferred conflict before it is pushed onto the batch, in the shape the run gives an original. For a merged pull request `--commit` is a merge whose first parent is the head of the open batch pull request and whose message names the original in exactly one `Backported-from:` trailer; its second parent ends a straight line from that head of picks of the pull request's own commits, in their order, each ending in the `(cherry picked from commit …)` line of the commit it came from, none claiming another commit of the same original, a commit of another pull request never among them. For a squash-merged one it is a single commit on that head whose `(cherry picked from commit …)` line names the original's commit on `main`. Either has to change something, and only files the original changes or the paths a rename on `main` or on the line gave them, and has to leave nothing the original modifies or deletes without effect, judged as [`run`](#run) judges a pick: a resolution that ports what the line has and leaves out what it lacks is refused, since such a port goes to the line as a pull request of its own. The [conflict task](../../docs/release/backport-tasks/resolve-conflict.md) gives the commands. fold prints `ok` and exits 0, or prints why not and exits 1. It never commits or pushes; push one checked resolution at a time, since the next one has to sit on the new head.
|
||||
Checks a hand-made resolution of a deferred conflict before it is pushed onto the batch, in the shape the run gives an original. For a merged pull request `--commit` is a merge whose first parent is the head of the open batch pull request and whose message names the original in exactly one `Backported-from:` trailer; its second parent ends a straight line from that head of picks of the pull request's own commits, in their order, each ending in the `(cherry picked from commit …)` line of the commit it came from, none claiming another commit of the same original, a commit of another pull request never among them. For a squash-merged one it is a single commit on that head whose `(cherry picked from commit …)` line names the original's commit on `main`. An original parked for what it builds on folds like any other when the resolution is complete. Either has to change something, and only files the original changes or the paths a rename on `main` or on the line gave them, and has to leave nothing the original modifies or deletes without effect, judged as [`run`](#run) judges a pick: a resolution that ports what the line has and leaves out what it lacks is refused, since such a port goes to the line as a pull request of its own. The [conflict task](../../docs/release/backport-tasks/resolve-conflict.md) gives the commands. fold prints `ok` and exits 0, or prints why not and exits 1. It never commits or pushes; push one checked resolution at a time, since the next one has to sit on the new head.
|
||||
|
||||
### verify
|
||||
|
||||
@@ -67,6 +71,8 @@ Holds every unit of a batch to the shape fold checks for one, the clean picks as
|
||||
|
||||
Reads the [line's record](#the-lines-record-and-reports) first, as the other commands do, and exits 2 when it cannot read it or when it says the open batch is being closed, with a batch open or not. Then it reads the open batch pull request of the line, trusted as described below, and prints one line for each thing that waits on it: a batch open for three days or more, the shortest gap between two scheduled runs, so one the previous run already saw; the conflicts it deferred; and the originals waiting for a maintainer because they change workflows. Nothing open prints nothing.
|
||||
|
||||
An original the record has wait on others is listed once, as `#M, after #F`, where what decides its wait is listed: after a deferred conflict with the conflicts, after a workflow wait with the waits; one waiting on what is missing or held by rule 6 is not listed. A unit on the batch that carries only part of its original is listed apart, to be taken out before the cut.
|
||||
|
||||
With `--push` it writes the same into one comment on the batch pull request: the conflicts, each to be resolved as the [conflict task](../../docs/release/backport-tasks/resolve-conflict.md) describes, and the originals that wait because they change workflows.
|
||||
|
||||
The comment starts with `<!-- backport-batch:notify -->` and is one per pull request: a later run edits it in place rather than adding another, and once nothing waits it says so. Only a comment whose author the batch trusts counts as it, so one someone else wrote with the same first line is neither edited nor believed. It mentions `--mention`, an `org/team` or a login, with or without `@`, only while something waits. A failed batch CI is not among what it reports: the run has no trigger on the batch's CI finishing.
|
||||
@@ -116,7 +122,7 @@ An original the policy takes can build on code its line does not have: another p
|
||||
- A file it modifies or deletes whose counterpart, as [`run`](#run) follows renames, the line does not have is named by the first-parent commit on `main` that added it since the line branched: `git --literal-pathspecs log --first-parent --diff-merges=first-parent --no-renames --diff-filter=A -1 <fork point>..M^1 -- <path>`. A file nothing added since the fork point is shown with the original, since no other pull request brought it.
|
||||
- A line it removes or changes in a file the line has is given by `git blame --porcelain -w`, at `M^1` named by its full commit, to a commit, which counts through the first-parent commit on `main` that brought it: each commit of `main`'s first-parent line since the fork point brings itself and every commit of the range reachable from its other parents that no earlier one brought. A commit from before the fork point, which the line has, and the original's own count for nothing. The commit counts only while one of its lines, with its edges trimmed and nothing else, is absent from the line's version of the file, so a hand backport under another commit clears it. A file the line already has as the original makes it, the same blob or a clean `git merge-file` back into the line's file, builds on nothing.
|
||||
|
||||
Lines a tool wrote are not blamed: a generated file whole, `zz_generated*`, one with a `Code generated … DO NOT EDIT` marker in its first 100 lines, `go.sum` and the package-manager lock files, and in an ApplicationDefinition under `packages/system/*-rd/cozyrds/` the keys `hack/update-crd.sh` writes, found by their indentation. Controller-gen CRDs and `values.schema.json` are blamed like any other file. Each `git log`, `git diff` and `git blame` the detector and the rename detection run has two minutes, and rename detection that runs out of time counts as skipped, and an original has at most 256 files, missing or blamed, 20 000 blamed lines and 8 MiB per file read for it. Evidence it cannot read, past one of those bounds, a binary file, a symlink, a submodule, a commit blame names that did not come through `main`, a path that is not UTF-8, or a rename git skipped looking for, is shown with the original, whatever becomes of it, under its line in the body and in the report's `diag`. Output of git the tool cannot read whole stops it with exit 2, and is never taken for an absent dependency. A dependency carried only by lines an original adds is not seen. `run` prints how long reading the line took on stderr.
|
||||
Lines a tool wrote are not blamed: a generated file whole, `zz_generated*`, one with a `Code generated … DO NOT EDIT` marker in its first 100 lines, `go.sum` and the package-manager lock files, and in an ApplicationDefinition under `packages/system/*-rd/cozyrds/` the keys `hack/update-crd.sh` writes, found by their indentation. Controller-gen CRDs and `values.schema.json` are blamed like any other file. Each `git log`, `git diff` and `git blame` the detector and the rename detection run has two minutes, and rename detection that runs out of time counts as skipped, and an original has at most 256 files, missing or blamed, 20 000 blamed lines and 8 MiB per file read for it. Evidence it cannot read, past one of those bounds, a binary file, a symlink, a submodule, a commit blame names that did not come through `main`, a path that is not UTF-8, or a rename git skipped looking for, is shown with the original, whatever becomes of it, under its line in the body and in the report's `diag`. Output of git the tool cannot read whole stops it with exit 2, and is never taken for an absent dependency. A dependency carried only by lines an original adds is not seen. `run` prints how long reading the line took on stderr. What follows from a dependency, a park or a wait, is in [`run`](#run) and [`check`](#check).
|
||||
|
||||
## The line's record and reports
|
||||
|
||||
@@ -126,7 +132,7 @@ The record is written only while its pull request is open: a merged or closed ba
|
||||
|
||||
The record is only as trustworthy as the body it sits in. Anyone with write access can edit any body, the bot's included, and neither the bot's authorship nor anything in the block proves who edited it last. A hand edit that leaves a readable record is believed; one that breaks it stops every command with exit 2, naming the pull request. A reason or a file name in the record counts only in the form a run writes it, one line with no control, zero-width or bidi character, so text someone typed into the body never reaches a terminal, a body or a comment as they typed it. When the newest batch pull request is deleted and no later one exists, nothing shows it was there: the older record governs, and what was recorded since is lost.
|
||||
|
||||
The record holds only what later commands act on. Every run that classifies the line also makes a report, one line of JSON in a `backport-batch-report` block: every original merged into `main` since the line branched in exactly one category, picked, missing, deferred with what it was deferred for, or skipped with the rule that skipped it, each drop the record keeps with the merge commit it is bound to, its reason and the batch pull request that recorded it, the commits on `main` that merged no pull request, the labels, and what the classification was made of: the heads of `main`, the line and the newer line, the policy, the batch head it describes, the tool's commit, the Actions run and the flags. Its ID is a hash of all that but the time and the run, so two runs that find the same make the same report, and it names no pull request, so a new batch's report is whole before GitHub numbers the pull request. The body carries the latest report beside the record, and a comment on the open batch pull request keeps each one: `<!-- backport-batch:report <id> -->` and the same block, folded away. A report already posted is not posted again, and the tool never edits or deletes such a comment, so a report the next run replaces in the body is still read back by `report`, also after the batch merged. A comment that looks like one but whose author the batch does not trust is not read. When a run stops after writing the body but before posting its comment, the next `run --push` on the open batch posts that report first, byte for byte; once the batch is closed nothing is written to it, and the report stays in its body. A run that picks nothing while no batch is open keeps no report.
|
||||
The record holds only what later commands act on. Version 3, which this tool writes, adds what is parked and why, with the merge commit each park is bound to, the units on the batch that do only part of their original, the picks that differ from theirs, and what each wait on another original waits on; it reads versions 1 to 3, and a tool that reads only 1 and 2 refuses version 3 with exit 2. Every run that classifies the line also makes a report, one line of JSON in a `backport-batch-report` block: every original merged into `main` since the line branched in exactly one category, picked, missing, deferred with what it was deferred for, or skipped with the rule that skipped it, each drop the record keeps with the merge commit it is bound to, its reason and the batch pull request that recorded it, the commits on `main` that merged no pull request, the labels, and what the classification was made of: the heads of `main`, the line and the newer line, the policy, the batch head it describes, the tool's commit, the Actions run and the flags. Its ID is a hash of all that but the time and the run, so two runs that find the same make the same report, and it names no pull request, so a new batch's report is whole before GitHub numbers the pull request. The body carries the latest report beside the record, and a comment on the open batch pull request keeps each one: `<!-- backport-batch:report <id> -->` and the same block, folded away. A report already posted is not posted again, and the tool never edits or deletes such a comment, so a report the next run replaces in the body is still read back by `report`, also after the batch merged. A comment that looks like one but whose author the batch does not trust is not read. When a run stops after writing the body but before posting its comment, the next `run --push` on the open batch posts that report first, byte for byte; once the batch is closed nothing is written to it, and the report stays in its body. A run that picks nothing while no batch is open keeps no report.
|
||||
|
||||
A `--defer` that leaves the batch carrying nothing closes it, and writes everything while the pull request is still open: the report comment, then the body, whose record keeps the deferrals and says the batch is closing, with its number, branch and the head the rebuild started from. It then reads the pull request and the branch again, closes the pull request while both are at that head, and deletes the branch with `--force-with-lease` on it, printing `closed <url>`. The next batch tries what was deferred again. A close that stops part way is finished by the next `run --push`, before it does anything else: it closes and deletes when the pull request is open at the frozen head, deletes the branch when the pull request is closed and the branch still at that head, and goes on as usual once both are gone. A run that finishes a close stops there, with exit 0, or with exit 2 when it was asked for `--defer`, `--drop` or `--undrop`, which it does not apply. It never takes a head it did not freeze: with the branch moved, it stops with exit 2 and names both heads. `run` without `--push`, `check` and `fold` stop with exit 2 while the pull request is still open; once it is closed they go on, warning about a branch the close left, and `notify` says nothing. A closed pull request is never written to, so its record says it was closing for good, and a closed pull request whose branch is gone counts as closed.
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ type pick struct {
|
||||
files []string
|
||||
// failed is the commit whose pick conflicted.
|
||||
failed string
|
||||
// needs are the originals still to come it waits on.
|
||||
needs []int
|
||||
// more counts the conflicting files a recorded conflict no longer names.
|
||||
more int
|
||||
reason string
|
||||
@@ -204,6 +206,19 @@ func (a *app) run(args []string) int {
|
||||
return a.fail(err)
|
||||
}
|
||||
}
|
||||
// cls is what each original became in this run, to an original that
|
||||
// builds on it; the rules decide the rest.
|
||||
mode := analysisMode{noWorkflowFiles: *noWorkflows}
|
||||
cls := map[*verdict]edgeClass{}
|
||||
classOf := func(f *verdict) edgeClass {
|
||||
if c, ok := b.ruleClass(f); ok {
|
||||
return c
|
||||
}
|
||||
if c, ok := cls[f]; ok {
|
||||
return c
|
||||
}
|
||||
return edgeMissing
|
||||
}
|
||||
for _, v := range b.qualifying() {
|
||||
on := false
|
||||
if carried != nil {
|
||||
@@ -214,9 +229,11 @@ func (a *app) run(args []string) int {
|
||||
switch {
|
||||
case on:
|
||||
r.onBranch = append(r.onBranch, v)
|
||||
cls[v] = edgeSatisfied
|
||||
continue
|
||||
case held[v.o.number].Reason != "":
|
||||
r.held = append(r.held, pick{v: v, status: "held", reason: held[v.o.number].Reason})
|
||||
cls[v] = edgeDeferred
|
||||
continue
|
||||
case v.onBatch != "":
|
||||
v.rule, v.reason = ruleOnLine, fmt.Sprintf("on the open batch pull request #%d", b.pr.Number)
|
||||
@@ -231,6 +248,17 @@ func (a *app) run(args []string) int {
|
||||
}
|
||||
if v.partial != nil {
|
||||
r.parked = append(r.parked, v)
|
||||
cls[v] = edgeNever
|
||||
continue
|
||||
}
|
||||
}
|
||||
if len(v.deps) > 0 {
|
||||
kind, err := a.dependsAt(b, r, v, mode, classOf)
|
||||
if err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
if kind != edgeSatisfied {
|
||||
cls[v] = kind
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -241,6 +269,7 @@ func (a *app) run(args []string) int {
|
||||
}
|
||||
if len(files) > 0 {
|
||||
r.waiting = append(r.waiting, pick{v: v, status: "waiting", files: files})
|
||||
cls[v] = edgeWorkflow
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -257,10 +286,13 @@ func (a *app) run(args []string) int {
|
||||
v.partial = p.files
|
||||
v.park = &parkedEntry{Original: v.o.number, Merge: v.o.merge, Kind: parkPartial, Files: sortedClean(p.files)}
|
||||
r.parked = append(r.parked, v)
|
||||
cls[v] = edgeNever
|
||||
case "picked":
|
||||
r.onBranch = append(r.onBranch, v)
|
||||
cls[v] = edgeSatisfied
|
||||
case "conflict":
|
||||
r.deferred = append(r.deferred, p)
|
||||
cls[v] = edgeDeferred
|
||||
case "empty":
|
||||
v.rule, v.reason = ruleOnLine, "the earlier picks already carry it"
|
||||
r.skipped[ruleOnLine] = append(r.skipped[ruleOnLine], v)
|
||||
@@ -285,6 +317,50 @@ func (a *app) run(args []string) int {
|
||||
return a.finish(b, r, branch, date, *push, false)
|
||||
}
|
||||
|
||||
// dependsAt decides, from what v builds on that the branch lacks, whether
|
||||
// the run leaves it out: waiting for a maintainer in the scheduled mode
|
||||
// when only tests or docs build on what never comes, parked when anything
|
||||
// else never comes, or waiting on prerequisites still to come. What is
|
||||
// there, the line's, the batch's, or what this run picked or found empty,
|
||||
// counts for nothing; once earlier picks moved the branch, v is judged at
|
||||
// its head. It returns what v became to an original that builds on it,
|
||||
// edgeSatisfied when the run goes on to pick it.
|
||||
func (a *app) dependsAt(b *batch, r *report, v *verdict, mode analysisMode, classOf func(*verdict) edgeClass) (edgeClass, error) {
|
||||
deps := v.deps
|
||||
head, err := resolve("HEAD")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if head != b.lineHead {
|
||||
if deps, err = b.depsAt(v, head); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
never, pending := edges(deps, classOf)
|
||||
primary, err := workflowPrimary(mode, v, never, pending)
|
||||
switch {
|
||||
case err != nil:
|
||||
return 0, err
|
||||
case primary:
|
||||
files, err := workflowFiles(v.commits)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
v.addDiag(testsOnly(v, never, b.line))
|
||||
r.waiting = append(r.waiting, pick{v: v, status: "waiting", files: files})
|
||||
return edgeWorkflow, nil
|
||||
case len(never) > 0:
|
||||
v.park = dependencyPark(v, never)
|
||||
r.parked = append(r.parked, v)
|
||||
return edgeNever, nil
|
||||
case len(pending) > 0:
|
||||
class, needs := strongest(pending)
|
||||
r.needs = append(r.needs, pick{v: v, status: "waiting", needs: numbers(needs)})
|
||||
return class, nil
|
||||
}
|
||||
return edgeSatisfied, nil
|
||||
}
|
||||
|
||||
// partialAtHead judges v again where the run has got to, when earlier picks
|
||||
// moved the branch past the line's head.
|
||||
func (a *app) partialAtHead(b *batch, v *verdict) error {
|
||||
|
||||
@@ -176,6 +176,9 @@ type deferredEntry struct {
|
||||
More int `json:"more,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
Workflows bool `json:"workflows,omitempty"`
|
||||
// Needs, from version 3, are the originals still to come that it waits
|
||||
// on, those of the kind that decides the wait.
|
||||
Needs []int `json:"needs,omitempty"`
|
||||
}
|
||||
|
||||
// How many conflicting files of one original the body names, in the list and
|
||||
@@ -194,7 +197,7 @@ type deferredRecord struct {
|
||||
// had a version. encoding/json leaves bidi and zero-width characters as they
|
||||
// are, so file names go through clean first, as the reason does.
|
||||
func deferredBlock(l line, conflicts, held, waiting []pick) string {
|
||||
data, _ := json.Marshal(deferredRecord{Line: l.branch(), Deferred: deferredEntries(conflicts, held, waiting)})
|
||||
data, _ := json.Marshal(deferredRecord{Line: l.branch(), Deferred: deferredEntries(conflicts, held, waiting, nil)})
|
||||
return deferredFence + "\n" + string(data) + "\n```"
|
||||
}
|
||||
|
||||
@@ -231,6 +234,7 @@ type report struct {
|
||||
deferred []pick // conflicts
|
||||
held []pick // what --defer took out, with the reason
|
||||
waiting []pick // what changes workflows, left to a maintainer
|
||||
needs []pick // what waits on other originals still to come
|
||||
skipped map[int][]*verdict
|
||||
other int
|
||||
// overrides are the originals a backport/ label kept out or let in, and
|
||||
@@ -381,6 +385,12 @@ func (r *report) what(details map[int]bool) string {
|
||||
fmt.Fprintf(&b, "- %s %s: %s\n%s", prLink(v.o.number), titleSpan(v.o.title), parkReason(*v.park), diagItems(v))
|
||||
}
|
||||
}
|
||||
if len(r.needs) > 0 {
|
||||
fmt.Fprintf(&b, "\n### Waiting on another original\n\nThese build on another original that has not reached %s yet, so the batch does not try them; each names the one it waits on, and the batch tries it again once that one is there.\n\n", codeSpan(r.line.branch()))
|
||||
for _, p := range r.needs {
|
||||
fmt.Fprintf(&b, "- %s %s: after %s\n%s", prLink(p.v.o.number), titleSpan(p.v.o.title), prLinks(p.needs), diagItems(p.v))
|
||||
}
|
||||
}
|
||||
if len(r.overrides) > 0 {
|
||||
b.WriteString("\n### Maintainer overrides\n\n")
|
||||
for _, v := range r.overrides {
|
||||
@@ -437,6 +447,9 @@ func (r *report) outcome(v *verdict) string {
|
||||
return "waiting for a maintainer: it changes " + codeSpan(workflowsDir)
|
||||
case slices.Contains(r.parked, v):
|
||||
return "parked: " + parkReason(*v.park)
|
||||
case slices.ContainsFunc(r.needs, func(p pick) bool { return p.v == v }):
|
||||
i := slices.IndexFunc(r.needs, func(p pick) bool { return p.v == v })
|
||||
return "waiting on " + prLinks(r.needs[i].needs)
|
||||
case v.rule != 0:
|
||||
return "skipped by " + ruleName(v.rule) + ", " + titleSpan(v.reason)
|
||||
}
|
||||
@@ -465,6 +478,15 @@ func fileSpans(files []string) string {
|
||||
return strings.Join(out, ", ")
|
||||
}
|
||||
|
||||
// prLinks links to pull requests by number.
|
||||
func prLinks(numbers []int) string {
|
||||
var out []string
|
||||
for _, n := range numbers {
|
||||
out = append(out, prLink(n))
|
||||
}
|
||||
return strings.Join(out, ", ")
|
||||
}
|
||||
|
||||
// parkReason says why a park leaves its original out, for the body.
|
||||
func parkReason(p parkedEntry) string {
|
||||
if p.Kind == parkPartial {
|
||||
|
||||
@@ -51,7 +51,13 @@ func (a *app) check(args []string) int {
|
||||
if err := a.warnLeftBranch(b); err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
disp, err := b.dispositions(*cut)
|
||||
// The scheduled run's mode, as the open batch saved it; with none open,
|
||||
// the scheduled run's, which is what the next batch is built in.
|
||||
mode := analysisMode{noWorkflowFiles: true}
|
||||
if b.src.open {
|
||||
mode.noWorkflowFiles = b.src.savedNoWorkflowFiles()
|
||||
}
|
||||
disp, err := b.dispositions(mode, *cut)
|
||||
if err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
@@ -138,8 +144,11 @@ type disposition struct {
|
||||
|
||||
// dispositions says what check reports about each original that needs a line
|
||||
// of its own; the others pass in silence. The text is what follows the line's
|
||||
// name, or the original alone for one that is missing.
|
||||
func (b *batch) dispositions(cut bool) (map[*verdict]disposition, error) {
|
||||
// name, or the original alone for one that is missing. Originals are taken in
|
||||
// merge order, each by the first of: a unit on the batch that does only part
|
||||
// of it, a reason a person deferred it for, a park, a wait for a maintainer
|
||||
// or on other originals, and what the record says of it.
|
||||
func (b *batch) dispositions(mode analysisMode, cut bool) (map[*verdict]disposition, error) {
|
||||
if c := b.src.closingOpen(); c != nil {
|
||||
return nil, fmt.Errorf("batch pull request #%d is being closed; backport-batch run --line %s --push finishes it", c.PR, b.line.branch())
|
||||
}
|
||||
@@ -159,10 +168,40 @@ func (b *batch) dispositions(cut bool) (map[*verdict]disposition, error) {
|
||||
on += " (" + prState(c) + ")"
|
||||
}
|
||||
}
|
||||
if err := b.analyze(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if b.pr != nil {
|
||||
if err := b.keepRecordedPartials(b.prHead); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
held := map[int]string{}
|
||||
for n, e := range deferred {
|
||||
if e.Reason != "" {
|
||||
held[n] = e.Reason
|
||||
}
|
||||
}
|
||||
states, err := b.classify(mode, held, deferred, b.src.open)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// waitsOn names what an original waits on, as check says it.
|
||||
waitsOn := func(s *state) string {
|
||||
var names []string
|
||||
for _, f := range s.needs {
|
||||
names = append(names, fmt.Sprintf("#%d", f.o.number))
|
||||
}
|
||||
return strings.Join(names, " and ")
|
||||
}
|
||||
out := map[*verdict]disposition{}
|
||||
for _, v := range b.verdicts {
|
||||
named := v.o.url() + " " + terminalSafe(v.o.title)
|
||||
e, isDeferred := deferred[v.o.number]
|
||||
s := states[v]
|
||||
if s == nil {
|
||||
s = &state{kind: stOwn}
|
||||
}
|
||||
switch {
|
||||
case b.partialUnits[v] != nil && cut:
|
||||
out[v] = disposition{outcomeUnmerged, fmt.Sprintf("#%d is on batch #%d, but only part of it applies to %s: it leaves %s without effect; take it out with backport-batch run --defer before the cut: %s", v.o.number, b.pr.Number, b.line.branch(), quotedFiles(b.partialUnits[v]), named)}
|
||||
@@ -178,17 +217,41 @@ func (b *batch) dispositions(cut bool) (map[*verdict]disposition, error) {
|
||||
if cut {
|
||||
out[v] = disposition{outcomeUnmerged, fmt.Sprintf("#%d is only on open batch PR #%d, merge it before the cut: %s", v.o.number, b.pr.Number, named)}
|
||||
}
|
||||
case isDeferred && e.Reason != "":
|
||||
case s.kind == stHeld:
|
||||
out[v] = disposition{outcomeWarning, fmt.Sprintf("deferred on %s to the next batch: %s (%s)", on, named, terminalSafe(e.Reason))}
|
||||
case v.park != nil && v.park.Kind == parkPartial:
|
||||
case s.kind == stPartial:
|
||||
out[v] = disposition{outcomeNote, fmt.Sprintf("#%d is parked: only part of it applies to %s, which would leave %s without effect; port what applies as a pull request of its own: %s", v.o.number, b.line.branch(), quotedFiles(v.park.Files), named)}
|
||||
case s.kind == stWorkflowPrimary && s.class == edgeMissing:
|
||||
out[v] = disposition{outcomeMissing, named}
|
||||
case s.kind == stParked:
|
||||
out[v] = disposition{outcomeNote, fmt.Sprintf("#%d is parked: it builds on %s, which never reaches %s; port what applies as a pull request of its own, or drop it: %s", v.o.number, parkNames(*v.park), b.line.branch(), named)}
|
||||
case s.kind == stNeeds && s.wait == edgeMissing:
|
||||
out[v] = disposition{outcomeMissing, fmt.Sprintf("%s (it waits on %s, which is not on the line either)", named, waitsOn(s))}
|
||||
case s.kind == stNeeds && s.wait == edgeWorkflow && cut:
|
||||
out[v] = disposition{outcomeWaiting, fmt.Sprintf("#%d waits on %s, which changes %s and waits on batch PR %s for a maintainer; bring it over, or defer both, before the cut: %s", v.o.number, waitsOn(s), workflowsDir, on, named)}
|
||||
case s.kind == stNeeds && s.wait == edgeWorkflow:
|
||||
out[v] = disposition{outcomeWarning, fmt.Sprintf("#%d waits on %s, which waits on %s for a maintainer: %s", v.o.number, waitsOn(s), on, named)}
|
||||
case s.kind == stNeeds && s.wait == edgeDeferred:
|
||||
what := "a deferred conflict on " + on
|
||||
if f := s.needs[0]; deferred[f.o.number].Reason != "" {
|
||||
what = "deferred on " + on + " to the next batch"
|
||||
} else if states[f] != nil && states[f].kind == stNeeds {
|
||||
what = "which waits itself"
|
||||
}
|
||||
out[v] = disposition{outcomeWarning, fmt.Sprintf("#%d waits on %s, %s: %s", v.o.number, waitsOn(s), what, named)}
|
||||
case s.kind == stNeeds:
|
||||
newer := "the newer line"
|
||||
if b.newer != nil {
|
||||
newer = b.newer.branch()
|
||||
}
|
||||
out[v] = disposition{outcomeNote, fmt.Sprintf("#%d waits on %s, which is not on %s yet: %s", v.o.number, waitsOn(s), newer, named)}
|
||||
case isDeferred && e.Workflows && !b.src.open:
|
||||
out[v] = disposition{outcomeMissing, named}
|
||||
case isDeferred && e.Workflows && cut:
|
||||
out[v] = disposition{outcomeWaiting, fmt.Sprintf("#%d changes %s and waits on batch PR %s for a maintainer, bring it over or defer it before the cut: %s", v.o.number, workflowsDir, on, named)}
|
||||
case isDeferred && e.Workflows:
|
||||
out[v] = disposition{outcomeWarning, fmt.Sprintf("waiting on %s for a maintainer, since it changes %s: %s", on, workflowsDir, named)}
|
||||
case isDeferred:
|
||||
case isDeferred && len(e.Needs) == 0:
|
||||
out[v] = disposition{outcomeWarning, fmt.Sprintf("deferred conflict on %s: %s", on, named)}
|
||||
default:
|
||||
out[v] = disposition{outcomeMissing, named}
|
||||
@@ -197,6 +260,18 @@ func (b *batch) dispositions(cut bool) (map[*verdict]disposition, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// parkNames names what a park waits on for a terminal.
|
||||
func parkNames(p parkedEntry) string {
|
||||
var out []string
|
||||
for _, n := range p.Needs {
|
||||
out = append(out, fmt.Sprintf("#%d", n))
|
||||
}
|
||||
for _, c := range p.Commits {
|
||||
out = append(out, c[:12])
|
||||
}
|
||||
return strings.Join(out, ", ")
|
||||
}
|
||||
|
||||
// quotedFiles names files for a terminal, each quoted, the first few of them.
|
||||
func quotedFiles(files []string) string {
|
||||
var out []string
|
||||
|
||||
@@ -138,22 +138,50 @@ func (a *app) reclassify(b *batch, picks *history, hold map[int]string, drops []
|
||||
if r.stale, err = keptOut(b, picks); err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
// What the rebuild took off is no longer there for what builds on it.
|
||||
units, err := b.unitsOn(picks.head)
|
||||
if err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
for _, v := range b.verdicts {
|
||||
v.batched = units[v]
|
||||
}
|
||||
on := map[*verdict]bool{}
|
||||
for _, v := range b.qualifying() {
|
||||
e := recorded[v.o.number]
|
||||
on, err := b.onBranch(picks, v)
|
||||
if err != nil {
|
||||
if on[v], err = b.onBranch(picks, v); err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
if !on[v] {
|
||||
v.onBatch = ""
|
||||
}
|
||||
}
|
||||
if err := b.keepRecordedPartials(picks.head); err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
states, err := b.classify(analysisMode{noWorkflowFiles: r.opts.NoWorkflowFiles}, hold, recorded, true)
|
||||
if err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
for _, v := range b.qualifying() {
|
||||
e := recorded[v.o.number]
|
||||
s := states[v]
|
||||
if s == nil {
|
||||
s = &state{kind: stOwn}
|
||||
}
|
||||
switch {
|
||||
case on:
|
||||
case on[v]:
|
||||
r.onBranch = append(r.onBranch, v)
|
||||
case hold[v.o.number] != "":
|
||||
r.held = append(r.held, pick{v: v, status: "held", reason: hold[v.o.number]})
|
||||
case v.park != nil:
|
||||
case s.kind == stPartial || s.kind == stParked:
|
||||
r.parked = append(r.parked, v)
|
||||
case s.kind == stNeeds:
|
||||
r.needs = append(r.needs, pick{v: v, status: "waiting", needs: numbers(s.needs)})
|
||||
case s.kind == stWorkflowPrimary && !e.Workflows:
|
||||
r.missing = append(r.missing, v)
|
||||
case e.Workflows:
|
||||
r.waiting = append(r.waiting, pick{v: v, status: "waiting", files: e.Files, more: e.More})
|
||||
case len(e.Files) > 0:
|
||||
case len(e.Files) > 0 && len(e.Needs) == 0:
|
||||
r.deferred = append(r.deferred, pick{v: v, status: "conflict", files: e.Files, more: e.More, failed: e.Commit})
|
||||
default:
|
||||
// Merged into main since the batch was assembled, or recorded
|
||||
|
||||
+280
-21
@@ -436,6 +436,23 @@ func (b *batch) dependencies(v *verdict, target string) ([]dependency, []string,
|
||||
for _, d := range byMerge {
|
||||
slices.Sort(d.paths)
|
||||
deps = append(deps, *d)
|
||||
// The rules decide before the line is looked at, so whether the
|
||||
// line carries a prerequisite they keep out is asked here.
|
||||
if f := d.v; f != nil && f.rule != 0 && f.rule != ruleOnLine && f.rule != ruleNewer && b.lineHist != nil {
|
||||
if _, asked := b.lineCarries[f]; !asked {
|
||||
if err := b.load(f); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
how, err := b.lineHist.carries(f.o, f.commits)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if b.lineCarries == nil {
|
||||
b.lineCarries = map[*verdict]bool{}
|
||||
}
|
||||
b.lineCarries[f] = how != ""
|
||||
}
|
||||
}
|
||||
}
|
||||
slices.SortFunc(deps, func(x, y dependency) int { return strings.Compare(x.merge, y.merge) })
|
||||
return deps, diag, nil
|
||||
@@ -614,25 +631,9 @@ func (b *batch) beforeBase(commit string) (bool, error) {
|
||||
return ok, err
|
||||
}
|
||||
|
||||
// depNote is how a dependency is shown with its original.
|
||||
func (d dependency) note(l line) string {
|
||||
who := fmt.Sprintf("%.12s, a commit on main that merged no pull request", d.merge)
|
||||
if d.v != nil {
|
||||
who = fmt.Sprintf("#%d", d.v.o.number)
|
||||
}
|
||||
quoted := make([]string, len(d.paths))
|
||||
for i, p := range d.paths {
|
||||
quoted[i] = shown(p)
|
||||
}
|
||||
how := "in " + strings.Join(quoted, ", ")
|
||||
if d.added {
|
||||
how = "which added " + strings.Join(quoted, ", ")
|
||||
}
|
||||
return oneLineText(fmt.Sprintf("builds on %s, %s, which %s lacks", who, how, l.branch()))
|
||||
}
|
||||
|
||||
// analyze reads what every original the policy takes and nothing carries
|
||||
// builds on that the line lacks, and keeps it with the original.
|
||||
// builds on that the line lacks, and keeps it with the original, for the
|
||||
// parks and waits that follow from it.
|
||||
func (b *batch) analyze() error {
|
||||
defer b.timed(time.Now())
|
||||
for _, v := range b.qualifying() {
|
||||
@@ -645,9 +646,267 @@ func (b *batch) analyze() error {
|
||||
}
|
||||
v.deps = deps
|
||||
v.addDiag(diag...)
|
||||
for _, d := range deps {
|
||||
v.addDiag(d.note(b.line))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// analysisMode is how a classification treats an original that changes a
|
||||
// workflow: as the scheduled run does, whose token cannot push one, or as a
|
||||
// maintainer's run.
|
||||
type analysisMode struct{ noWorkflowFiles bool }
|
||||
|
||||
// edgeClass is what a prerequisite is to an original that builds on it,
|
||||
// from what never matters to what decides first.
|
||||
type edgeClass int
|
||||
|
||||
const (
|
||||
edgeSatisfied edgeClass = iota
|
||||
// edgeNewer is held by rule 6 on this line.
|
||||
edgeNewer
|
||||
// edgeDeferred is a deferred conflict, or deferred for a reason.
|
||||
edgeDeferred
|
||||
// edgeWorkflow waits on the open batch for a maintainer.
|
||||
edgeWorkflow
|
||||
// edgeMissing is on neither the line, the batch nor the record.
|
||||
edgeMissing
|
||||
// edgeNever never reaches the line.
|
||||
edgeNever
|
||||
)
|
||||
|
||||
// edge is a dependency whose prerequisite has not reached the line, with
|
||||
// what that prerequisite is.
|
||||
type edge struct {
|
||||
dep dependency
|
||||
class edgeClass
|
||||
}
|
||||
|
||||
// ruleClass is what the rules alone make of a prerequisite, or ok false when
|
||||
// it depends on what this classification makes of it: one the line or the
|
||||
// open batch carries is there, whatever its label, drop or rule says, and a
|
||||
// direct push and an original the rules keep out never come.
|
||||
func (b *batch) ruleClass(f *verdict) (edgeClass, bool) {
|
||||
switch {
|
||||
case f == nil:
|
||||
return edgeNever, true
|
||||
case f.rule == ruleOnLine || f.onBatch != "" || f.batched != "" || b.lineCarries[f]:
|
||||
return edgeSatisfied, true
|
||||
case f.rule == ruleNewer:
|
||||
return edgeNewer, true
|
||||
case f.rule != 0:
|
||||
return edgeNever, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// edges sorts dependencies by what classOf says of each prerequisite into
|
||||
// those that never come and those still to come, dropping the ones there.
|
||||
func edges(deps []dependency, classOf func(*verdict) edgeClass) (never, pending []edge) {
|
||||
for _, d := range deps {
|
||||
switch c := classOf(d.v); c {
|
||||
case edgeSatisfied:
|
||||
case edgeNever:
|
||||
never = append(never, edge{d, c})
|
||||
default:
|
||||
pending = append(pending, edge{d, c})
|
||||
}
|
||||
}
|
||||
return never, pending
|
||||
}
|
||||
|
||||
// strongest is the class of prerequisite that decides a wait, and the
|
||||
// prerequisites of that class, in merge order.
|
||||
func strongest(pending []edge) (edgeClass, []*verdict) {
|
||||
top := edgeSatisfied
|
||||
for _, e := range pending {
|
||||
top = max(top, e.class)
|
||||
}
|
||||
var out []*verdict
|
||||
for _, e := range pending {
|
||||
if e.class == top && !slices.Contains(out, e.dep.v) {
|
||||
out = append(out, e.dep.v)
|
||||
}
|
||||
}
|
||||
return top, out
|
||||
}
|
||||
|
||||
// auxiliary says whether a path holds tests or documentation, which an
|
||||
// original can change without building on what it needs to work.
|
||||
func auxiliary(p string) bool {
|
||||
parts := strings.Split(p, "/")
|
||||
base := parts[len(parts)-1]
|
||||
for _, d := range parts[:len(parts)-1] {
|
||||
if d == "test" || d == "tests" || d == "testdata" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case strings.HasSuffix(base, "_test.go"), strings.Contains(base, ".test."), strings.Contains(base, ".spec."), strings.HasSuffix(base, ".bats"):
|
||||
return true
|
||||
case len(parts) > 1 && parts[0] == "docs":
|
||||
return true
|
||||
}
|
||||
return len(parts) == 1 && strings.HasSuffix(base, ".md")
|
||||
}
|
||||
|
||||
// workflowPrimary says whether v waits for a maintainer rather than parks:
|
||||
// in the scheduled mode, an original that changes a workflow, all of whose
|
||||
// missing dependencies that never come are tests or docs, and whose
|
||||
// workflow lines build on nothing still missing. The workflow is what it is
|
||||
// for, and a maintainer brings over what applies. Only what is still
|
||||
// missing counts: never and pending are what is left once what is there was
|
||||
// taken out.
|
||||
func workflowPrimary(mode analysisMode, v *verdict, never, pending []edge) (bool, error) {
|
||||
if !mode.noWorkflowFiles || len(never) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
for _, e := range never {
|
||||
if slices.ContainsFunc(e.dep.paths, func(p string) bool { return !auxiliary(p) }) {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
for _, e := range append(slices.Clone(never), pending...) {
|
||||
if slices.ContainsFunc(e.dep.paths, func(p string) bool { return strings.HasPrefix(p, workflowsDir) }) {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
files, err := workflowFiles(v.commits)
|
||||
return len(files) > 0, err
|
||||
}
|
||||
|
||||
// testsOnly is the note a workflow original gets that waits for a
|
||||
// maintainer although its tests build on what never comes.
|
||||
func testsOnly(v *verdict, never []edge, l line) string {
|
||||
var who []string
|
||||
for _, e := range never {
|
||||
if e.dep.v != nil {
|
||||
who = append(who, fmt.Sprintf("#%d", e.dep.v.o.number))
|
||||
} else {
|
||||
who = append(who, e.dep.merge[:12])
|
||||
}
|
||||
}
|
||||
slices.Sort(who)
|
||||
return oneLineText(fmt.Sprintf("only its tests or docs build on %s, which never reaches %s", strings.Join(slices.Compact(who), ", "), l.branch()))
|
||||
}
|
||||
|
||||
// dependencyPark is the park of v for prerequisites that never come.
|
||||
func dependencyPark(v *verdict, never []edge) *parkedEntry {
|
||||
p := &parkedEntry{Original: v.o.number, Merge: v.o.merge, Kind: parkDependency}
|
||||
for _, e := range never {
|
||||
if e.dep.v != nil {
|
||||
p.Needs = append(p.Needs, e.dep.v.o.number)
|
||||
} else {
|
||||
p.Commits = append(p.Commits, e.dep.merge)
|
||||
}
|
||||
}
|
||||
slices.Sort(p.Needs)
|
||||
p.Needs = slices.Compact(p.Needs)
|
||||
slices.Sort(p.Commits)
|
||||
p.Commits = slices.Compact(p.Commits)
|
||||
return p
|
||||
}
|
||||
|
||||
// depsAt is what v builds on that target lacks, read once per target: the
|
||||
// run asks again at its head once earlier picks moved the branch.
|
||||
func (b *batch) depsAt(v *verdict, target string) ([]dependency, error) {
|
||||
key := target + " " + v.o.merge
|
||||
if d, ok := b.depCache[key]; ok {
|
||||
return d, nil
|
||||
}
|
||||
deps, diag, err := b.dependencies(v, target)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.addDiag(diag...)
|
||||
if b.depCache == nil {
|
||||
b.depCache = map[string][]dependency{}
|
||||
}
|
||||
b.depCache[key] = deps
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
// stateKind is what a classification makes of an original the policy takes
|
||||
// that nothing carries, in the order that decides it.
|
||||
type stateKind int
|
||||
|
||||
const (
|
||||
// stHeld is deferred for a reason a person gave.
|
||||
stHeld stateKind = iota + 1
|
||||
// stPartial would leave part of it without effect on the line.
|
||||
stPartial
|
||||
// stWorkflowPrimary waits for a maintainer, though its tests build on
|
||||
// what never comes.
|
||||
stWorkflowPrimary
|
||||
// stParked builds on what never comes.
|
||||
stParked
|
||||
// stNeeds waits on prerequisites still to come.
|
||||
stNeeds
|
||||
// stOwn is what the record says of it, or missing.
|
||||
stOwn
|
||||
)
|
||||
|
||||
// state is a classification of one original: what it is, what it is to an
|
||||
// original that builds on it, and for a wait the class that decides it and
|
||||
// the prerequisites of that class.
|
||||
type state struct {
|
||||
kind stateKind
|
||||
class edgeClass
|
||||
wait edgeClass
|
||||
needs []*verdict
|
||||
}
|
||||
|
||||
// classify decides, in merge order, what becomes of every original the
|
||||
// policy takes that neither the line nor the open batch carries, as an
|
||||
// operation that picks nothing sees it: check, and the ones that only
|
||||
// change the record. held are the reasons people deferred originals for,
|
||||
// recorded what the record defers, and listed says the record's workflow
|
||||
// waits still wait on an open batch. Parks it finds go into each verdict.
|
||||
func (b *batch) classify(mode analysisMode, held map[int]string, recorded map[int]deferredEntry, listed bool) (map[*verdict]*state, error) {
|
||||
states := map[*verdict]*state{}
|
||||
classOf := func(f *verdict) edgeClass {
|
||||
if c, ok := b.ruleClass(f); ok {
|
||||
return c
|
||||
}
|
||||
if s := states[f]; s != nil {
|
||||
return s.class
|
||||
}
|
||||
return edgeMissing
|
||||
}
|
||||
for _, v := range b.qualifying() {
|
||||
if v.onBatch != "" {
|
||||
continue
|
||||
}
|
||||
s := &state{}
|
||||
states[v] = s
|
||||
e := recorded[v.o.number]
|
||||
never, pending := edges(v.deps, classOf)
|
||||
primary, err := workflowPrimary(mode, v, never, pending)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch {
|
||||
case held[v.o.number] != "":
|
||||
s.kind, s.class = stHeld, edgeDeferred
|
||||
case v.park != nil && v.park.Kind == parkPartial:
|
||||
s.kind, s.class = stPartial, edgeNever
|
||||
case primary:
|
||||
s.kind, s.class = stWorkflowPrimary, edgeMissing
|
||||
if listed && e.Workflows {
|
||||
s.class = edgeWorkflow
|
||||
}
|
||||
case len(never) > 0:
|
||||
v.park = dependencyPark(v, never)
|
||||
s.kind, s.class = stParked, edgeNever
|
||||
case len(pending) > 0:
|
||||
s.kind = stNeeds
|
||||
s.wait, s.needs = strongest(pending)
|
||||
s.class = s.wait
|
||||
case listed && e.Workflows:
|
||||
s.kind, s.class = stOwn, edgeWorkflow
|
||||
case !e.Workflows && len(e.Needs) == 0 && (e.Commit != "" || len(e.Files) > 0):
|
||||
s.kind, s.class = stOwn, edgeDeferred
|
||||
default:
|
||||
s.kind, s.class = stOwn, edgeMissing
|
||||
}
|
||||
}
|
||||
return states, nil
|
||||
}
|
||||
@@ -117,6 +117,9 @@ func (a *app) redrop(b *batch, numbers []int, reason string, undrop bool, push b
|
||||
if err := b.load(v); err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
if err := b.rejudged(v); err != nil {
|
||||
return a.fail(err)
|
||||
}
|
||||
if undrop {
|
||||
continue
|
||||
}
|
||||
@@ -159,6 +162,38 @@ func (b *batch) bindDrops(merges []*original) (map[int]droppedEntry, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// waitOrder refuses a record whose waits or parks need an original merged
|
||||
// after the one that needs it: a dependency is always on main first.
|
||||
func (b *batch) waitOrder(merges []*original) error {
|
||||
if b.src.rec == nil {
|
||||
return nil
|
||||
}
|
||||
at := map[int]int{}
|
||||
for i, o := range merges {
|
||||
at[o.number] = i
|
||||
}
|
||||
check := func(n int, needs []int) error {
|
||||
i, ok := at[n]
|
||||
for _, f := range needs {
|
||||
if j, known := at[f]; ok && known && j >= i {
|
||||
return fmt.Errorf("batch pull request #%d has #%d wait on #%d, which merged after it", b.src.carrier.Number, n, f)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for _, d := range b.src.rec.Deferred {
|
||||
if err := check(d.Original, d.Needs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, p := range b.src.rec.Parked {
|
||||
if err := check(p.Original, p.Needs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindEntries binds drops to main: one whose original is among merges, the
|
||||
// originals main merged since the line branched, has to name that
|
||||
// original's merge exactly; any other has to be a merge of its number on
|
||||
|
||||
@@ -444,6 +444,7 @@ func (b *batch) partialStates() error {
|
||||
return err
|
||||
}
|
||||
for v, commit := range on {
|
||||
v.batched = commit
|
||||
if v.rule == 0 && v.onBatch == "" {
|
||||
v.onBatch = commit
|
||||
}
|
||||
@@ -511,6 +512,58 @@ func (b *batch) markPartial(r *report, head string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// keepRecordedPartials judges again, at head, what the batch carries now,
|
||||
// each original the open record parks as partial that the line's head
|
||||
// judges whole: the run's picker found it partial after the picks before
|
||||
// it, which check and an operation that picks nothing do not replay. It
|
||||
// stays parked while its net merge onto head still leaves something
|
||||
// without effect, and is the line's again once that went, as when the pick
|
||||
// that made it partial was taken off.
|
||||
func (b *batch) keepRecordedPartials(head string) error {
|
||||
if !b.src.open || b.src.rec == nil {
|
||||
return nil
|
||||
}
|
||||
for _, p := range b.src.rec.Parked {
|
||||
v := b.find(p.Original)
|
||||
if p.Kind != parkPartial || v == nil || v.rule != 0 || v.onBatch != "" || v.park != nil || v.o.merge != p.Merge {
|
||||
continue
|
||||
}
|
||||
if err := b.partialAt(v, head); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// rejudged reads again what partialStates and analyze read for v once its
|
||||
// rules changed, as a withdrawn drop changes them: it is back where the
|
||||
// line puts it.
|
||||
func (b *batch) rejudged(v *verdict) error {
|
||||
if b.pr != nil {
|
||||
on, err := b.unitsOn(b.prHead)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.batched = on[v]
|
||||
if v.rule == 0 && v.onBatch == "" {
|
||||
v.onBatch = on[v]
|
||||
}
|
||||
}
|
||||
if v.rule != 0 || v.onBatch != "" {
|
||||
return nil
|
||||
}
|
||||
if err := b.partialAt(v, b.lineHead); err != nil {
|
||||
return err
|
||||
}
|
||||
deps, diag, err := b.dependencies(v, b.lineHead)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.deps = deps
|
||||
v.addDiag(diag...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// partialAt judges v's clean net merge onto head, and parks it, or clears
|
||||
// the park, by what that merge leaves without effect.
|
||||
func (b *batch) partialAt(v *verdict, head string) error {
|
||||
|
||||
@@ -381,6 +381,22 @@ func TestFoldRefusesAKeptDeletion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// An original parked for what it builds on can still land as a complete
|
||||
// hand adaptation: every file it changes, changed, in the batch's shape.
|
||||
func TestFoldAcceptsACompleteAdaptationOfAParkedOriginal(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(3, "feat(app): a loud two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
mc5 := f.pr(5, "fix(app): an excited two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
w := emptyBatch(f, &fakeGH{}, "")
|
||||
pick := w.pick(w.head, f.git("rev-parse", mc5+"^2"), map[string]string{"app/a.txt": strings.Replace(appFile, "two", "two!", 1)})
|
||||
fold := w.merge(w.head, pick, "fix(app): an excited two (#5)\n\n"+batchTrailer+": "+mc5)
|
||||
if code, out, stderr := f.exec(w.gh, "fold", "--line", "release-1.1", "--original", "5", "--commit", fold); code != 0 || out != "ok\n" {
|
||||
t.Errorf("fold of an adaptation of #5 = %d, %q\n%s", code, out, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// A fold that keeps a file the original deletes leaves the deletion without
|
||||
// effect, whatever it changes in the file: a port that keeps what the line
|
||||
// made of it, or the file with a line added, is a pull request of its own.
|
||||
|
||||
@@ -207,8 +207,11 @@ type verdict struct {
|
||||
// and by load for anything else.
|
||||
commits []string
|
||||
changes []fileChange
|
||||
// onBatch is the commit of the open batch pull request that picks it.
|
||||
// onBatch is the commit of the open batch pull request that picks it,
|
||||
// and batched the unit of the open batch that carries it whatever the
|
||||
// rules now say of it.
|
||||
onBatch string
|
||||
batched string
|
||||
// label is the maintainer override the original carries, if any.
|
||||
label string
|
||||
// partial lists what its clean net merge onto the line would leave
|
||||
@@ -268,6 +271,10 @@ type batch struct {
|
||||
ancestors map[string]bool
|
||||
// detecting is how long judging partial units and dependencies took.
|
||||
detecting time.Duration
|
||||
depCache map[string][]dependency
|
||||
// lineCarries says, for a prerequisite the rules keep out, whether the
|
||||
// line carries it all the same.
|
||||
lineCarries map[*verdict]bool
|
||||
}
|
||||
|
||||
// fetch moves to the top of the working tree first: every path the batch
|
||||
@@ -374,6 +381,9 @@ func (a *app) prepare(l line) (*batch, error) {
|
||||
if b.drops, err = b.bindDrops(merges); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := b.waitOrder(merges); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, o := range merges {
|
||||
v := &verdict{o: o, label: labels[o.number]}
|
||||
if err := b.judge(v, b.drops); err != nil {
|
||||
|
||||
@@ -87,20 +87,42 @@ func (a *app) notify(args []string) int {
|
||||
return a.fail(err)
|
||||
}
|
||||
deferred := map[int]deferredEntry{}
|
||||
var partial []int
|
||||
if src.open {
|
||||
deferred = src.rec.deferred()
|
||||
deferred, partial = src.rec.deferred(), src.rec.Partial
|
||||
}
|
||||
// An original that waits on others is listed once, after what decides
|
||||
// its wait, where that one is listed.
|
||||
var conflicts, waiting []int
|
||||
after := map[int][]int{}
|
||||
for n, e := range deferred {
|
||||
switch {
|
||||
case e.Workflows:
|
||||
switch place := placement(deferred, n, map[int]bool{}); {
|
||||
case place == "workflow":
|
||||
waiting = append(waiting, n)
|
||||
case e.Reason == "":
|
||||
case place == "conflict":
|
||||
conflicts = append(conflicts, n)
|
||||
}
|
||||
if len(e.Needs) > 0 {
|
||||
after[n] = e.Needs
|
||||
}
|
||||
}
|
||||
slices.Sort(conflicts)
|
||||
slices.Sort(waiting)
|
||||
item := func(n int) string {
|
||||
if needs := after[n]; len(needs) > 0 {
|
||||
return fmt.Sprintf("\n- %s, after %s", prLink(n), prLinks(needs))
|
||||
}
|
||||
return "\n- " + prLink(n)
|
||||
}
|
||||
count := func(ns []int) int {
|
||||
c := 0
|
||||
for _, n := range ns {
|
||||
if len(after[n]) == 0 {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
today := a.now().UTC().Truncate(24 * time.Hour)
|
||||
days := int(today.Sub(opened).Hours() / 24)
|
||||
@@ -110,21 +132,34 @@ func (a *app) notify(args []string) int {
|
||||
fmt.Fprintf(a.stdout, "%s: batch pull request #%d has been open since %s, %d days\n", l.branch(), pr.Number, opened.Format(time.DateOnly), days)
|
||||
text = append(text, fmt.Sprintf("This batch has been open since %s, %d days, through at least one scheduled run. Merge it, or close it and the next run starts a new one; until then each run adds what the rules take to it.", opened.Format(time.DateOnly), days))
|
||||
}
|
||||
if len(conflicts) > 0 {
|
||||
fmt.Fprintf(a.stdout, "%s: %d deferred conflicts on #%d wait for a maintainer\n", l.branch(), len(conflicts), pr.Number)
|
||||
if len(partial) > 0 {
|
||||
fmt.Fprintf(a.stdout, "%s: %d units on #%d carry only part of their originals\n", l.branch(), len(partial), pr.Number)
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "These conflicts wait for a maintainer, as [resolving a conflict](%sresolve-conflict.md) describes; unresolved, each goes to the next batch:\n", tasksURL)
|
||||
b.WriteString("These are on the batch but carry only part of their originals on this line; take each out with `backport-batch run --defer` before the cut, and port what applies as a pull request of its own:\n")
|
||||
for _, n := range partial {
|
||||
b.WriteString(item(n))
|
||||
}
|
||||
text = append(text, b.String())
|
||||
}
|
||||
if len(conflicts) > 0 {
|
||||
fmt.Fprintf(a.stdout, "%s: %d deferred conflicts on #%d wait for a maintainer\n", l.branch(), count(conflicts), pr.Number)
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "These conflicts wait for a maintainer, as [resolving a conflict](%sresolve-conflict.md) describes; unresolved, each goes to the next batch, and so does what waits on one:\n", tasksURL)
|
||||
for _, n := range conflicts {
|
||||
fmt.Fprintf(&b, "\n- %s", prLink(n))
|
||||
b.WriteString(item(n))
|
||||
}
|
||||
text = append(text, b.String())
|
||||
}
|
||||
if len(waiting) > 0 {
|
||||
fmt.Fprintf(a.stdout, "%s: %d originals on #%d change %s and wait for a maintainer\n", l.branch(), len(waiting), pr.Number, workflowsDir)
|
||||
if count(waiting) == len(waiting) {
|
||||
fmt.Fprintf(a.stdout, "%s: %d originals on #%d change %s and wait for a maintainer\n", l.branch(), len(waiting), pr.Number, workflowsDir)
|
||||
} else {
|
||||
fmt.Fprintf(a.stdout, "%s: %d originals on #%d change %s or wait on one that does\n", l.branch(), len(waiting), pr.Number, workflowsDir)
|
||||
}
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "These change `%s`, which the batch's token may not push, and wait for a maintainer to bring them over, as [changes to workflows](%s#changes-to-workflows) describes:\n", workflowsDir, policyURL)
|
||||
fmt.Fprintf(&b, "These change `%s`, which the batch's token may not push, and wait for a maintainer to bring them over, as [changes to workflows](%s#changes-to-workflows) describes, or wait on one that does:\n", workflowsDir, policyURL)
|
||||
for _, n := range waiting {
|
||||
fmt.Fprintf(&b, "\n- %s", prLink(n))
|
||||
b.WriteString(item(n))
|
||||
}
|
||||
text = append(text, b.String())
|
||||
}
|
||||
@@ -134,6 +169,36 @@ func (a *app) notify(args []string) int {
|
||||
return a.comment(pr, *mention, today, text)
|
||||
}
|
||||
|
||||
// placement says under which list notify names original n of the record:
|
||||
// workflow for a wait for a maintainer, conflict for a deferred conflict, ""
|
||||
// for neither, a deferral for a reason among them. One that waits on others
|
||||
// goes where what decides its wait goes, followed down the record; one that
|
||||
// is not in the record is held by rule 6 or missing, and waits on nobody.
|
||||
func placement(deferred map[int]deferredEntry, n int, seen map[int]bool) string {
|
||||
e, ok := deferred[n]
|
||||
switch {
|
||||
case !ok || seen[n]:
|
||||
return ""
|
||||
case e.Workflows:
|
||||
return "workflow"
|
||||
case e.Reason != "":
|
||||
return ""
|
||||
case len(e.Needs) == 0:
|
||||
return "conflict"
|
||||
}
|
||||
seen[n] = true
|
||||
place := ""
|
||||
for _, f := range e.Needs {
|
||||
switch p := placement(deferred, f, seen); {
|
||||
case p == "workflow":
|
||||
return p
|
||||
case p == "conflict":
|
||||
place = p
|
||||
}
|
||||
}
|
||||
return place
|
||||
}
|
||||
|
||||
// comment writes what waits into the one notify comment on the batch pull
|
||||
// request: it edits the comment if there is one, and opens it only when
|
||||
// something waits. Only a comment by an author the batch trusts is taken for
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -198,6 +199,263 @@ func TestOnBatchAfterAnEmptyFirstPick(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// featWorld is #5071's shape: #3, a feat the line never gets, adds a file,
|
||||
// and #5 fixes that file; #6 is a plain fix beside it.
|
||||
func featWorld(t *testing.T) *fixture {
|
||||
t.Helper()
|
||||
f := newFixture(t)
|
||||
f.lines()
|
||||
f.pr(3, "feat(app): tap", "", map[string]string{"app/tap.go": appFile})
|
||||
f.pr(5, "fix(app): fix the tap", "```release-note\nfix(app): the tap works.\n```\n", map[string]string{"app/tap.go": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
return f
|
||||
}
|
||||
|
||||
// A fix of a file a feat added on main, which the line never gets, is
|
||||
// parked, not tried, and check takes the park as a note.
|
||||
func TestParkAFixOfAFeatureTheLineLacks(t *testing.T) {
|
||||
f := featWorld(t)
|
||||
gh := &fakeGH{}
|
||||
code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--push")
|
||||
if code != 0 {
|
||||
t.Fatalf("run --push = %d\n%s", code, stderr)
|
||||
}
|
||||
if strings.Contains(stdout, "### Deferred conflicts") || !strings.Contains(stdout, `"parked":[{"original":5,`) || !strings.Contains(stdout, `"kind":"dependency","needs":[3]`) {
|
||||
t.Errorf("#5 is not parked on #3:\n%s", stdout)
|
||||
}
|
||||
if !strings.Contains(stdout, "### Parked") || !strings.Contains(stdout, "builds on [#3]") {
|
||||
t.Errorf("the body does not say #5 builds on #3:\n%s", stdout)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
code, stdout, stderr = f.exec(gh, "check", "--line", "release-1.1")
|
||||
if code != 0 || !strings.Contains(stderr, "note: #5 is parked: it builds on #3, which never reaches release-1.1") {
|
||||
t.Errorf("check = %d, want 0 with a note that #5 is parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// backport/include lifts no park.
|
||||
func TestIncludeDoesNotLiftThePark(t *testing.T) {
|
||||
f := featWorld(t)
|
||||
code, stdout, stderr := f.exec(&fakeGH{labels: map[string][]int{labelInclude: {5}}}, "run", "--line", "release-1.1")
|
||||
if code != 0 || !strings.Contains(stdout, `"parked":[{"original":5,`) || !strings.Contains(stdout, "`backport/include`, parked: builds on") {
|
||||
t.Errorf("run with backport/include on #5 = %d, want #5 still parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// A prerequisite that is itself parked, but adapted onto the batch by hand,
|
||||
// satisfies what builds on it: #3 is parked on #2, a feat, and #5 changes a
|
||||
// line #3 wrote.
|
||||
func TestAdaptedPrerequisiteSatisfiesItsDependent(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a and b", "", map[string]string{"app/a.txt": appFile, "app/b.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(20, "feat(app): a loud two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
mc3 := f.pr(3, "fix(app): an excited two, a loud three", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1), "app/b.txt": strings.Replace(appFile, "three", "THREE", 1)})
|
||||
f.pr(5, "fix(app): an excited three", "", map[string]string{"app/b.txt": strings.Replace(appFile, "three", "THREE!", 1)})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1"); code != 0 || !strings.Contains(stdout, `"kind":"dependency","needs":[3]`) {
|
||||
t.Fatalf("run = %d, want #5 parked as long as #3 is:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
w := emptyBatch(f, &fakeGH{}, "batch\n\n"+deferredBlock(line11, nil, nil, nil)+"\n")
|
||||
// #3 adapted by hand: every file it changes, changed, in the batch's
|
||||
// shape.
|
||||
pick := w.pick(w.head, f.git("rev-parse", mc3+"^2"), map[string]string{"app/a.txt": strings.Replace(appFile, "two", "two!", 1), "app/b.txt": strings.Replace(appFile, "three", "THREE", 1)})
|
||||
fold := w.merge(w.head, pick, "fix(app): an excited two, a loud three (#3)\n\n"+batchTrailer+": "+mc3)
|
||||
f.git("push", "-q", "origin", fold+":refs/heads/"+batchBranch1)
|
||||
w.gh.prs = []pullRequest{f.batchPR(90, "release-1.1", batchBranch1, w.gh.prs[0].Body)}
|
||||
code, stdout, stderr := f.exec(w.gh, "check", "--line", "release-1.1")
|
||||
if code != 1 || strings.Contains(stderr, "#5 is parked") || strings.Contains(stdout+stderr, "waits on") || !strings.Contains(stdout, "/pull/5 ") {
|
||||
t.Errorf("check = %d, want #5 missing, not parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
code, stdout, stderr = f.exec(w.gh, "run", "--line", "release-1.1", "--continue")
|
||||
if code != 0 || !strings.Contains(stdout, `"picked":[3,5]`) {
|
||||
t.Errorf("run --continue = %d, want #5 picked after #3's adaptation:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// What an earlier unit of the batch brought counts: #3 writes the line #8
|
||||
// changes, a feat takes it back and another feat, #6, writes it again, so
|
||||
// blame names #6, which never comes; once #3 is picked the branch has the
|
||||
// line all the same.
|
||||
func TestContentFromAnotherUnitSatisfies(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(3, "fix(app): a loud two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(4, "feat(app): a quiet two", "", map[string]string{"app/a.txt": appFile})
|
||||
f.pr(6, "feat(app): a loud two again", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(8, "fix(app): an excited two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1")
|
||||
if code != 0 {
|
||||
t.Fatalf("run = %d\n%s", code, stderr)
|
||||
}
|
||||
if got := f.subjects("origin/release-1.1", "HEAD"); !slices.Equal(got, []string{"fix(app): a loud two (#3)", "fix(app): an excited two (#8)"}) {
|
||||
t.Errorf("picked %q, want #3 and #8:\n%s", got, stdout)
|
||||
}
|
||||
}
|
||||
|
||||
// auxWorld is #5142's shape: #3, a feat, adds a bats test; #5 fixes a
|
||||
// workflow and that test, so all it builds on that never comes is a test;
|
||||
// #6 is a plain fix.
|
||||
func auxWorld(t *testing.T) *fixture {
|
||||
t.Helper()
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a workflow", "", map[string]string{".github/workflows/release.yaml": "on: push\njobs: {}\n"})
|
||||
f.lines()
|
||||
f.pr(3, "feat(ci): test the changelog", "", map[string]string{"hack/changelog.bats": "@test x {\n true\n}\n"})
|
||||
f.pr(5, "fix(ci): run the release on tags", "", map[string]string{".github/workflows/release.yaml": "on: [push, tag]\njobs: {}\n", "hack/changelog.bats": "@test x {\n false\n}\n"})
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
return f
|
||||
}
|
||||
|
||||
// A workflow original whose only missing dependency is a test waits for a
|
||||
// maintainer in the scheduled run, whose token cannot push workflows, and
|
||||
// check holds the cut on it. A maintainer's own run parks it. With no batch
|
||||
// open, or one whose body carries no record, it is missing; a record from
|
||||
// before the mode was saved says the scheduled mode by listing a wait.
|
||||
func TestWorkflowModeCarriesToCheck(t *testing.T) {
|
||||
f := auxWorld(t)
|
||||
gh := &fakeGH{}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--no-workflow-files", "--push"); code != 0 || strings.Contains(stdout, `"parked":[{`) || !strings.Contains(stdout, `{"original":5,"files":[".github/workflows/release.yaml"],"workflows":true}`) {
|
||||
t.Fatalf("scheduled run = %d, want #5 waiting, not parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1", "--cut"); code != 1 || !strings.Contains(stdout, "#5 changes .github/workflows/ and waits on batch PR #90") {
|
||||
t.Errorf("check --cut = %d, want #5 waiting:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
v1 := "batch\n\n" + deferredBlock(line11, nil, nil, []pick{{v: &verdict{o: &original{number: 5}}, files: []string{".github/workflows/release.yaml"}}}) + "\n"
|
||||
gh.prs = []pullRequest{f.batchPR(90, "release-1.1", batchBranch1, v1)}
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1", "--cut"); code != 1 || !strings.Contains(stdout, "#5 changes .github/workflows/ and waits on batch PR #90") {
|
||||
t.Errorf("check --cut with a version 1 record = %d, want #5 waiting:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
gh.prs = []pullRequest{f.batchPR(90, "release-1.1", batchBranch1, "a batch someone wrote")}
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 1 || !strings.Contains(stdout, "/pull/5 ") || strings.Contains(stderr, "parked") {
|
||||
t.Errorf("check under a batch with no record = %d, want #5 missing:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
|
||||
f = auxWorld(t)
|
||||
if code, stdout, stderr := f.exec(nil, "check", "--line", "release-1.1"); code != 1 || !strings.Contains(stdout, "/pull/5 ") || strings.Contains(stderr, "parked") {
|
||||
t.Errorf("check with no batch = %d, want #5 missing:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
gh = &fakeGH{}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--push"); code != 0 || !strings.Contains(stdout, `"parked":[{"original":5,`) {
|
||||
t.Fatalf("a maintainer's run = %d, want #5 parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 0 || !strings.Contains(stderr, "note: #5 is parked") {
|
||||
t.Errorf("check after a maintainer's run = %d, want 0 with #5 parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// Evidence found only in a test file still parks an original that changes
|
||||
// no workflow: #4973's shape.
|
||||
func TestTestOnlyEvidenceParksOtherOriginals(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: nodes", "", map[string]string{"app/nodes.go": "package app\n", "app/nodes_test.go": "package app\n\nfunc a() {}\n"})
|
||||
f.lines()
|
||||
f.pr(3, "feat(app): proxmox nodes", "", map[string]string{"app/nodes_test.go": "package app\n\nfunc a() { proxmox() }\n"})
|
||||
f.pr(5, "fix(app): nodes", "", map[string]string{"app/nodes.go": "package app\n\nvar fixed = true\n", "app/nodes_test.go": "package app\n\nfunc a() { proxmox(); fixed() }\n"})
|
||||
code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1")
|
||||
if code != 0 || strings.Contains(stdout, "### Deferred conflicts") || !strings.Contains(stdout, `"parked":[{"original":5,`) {
|
||||
t.Errorf("run = %d, want #5 parked on #3:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// What an original builds on through lines it adds is not seen: #4973's
|
||||
// $isProxmox. The original is picked; CI on the batch is what catches it.
|
||||
func TestAddedLinesDependencyIsNotSeen(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: nodes", "", map[string]string{"app/nodes.tpl": "a\nb\n"})
|
||||
f.lines()
|
||||
f.pr(3, "feat(app): define isProxmox", "", map[string]string{"app/proxmox.tpl": "isProxmox\n"})
|
||||
f.pr(5, "fix(app): use isProxmox", "", map[string]string{"app/nodes.tpl": "a\nif isProxmox\nb\n"})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1"); code != 0 || strings.Contains(stdout, `"parked":[{`) || !strings.Contains(stdout, `"picked":[5]`) {
|
||||
t.Errorf("run = %d, want #5 picked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// With no batch open, check reads a closed record whatever its version and
|
||||
// whatever mode it saved as the scheduled run's: the workflow original it
|
||||
// left waiting is missing, not parked, while its drops and its other
|
||||
// deferrals still count.
|
||||
func TestClosedRecordModeFallback(t *testing.T) {
|
||||
for _, version := range []int{2, 3} {
|
||||
for _, saved := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("version %d, noWorkflowFiles %v", version, saved), func(t *testing.T) {
|
||||
f := auxWorld(t)
|
||||
mc6 := f.git("log", "--first-parent", "--format=%H", "-1", "--grep", "(#6)$", "main")
|
||||
mc7 := f.pr(7, "fix(app): seven", "", map[string]string{"app/seven.txt": "7\n"})
|
||||
sha := f.git("rev-parse", "origin/main")
|
||||
rec := lineRecord{Version: version, Line: "release-1.1", Report: strings.Repeat("b", 64),
|
||||
Built: &builtFrom{Main: sha, Line: sha, Policy: sha, Batch: sha, At: "2026-10-26T06:00:00Z", Options: runOptions{NoWorkflowFiles: saved, Mode: modeContinue}},
|
||||
Deferred: []deferredEntry{{Original: 5, Files: []string{".github/workflows/release.yaml"}, Workflows: true}, {Original: 7, Commit: f.git("rev-parse", mc7+"^2"), Files: []string{"app/seven.txt"}}},
|
||||
Dropped: []droppedEntry{{Original: 6, Merge: mc6, Reason: "not for this line", On: 90, Date: "2026-10-26"}}, Stale: []int{}}
|
||||
pr := f.batchPR(90, "release-1.1", batchBranch1, "batch\n\n"+recordBlock(rec)+"\n")
|
||||
at := "2026-10-26T12:00:00Z"
|
||||
pr.State, pr.MergedAt = "closed", &at
|
||||
code, stdout, stderr := f.exec(&fakeGH{prs: []pullRequest{pr}}, "check", "--line", "release-1.1")
|
||||
if code != 1 || !strings.Contains(stdout, "/pull/5 ") || strings.Contains(stderr, "#5 is parked") {
|
||||
t.Errorf("check = %d, want #5 missing and not parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "note: #6 is dropped") || !strings.Contains(stderr, "warning: deferred conflict on #90 (merged): https://github.com/cozystack/cozystack/pull/7 ") {
|
||||
t.Errorf("check lost the closed record's drop or deferral:\n%s", stderr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Withdrawing a drop puts the original back where the rules and the line
|
||||
// put it: a partial original is parked again, in the record as in check.
|
||||
func TestUndropRestoresThePark(t *testing.T) {
|
||||
for name, world := range map[string]func(*testing.T) *fixture{
|
||||
"partial": func(t *testing.T) *fixture {
|
||||
f, _ := policyWorld(t)
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
return f
|
||||
},
|
||||
"dependency": featWorld,
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
f := world(t)
|
||||
gh := &fakeGH{}
|
||||
openBatch(t, f, gh)
|
||||
mustRun(t, f, gh, "run", "--line", "release-1.1", "--drop", "5", "--reason", "not for 1.1", "--push")
|
||||
reopen(f, gh)
|
||||
mustRun(t, f, gh, "run", "--line", "release-1.1", "--undrop", "5", "--push")
|
||||
reopen(f, gh)
|
||||
if rec := recordOf(t, gh); len(rec.Parked) != 1 || rec.Parked[0].Original != 5 || rec.Parked[0].Kind != name {
|
||||
t.Errorf("after the undrop the record parks %+v, want #5 parked %s", rec.Parked, name)
|
||||
}
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 0 || !strings.Contains(stderr, "note: #5 is parked") {
|
||||
t.Errorf("check = %d, want #5 parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A prerequisite the open batch carries is there for what builds on it,
|
||||
// whatever its label now says: check and run agree that #7 is not parked.
|
||||
func TestPrerequisiteStillOnTheBatchSatisfies(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
gh := &fakeGH{}
|
||||
openBatch(t, f, gh)
|
||||
f.pr(7, "fix(app): seven", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
gh.labels = map[string][]int{labelSkip: {5}}
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 1 || strings.Contains(stderr, "#7 is parked") || !strings.Contains(stdout, "/pull/7 ") {
|
||||
t.Errorf("check = %d, want #7 missing, not parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--continue"); code != 0 || !strings.Contains(stdout, `"picked":[7]`) {
|
||||
t.Errorf("run --continue = %d, want #7 picked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// The picker judges what its picks did where the run has got to: #4
|
||||
// deletes the file #5 also deletes, so after #4 #5 would bring only its
|
||||
// test, which the net merge at the line's head cannot see.
|
||||
@@ -231,6 +489,64 @@ func TestPartialClearedByAnEarlierPick(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A reason a person deferred an original for comes before its partial
|
||||
// park.
|
||||
func TestReasonComesBeforeThePartialPark(t *testing.T) {
|
||||
f, _ := policyWorld(t)
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
gh := &fakeGH{}
|
||||
openBatch(t, f, gh)
|
||||
mustRun(t, f, gh, "run", "--line", "release-1.1", "--defer", "5", "--reason", "waits for the policy rework", "--push")
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 0 || !strings.Contains(stderr, "warning: deferred on #90 to the next batch: https://github.com/cozystack/cozystack/pull/5 ") || strings.Contains(stderr, "#5 is parked") {
|
||||
t.Errorf("check = %d, want #5 deferred for its reason:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// The workflow exception holds only while what never comes is tests or
|
||||
// docs, and while the workflow lines build on nothing missing: a
|
||||
// workflow original that also fixes a file a feat added, or whose workflow
|
||||
// line another original still to come wrote, parks in the scheduled run too.
|
||||
func TestWorkflowExceptionNeedsTestsOnly(t *testing.T) {
|
||||
t.Run("a never dependency outside tests", func(t *testing.T) {
|
||||
f := auxWorld(t)
|
||||
f.pr(20, "feat(app): tap", "", map[string]string{"app/tap.go": appFile})
|
||||
f.pr(7, "fix(ci): test the tap, and fix it", "", map[string]string{".github/workflows/tap.yaml": "on: push\n", "app/tap.go": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1", "--no-workflow-files"); code != 0 || !strings.Contains(stdout, `"parked":[{"original":7,`) {
|
||||
t.Errorf("scheduled run = %d, want #7 parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
t.Run("a workflow line still to come", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a workflow", "", map[string]string{".github/workflows/release.yaml": "on: push\njobs: {}\n", "app/four.txt": "old\n"})
|
||||
f.lines()
|
||||
f.onLine("release-1.1", "fix(app): four, the line's way", map[string]string{"app/four.txt": "line\n"})
|
||||
f.pr(3, "feat(ci): test the changelog", "", map[string]string{"hack/changelog.bats": "@test x {\n true\n}\n"})
|
||||
f.pr(4, "fix(ci): four", "", map[string]string{"app/four.txt": "four\n", ".github/workflows/release.yaml": "on: [push]\njobs: {}\n"})
|
||||
f.pr(5, "fix(ci): run the release on tags", "", map[string]string{".github/workflows/release.yaml": "on: [push, tag]\njobs: {}\n", "hack/changelog.bats": "@test x {\n false\n}\n"})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1", "--no-workflow-files"); code != 0 || !strings.Contains(stdout, `"parked":[{"original":5,`) {
|
||||
t.Errorf("scheduled run = %d, want #5 parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// What a rebuild takes off the batch is no longer there for what builds on
|
||||
// it: deferring #5 makes #7, which merged after the batch was built, wait
|
||||
// on it.
|
||||
func TestRebuildTakesThePrerequisiteAway(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
gh := &fakeGH{}
|
||||
openBatch(t, f, gh)
|
||||
f.pr(7, "fix(app): seven", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--defer", "5", "--reason", "fails the e2e"); code != 0 || !strings.Contains(stdout, `{"original":7,"files":[],"needs":[5]}`) {
|
||||
t.Errorf("run --defer 5 = %d, want #7 waiting on #5:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// A file the line renamed the way the original does is the original's own
|
||||
// rename, not a deletion left without effect.
|
||||
func TestSameRenameOnBothSidesIsWhole(t *testing.T) {
|
||||
@@ -245,6 +561,54 @@ func TestSameRenameOnBothSidesIsWhole(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A partial park only the picker saw, where the net merge at the line's
|
||||
// head looks whole, holds in check and in the operations that pick nothing
|
||||
// as the open record keeps it: check does not call the original missing.
|
||||
func TestPickerParkHoldsInCheck(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a policy", "", map[string]string{"app/policy.yaml": "allow: all\n"})
|
||||
f.lines()
|
||||
f.pr(4, "fix(app): drop the policy", "", map[string]string{"app/policy.yaml": "", "app/four.txt": "4\n"})
|
||||
f.pr(40, "feat(app): the policy again", "", map[string]string{"app/policy.yaml": "allow: all\n"})
|
||||
f.pr(5, "fix(app): drop the policy and test it", "", map[string]string{"app/policy.yaml": "", "app/policy_test.txt": "gone\n"})
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
gh := &fakeGH{}
|
||||
openBatch(t, f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 0 || !strings.Contains(stderr, "note: #5 is parked: only part of it applies") {
|
||||
t.Errorf("check = %d, want #5 parked as the record says:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--defer", "6", "--reason", "fails the e2e"); code != 0 || !strings.Contains(stdout, `"parked":[{"original":5,`) {
|
||||
t.Errorf("run --defer 6 = %d, want #5 still parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
// Deferring #4, which made #5 partial, ends the park: #5 applies whole
|
||||
// on what the batch carries now.
|
||||
f.git("switch", "-q", "main")
|
||||
code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--defer", "4", "--reason", "fails the e2e", "--push")
|
||||
if code != 0 || strings.Contains(stdout, `"parked":[{`) || !strings.Contains(stdout, `"missing":[5]`) {
|
||||
t.Errorf("run --defer 4 = %d, want #5 missing, no longer parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 1 || strings.Contains(stderr, "#5 is parked") || !strings.Contains(stdout, "/pull/5 ") {
|
||||
t.Errorf("check after deferring #4 = %d, want #5 missing:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// A workflow original that waits for a maintainer only as the open record
|
||||
// lists it: one merged since the batch was built is missing, and so is
|
||||
// what waits on it.
|
||||
func TestUnlistedWorkflowWaitIsMissing(t *testing.T) {
|
||||
f := auxWorld(t)
|
||||
gh := &fakeGH{}
|
||||
mustRun(t, f, gh, "run", "--line", "release-1.1", "--no-workflow-files", "--push")
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
f.pr(8, "fix(ci): run the new release on tags", "", map[string]string{".github/workflows/new.yaml": "on: tag\n", "hack/changelog.bats": "@test x {\n false\n}\n# eight\n", "app/eight.txt": appFile + "TWO\n"})
|
||||
f.pr(9, "fix(app): nine", "", map[string]string{"app/eight.txt": appFile + "TWO!\n"})
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 1 || !strings.Contains(stdout, "/pull/9 fix(app): nine (it waits on #8, which is not on the line either)") {
|
||||
t.Errorf("check = %d, want #9 missing, waiting on #8:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// The line's own rename stands for the original's only with the original's
|
||||
// change in it: a fold that leaves the renamed file as it was is refused.
|
||||
func TestSameRenameStillNeedsItsFix(t *testing.T) {
|
||||
@@ -262,6 +626,47 @@ func TestSameRenameStillNeedsItsFix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A prerequisite the line carries is there, though the rules would keep it
|
||||
// out: a feat carried by a hand adaptation does not park what builds on it.
|
||||
func TestCarriedExcludedPrerequisiteSatisfies(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
mc3 := f.pr(3, "feat(app): a loud two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.onLine("release-1.1", "feat(app): a loud two, adapted\n\n(cherry picked from commit "+mc3+")", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "Two", 1)})
|
||||
f.pr(5, "fix(app): an excited two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1"); code != 0 || strings.Contains(stdout, `"parked":[{`) {
|
||||
t.Errorf("run = %d, want #5 not parked on the carried #3:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
if code, stdout, stderr := f.exec(nil, "check", "--line", "release-1.1"); code != 1 || strings.Contains(stderr, "#5 is parked") {
|
||||
t.Errorf("check = %d, want #5 missing, not parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// With no batch open, a workflow wait a closed record keeps waits on
|
||||
// nothing: the original is judged as the scheduled run judges it, so one
|
||||
// that also builds on a feat the line lacks is parked, in check as in run.
|
||||
func TestClosedWorkflowWaitIsJudgedAsRunJudgesIt(t *testing.T) {
|
||||
f := auxWorld(t)
|
||||
f.pr(20, "feat(app): tap", "", map[string]string{"app/tap.go": appFile})
|
||||
f.pr(7, "fix(ci): test the tap, and fix it", "", map[string]string{".github/workflows/tap.yaml": "on: push\n", "app/tap.go": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
sha := f.git("rev-parse", "origin/main")
|
||||
rec := lineRecord{Version: 2, Line: "release-1.1", Report: strings.Repeat("b", 64),
|
||||
Built: &builtFrom{Main: sha, Line: sha, Policy: sha, Batch: sha, At: "2026-10-26T06:00:00Z", Options: runOptions{NoWorkflowFiles: true, Mode: modeContinue}},
|
||||
Deferred: []deferredEntry{{Original: 7, Files: []string{".github/workflows/tap.yaml"}, Workflows: true}}, Dropped: []droppedEntry{}, Stale: []int{}}
|
||||
pr := f.batchPR(90, "release-1.1", batchBranch1, "batch\n\n"+recordBlock(rec)+"\n")
|
||||
at := "2026-10-26T12:00:00Z"
|
||||
pr.State, pr.MergedAt = "closed", &at
|
||||
gh := &fakeGH{prs: []pullRequest{pr}}
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1", "--cut"); strings.Contains(stdout, "/pull/7 ") || !strings.Contains(stderr, "note: #7 is parked: it builds on #20") {
|
||||
t.Errorf("check --cut = %d, want #7 parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--no-workflow-files"); code != 0 || !strings.Contains(stdout, `"parked":[{"original":7,`) {
|
||||
t.Errorf("scheduled run = %d, want #7 parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// A pick that comes out empty is judged too: #5's own commit did half its
|
||||
// fix, which the line has, and a merge of main into its branch did the
|
||||
// rest, which no pick carries; #5 is not on the line.
|
||||
@@ -305,6 +710,51 @@ func TestDeferTakesOffAPartialExcludedUnit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A stored wait on an original merged after the one that waits cannot be
|
||||
// what a run wrote.
|
||||
func TestForwardWaitIsRefused(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.lines()
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/five.txt": "5\n"})
|
||||
f.pr(7, "fix(app): seven", "", map[string]string{"app/seven.txt": "7\n"})
|
||||
sha := f.git("rev-parse", "origin/main")
|
||||
rec := lineRecord{Version: recordVersion, Line: "release-1.1", Report: strings.Repeat("b", 64),
|
||||
Built: &builtFrom{Main: sha, Line: sha, Policy: sha, Batch: sha, At: "2026-10-26T06:00:00Z", Options: runOptions{Mode: modeContinue}},
|
||||
Deferred: []deferredEntry{{Original: 5, Files: []string{}, Needs: []int{7}}}, Dropped: []droppedEntry{}, Stale: []int{}}
|
||||
f.git("push", "-q", "origin", "origin/release-1.1:refs/heads/"+batchBranch1)
|
||||
gh := &fakeGH{prs: []pullRequest{f.batchPR(90, "release-1.1", batchBranch1, "batch\n\n"+recordBlock(rec)+"\n")}}
|
||||
if code, _, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 2 || !strings.Contains(stderr, "#5 wait on #7") {
|
||||
t.Errorf("check = %d, want 2 for a wait on a later original:\n%s", code, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// The workflow exception looks only at what still keeps the original from
|
||||
// the line: a workflow line its prerequisite wrote, which the open batch
|
||||
// carries though that prerequisite is labelled backport/skip, does not
|
||||
// stop it, in check as in run.
|
||||
func TestWorkflowExceptionIgnoresWhatIsThere(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a workflow", "", map[string]string{".github/workflows/release.yaml": "on: push\njobs: {}\n"})
|
||||
f.lines()
|
||||
f.pr(3, "feat(ci): test the changelog", "", map[string]string{"hack/changelog.bats": "@test x {\n true\n}\n"})
|
||||
f.pr(4, "fix(ci): run the release on pushes", "", map[string]string{".github/workflows/release.yaml": "on: [push]\njobs: {}\n"})
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
f.pr(7, "fix(ci): run the release on tags too", "", map[string]string{".github/workflows/release.yaml": "on: [push, tag]\njobs: {}\n", "hack/changelog.bats": "@test x {\n false\n}\n"})
|
||||
gh := &fakeGH{}
|
||||
mustRun(t, f, gh, "run", "--line", "release-1.1", "--push")
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
gh.labels = map[string][]int{labelSkip: {4}}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--continue", "--no-workflow-files", "--push"); code != 0 || !strings.Contains(stdout, `{"original":7,"files":[".github/workflows/release.yaml"],"workflows":true}`) {
|
||||
t.Fatalf("scheduled run = %d, want #7 waiting for a maintainer:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1", "--cut"); code != 1 || !strings.Contains(stdout, "#7 changes .github/workflows/ and waits on batch PR #90") {
|
||||
t.Errorf("check --cut = %d, want #7 waiting, as run has it:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// An empty pick leaves a deletion undone that only a merge of main into the
|
||||
// original's branch made: the original is not on the line.
|
||||
func TestEmptyPickLeavesADeletionUndone(t *testing.T) {
|
||||
@@ -329,3 +779,18 @@ func TestEmptyPickLeavesADeletionUndone(t *testing.T) {
|
||||
t.Errorf("run = %d, want #5 parked as partial, not on the line:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// A file the line already has as the original makes it builds on nothing
|
||||
// the line lacks: #5 fixes a.txt, which the line fixed the same way, and
|
||||
// b.txt, so it picks whole and is not parked on the feat that wrote a.txt.
|
||||
func TestAlreadyAppliedFileBuildsOnNothing(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: a and b", "", map[string]string{"app/a.txt": appFile, "app/b.txt": "old\n"})
|
||||
f.lines()
|
||||
f.pr(3, "feat(app): a loud two", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.onLine("release-1.1", "fix(app): two, the line's way", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
f.pr(5, "fix(app): an excited two, and b", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1), "app/b.txt": "fixed\n"})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1"); code != 0 || strings.Contains(stdout, `"parked":[{`) || !strings.Contains(stdout, `"picked":[5]`) {
|
||||
t.Errorf("run = %d, want #5 picked, not parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -258,6 +259,9 @@ func parseRecord(body string, l line) (*lineRecord, error) {
|
||||
default:
|
||||
return nil, fmt.Errorf("the %s block is version %d, which this backport-batch does not read; it reads 1 to %d", deferredFence, version, recordVersion)
|
||||
}
|
||||
if err == nil && version < 3 && slices.ContainsFunc(rec.Deferred, func(d deferredEntry) bool { return d.Needs != nil }) {
|
||||
err = fmt.Errorf("version %d has no waits on other originals", version)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading the %s block: %w", deferredFence, err)
|
||||
}
|
||||
@@ -294,7 +298,7 @@ func (rec *lineRecord) validate(l line) error {
|
||||
// A conflict names the commit that failed and its files, a deferral
|
||||
// its reason, and a wait its workflow files.
|
||||
kinds := 0
|
||||
for _, is := range []bool{d.Commit != "" || len(d.Files) > 0 && !d.Workflows && d.Reason == "", d.Reason != "", d.Workflows} {
|
||||
for _, is := range []bool{d.Commit != "" || len(d.Files) > 0 && !d.Workflows && d.Reason == "" && len(d.Needs) == 0, d.Reason != "", d.Workflows, len(d.Needs) > 0} {
|
||||
if is {
|
||||
kinds++
|
||||
}
|
||||
@@ -312,6 +316,13 @@ func (rec *lineRecord) validate(l line) error {
|
||||
return fmt.Errorf("names files of #%d that are not as a run writes them: %q", d.Original, d.Files)
|
||||
case d.More < 0:
|
||||
return fmt.Errorf("counts %d more files for #%d", d.More, d.Original)
|
||||
case len(d.Needs) > 0 && (len(d.Files) > 0 || d.More != 0):
|
||||
return fmt.Errorf("has #%d wait on other originals with files of its own", d.Original)
|
||||
}
|
||||
for i, n := range d.Needs {
|
||||
if n <= 0 || n == d.Original || i > 0 && d.Needs[i-1] >= n {
|
||||
return fmt.Errorf("has #%d wait on %v, which is not what a run writes", d.Original, d.Needs)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, d := range rec.Dropped {
|
||||
@@ -347,6 +358,27 @@ func (rec *lineRecord) validate(l line) error {
|
||||
}
|
||||
changedSeen[n] = true
|
||||
}
|
||||
if err := rec.waitsHold(); err != nil {
|
||||
return err
|
||||
}
|
||||
// What is on the batch is neither deferred nor parked.
|
||||
left := map[int]bool{}
|
||||
for _, d := range rec.Deferred {
|
||||
left[d.Original] = true
|
||||
}
|
||||
for _, p := range rec.Parked {
|
||||
left[p.Original] = true
|
||||
if slices.Contains(p.Commits, p.Merge) {
|
||||
return fmt.Errorf("parks #%d for its own merge", p.Original)
|
||||
}
|
||||
}
|
||||
for _, list := range [][]int{rec.Partial, rec.Changed} {
|
||||
for _, n := range list {
|
||||
if left[n] {
|
||||
return fmt.Errorf("has #%d on the batch and left off it at once", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
partialSeen := map[int]bool{}
|
||||
for _, n := range rec.Partial {
|
||||
// A unit that does only part of its original is still on the batch.
|
||||
@@ -401,6 +433,74 @@ func (b *builtFrom) validate() error {
|
||||
|
||||
var runURLRE = regexp.MustCompile(`^https://[^/\s]+/[^/\s]+/[^/\s]+/actions/runs/[0-9]+(/attempts/[0-9]+)?$`)
|
||||
|
||||
// waitsHold holds what waits and parks need to what the record says of the
|
||||
// originals they need: a wait needs ones still to come, so none parked or
|
||||
// dropped, a park ones that never come, so none deferred, and no wait ends
|
||||
// up waiting on itself. Its errors read after "the block".
|
||||
func (rec *lineRecord) waitsHold() error {
|
||||
deferred, never := map[int][]int{}, map[int]bool{}
|
||||
for _, d := range rec.Deferred {
|
||||
deferred[d.Original] = d.Needs
|
||||
}
|
||||
for _, p := range rec.Parked {
|
||||
never[p.Original] = true
|
||||
}
|
||||
for _, d := range rec.Dropped {
|
||||
never[d.Original] = true
|
||||
}
|
||||
for _, d := range rec.Deferred {
|
||||
for _, n := range d.Needs {
|
||||
if never[n] {
|
||||
return fmt.Errorf("has #%d wait on #%d, which never comes", d.Original, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, p := range rec.Parked {
|
||||
for _, n := range p.Needs {
|
||||
if _, ok := deferred[n]; ok {
|
||||
return fmt.Errorf("parks #%d for #%d, which is still to come", p.Original, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
needs := map[int][]int{}
|
||||
for _, d := range rec.Deferred {
|
||||
needs[d.Original] = d.Needs
|
||||
}
|
||||
for _, p := range rec.Parked {
|
||||
needs[p.Original] = p.Needs
|
||||
}
|
||||
return waitCycle(needs)
|
||||
}
|
||||
|
||||
// waitCycle refuses waits that lead back to where they started, which no
|
||||
// run writes: a prerequisite merged before what needs it.
|
||||
func waitCycle(needs map[int][]int) error {
|
||||
state := map[int]int{} // 1 on the path, 2 done
|
||||
var visit func(n int) error
|
||||
visit = func(n int) error {
|
||||
switch state[n] {
|
||||
case 1:
|
||||
return fmt.Errorf("has #%d wait on itself through what it waits on", n)
|
||||
case 2:
|
||||
return nil
|
||||
}
|
||||
state[n] = 1
|
||||
for _, f := range needs[n] {
|
||||
if err := visit(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
state[n] = 2
|
||||
return nil
|
||||
}
|
||||
for _, n := range slices.Sorted(maps.Keys(needs)) {
|
||||
if err := visit(n); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// lineRecordWithout is a version 2 record as the newest version holds it.
|
||||
func lineRecordWithout(v2 lineRecordV2) lineRecord {
|
||||
return lineRecord{Version: v2.Version, Line: v2.Line, Built: v2.Built, Report: v2.Report, Closing: v2.Closing, Deferred: v2.Deferred, Dropped: v2.Dropped, Stale: v2.Stale}
|
||||
|
||||
@@ -380,10 +380,32 @@ func TestRecordVersion3(t *testing.T) {
|
||||
block := func(json string) string { return "text\n\n" + deferredFence + "\n" + json + "\n```\n" }
|
||||
sha, other := strings.Repeat("a", 40), strings.Repeat("c", 40)
|
||||
parked := `,"parked":[{"original":10,"merge":"` + sha + `","kind":"partial","files":["a","b"]},{"original":11,"merge":"` + sha + `","kind":"dependency","needs":[3,4],"commits":["` + other + `"],"announced":true}],"partial":[9]`
|
||||
rec, err := parseRecord(block(v3(parked)), l)
|
||||
if err != nil || rec.Version != 3 || len(rec.Parked) != 2 || !rec.Parked[1].Announced || !slices.Equal(rec.Partial, []int{9}) {
|
||||
waits := strings.Replace(v3(parked), `{"original":6,"files":[],"reason":"fails the e2e"}`, `{"original":6,"files":[],"needs":[3,5]}`, 1)
|
||||
rec, err := parseRecord(block(waits), l)
|
||||
if err != nil || rec.Version != 3 || len(rec.Parked) != 2 || !rec.Parked[1].Announced || !slices.Equal(rec.Partial, []int{9}) || !slices.Equal(rec.deferred()[6].Needs, []int{3, 5}) {
|
||||
t.Fatalf("parseRecord of a whole v3 record = %+v, %v", rec, err)
|
||||
}
|
||||
for name, json := range map[string]string{
|
||||
"version 1 with a wait": `{"line":"release-1.1","deferred":[{"original":6,"files":[],"needs":[3,5]}]}`,
|
||||
"a wait with files": strings.Replace(waits, `"files":[],"needs":[3,5]`, `"files":["a"],"needs":[3,5]`, 1),
|
||||
"a wait that is a conflict": strings.Replace(waits, `"files":[],"needs":[3,5]`, `"commit":"`+sha+`","files":[],"needs":[3,5]`, 1),
|
||||
"a wait on itself": strings.Replace(waits, `"needs":[3,5]`, `"needs":[3,6]`, 1),
|
||||
"an unsorted wait": strings.Replace(waits, `"needs":[3,5]`, `"needs":[5,3]`, 1),
|
||||
"a wait on nothing": strings.Replace(waits, `"needs":[3,5]`, `"needs":[0]`, 1),
|
||||
"a wait cycle": strings.Replace(strings.Replace(waits, `"needs":[3,5]`, `"needs":[12]`, 1), `"deferred":[`, `"deferred":[{"original":12,"files":[],"needs":[6]},`, 1),
|
||||
"a wait on a parked one": strings.Replace(waits, `"needs":[3,5]`, `"needs":[10]`, 1),
|
||||
"a wait on a dropped one": strings.Replace(waits, `"needs":[3,5]`, `"needs":[8]`, 1),
|
||||
"a park on a deferred one": strings.Replace(waits, `"needs":[3,4]`, `"needs":[3,5]`, 1),
|
||||
"a partial unit also deferred": strings.Replace(strings.Replace(waits, `"stale":[9]`, `"stale":[9,5]`, 1), `"partial":[9]`, `"partial":[9,5]`, 1),
|
||||
"a changed pick also parked": v3(parked + `,"changed":[10]`),
|
||||
"a changed pick also deferred": v3(parked + `,"changed":[5]`),
|
||||
"a park on its own merge": strings.Replace(waits, `"commits":["`+other+`"]`, `"commits":["`+sha+`"]`, 1),
|
||||
"a park cycle": strings.Replace(strings.Replace(waits, `"needs":[3,4]`, `"needs":[3,13]`, 1), `"parked":[`, `"parked":[{"original":13,"merge":"`+sha+`","kind":"dependency","needs":[11]},`, 1),
|
||||
} {
|
||||
if _, err := parseRecord(block(json), l); err == nil {
|
||||
t.Errorf("%s: parseRecord accepted it", name)
|
||||
}
|
||||
}
|
||||
for name, json := range map[string]string{
|
||||
"version 2 with a park": v2(parked),
|
||||
"version 4": strings.Replace(v3(""), `"version":3`, `"version":4`, 1),
|
||||
|
||||
@@ -145,7 +145,7 @@ func numbers(vs []*verdict) []int {
|
||||
|
||||
// deferredEntries is what the record and the report say about the conflicts,
|
||||
// the deferrals and the waits of a run.
|
||||
func deferredEntries(conflicts, held, waiting []pick) []deferredEntry {
|
||||
func deferredEntries(conflicts, held, waiting, needs []pick) []deferredEntry {
|
||||
out := []deferredEntry{}
|
||||
for _, p := range conflicts {
|
||||
files := cleanFiles(p.files[:min(len(p.files), filesKept)])
|
||||
@@ -158,6 +158,9 @@ func deferredEntries(conflicts, held, waiting []pick) []deferredEntry {
|
||||
files := cleanFiles(p.files[:min(len(p.files), filesKept)])
|
||||
out = append(out, deferredEntry{Original: p.v.o.number, Files: files, More: len(p.files) - len(files) + p.more, Workflows: true})
|
||||
}
|
||||
for _, p := range needs {
|
||||
out = append(out, deferredEntry{Original: p.v.o.number, Files: []string{}, Needs: slices.Sorted(slices.Values(p.needs))})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -188,7 +191,7 @@ func buildReport(b *batch, r *report) (reportDoc, error) {
|
||||
doc.Overrides.Skip = append(doc.Overrides.Skip, v.o.number)
|
||||
}
|
||||
}
|
||||
doc.Primary = reportPrimary{Picked: numbers(r.onBranch), Missing: numbers(r.missing), Deferred: deferredEntries(r.deferred, r.held, r.waiting), Parked: parkedEntries(r.parked)}
|
||||
doc.Primary = reportPrimary{Picked: numbers(r.onBranch), Missing: numbers(r.missing), Deferred: deferredEntries(r.deferred, r.held, r.waiting, r.needs), Parked: parkedEntries(r.parked)}
|
||||
for _, l := range doc.Primary.Skipped.lists() {
|
||||
*l.list = []int{}
|
||||
}
|
||||
@@ -415,6 +418,9 @@ func (d *reportDoc) links() error {
|
||||
return fmt.Errorf("parks #%d for #%d, which it has %s", p.Original, n, or(c, "nowhere"))
|
||||
}
|
||||
}
|
||||
if other[p.Merge] || slices.Contains(p.Commits, p.Merge) {
|
||||
return fmt.Errorf("parks #%d by a merge it counts as no pull request's, or for its own merge", p.Original)
|
||||
}
|
||||
for _, c := range p.Commits {
|
||||
if !other[c] {
|
||||
return fmt.Errorf("parks #%d for %.12s, which it does not count among main's commits that merged no pull request", p.Original, c)
|
||||
@@ -480,6 +486,28 @@ func (d *reportDoc) links() error {
|
||||
if e.Workflows && !d.Built.Options.NoWorkflowFiles {
|
||||
return fmt.Errorf("has #%d waiting for its workflow files, but was made bringing them over", e.Original)
|
||||
}
|
||||
// What a wait waits on is still to come: not on the line, deferred,
|
||||
// or held by rule 6.
|
||||
for _, n := range e.Needs {
|
||||
switch c := where[n]; c {
|
||||
case "missing", "deferred", "skipped.newer":
|
||||
default:
|
||||
return fmt.Errorf("has #%d wait on #%d, which it has %s", e.Original, n, or(c, "nowhere"))
|
||||
}
|
||||
}
|
||||
if d.Format == 1 && len(e.Needs) > 0 {
|
||||
return fmt.Errorf("has #%d wait on other originals, which format 1 does not", e.Original)
|
||||
}
|
||||
}
|
||||
needs := map[int][]int{}
|
||||
for _, e := range d.Primary.Deferred {
|
||||
needs[e.Original] = e.Needs
|
||||
}
|
||||
for _, p := range d.Primary.Parked {
|
||||
needs[p.Original] = p.Needs
|
||||
}
|
||||
if err := waitCycle(needs); err != nil {
|
||||
return err
|
||||
}
|
||||
if d.Built.Options.Mode == modeClose && len(d.Primary.Picked)+len(d.Overlays.Stale) > 0 {
|
||||
return errors.New("closes the batch, but still has originals on it")
|
||||
@@ -734,6 +762,12 @@ func (a *app) printReport(pr *pullRequest, s storedReport, inBody *storedReport,
|
||||
switch {
|
||||
case e.Workflows:
|
||||
text += "waits for a maintainer, changes " + strings.Join(e.Files, ", ")
|
||||
case len(e.Needs) > 0:
|
||||
var needs []string
|
||||
for _, n := range e.Needs {
|
||||
needs = append(needs, "#"+strconv.Itoa(n))
|
||||
}
|
||||
text += "waits on " + strings.Join(needs, ", ")
|
||||
case e.Reason != "":
|
||||
text += e.Reason
|
||||
default:
|
||||
|
||||
@@ -633,6 +633,27 @@ func TestReportRefusesWhatItCannotVouchFor(t *testing.T) {
|
||||
d.Primary.Parked = []parkedEntry{{Original: 16, Merge: strings.Repeat("b", 40), Kind: parkDependency, Commits: []string{strings.Repeat("c", 40)}}}
|
||||
},
|
||||
"a partial unit not on the batch": func(d *reportDoc) { d.Overlays.Partial = []int{5} },
|
||||
"a wait on an original it picks": func(d *reportDoc) {
|
||||
d.Primary.Deferred = []deferredEntry{{Original: 6, Files: []string{}, Needs: []int{5}}}
|
||||
},
|
||||
"a wait on an original it puts nowhere": func(d *reportDoc) {
|
||||
d.Primary.Deferred = []deferredEntry{{Original: 6, Files: []string{}, Needs: []int{19}}}
|
||||
},
|
||||
"a park on its own merge as a commit": func(d *reportDoc) {
|
||||
d.Other = append(d.Other, strings.Repeat("b", 40))
|
||||
d.Primary.Parked = []parkedEntry{{Original: 16, Merge: strings.Repeat("b", 40), Kind: parkDependency, Commits: []string{strings.Repeat("b", 40)}}}
|
||||
},
|
||||
"a park cycle": func(d *reportDoc) {
|
||||
d.Primary.Parked = []parkedEntry{{Original: 16, Merge: strings.Repeat("b", 40), Kind: parkDependency, Needs: []int{18}}, {Original: 18, Merge: strings.Repeat("b", 40), Kind: parkDependency, Needs: []int{16}}}
|
||||
},
|
||||
"a wait cycle": func(d *reportDoc) {
|
||||
d.Primary.Deferred = []deferredEntry{{Original: 6, Files: []string{}, Needs: []int{7}}, {Original: 7, Files: []string{}, Needs: []int{6}}}
|
||||
},
|
||||
"format 1 with a wait": func(d *reportDoc) {
|
||||
d.Format = 1
|
||||
d.Primary.Missing = []int{19}
|
||||
d.Primary.Deferred = []deferredEntry{{Original: 6, Files: []string{}, Needs: []int{19}}}
|
||||
},
|
||||
"format 1 with a park": func(d *reportDoc) {
|
||||
d.Format = 1
|
||||
d.Primary.Parked = []parkedEntry{{Original: 16, Merge: strings.Repeat("b", 40), Kind: parkPartial, Files: []string{"a"}}}
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
Copyright 2026 The Cozystack Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// chainWorld has #5 conflict on the line and change a shared line, and #7
|
||||
// change that line again: #7 builds on #5.
|
||||
func chainWorld(t *testing.T) (*fixture, string) {
|
||||
t.Helper()
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: five and shared", "", map[string]string{"app/five.txt": "old\n", "app/shared.txt": appFile})
|
||||
f.lines()
|
||||
f.onLine("release-1.1", "fix(app): five, the line's way", map[string]string{"app/five.txt": "line\n"})
|
||||
mc5 := f.pr(5, "fix(app): five", "", map[string]string{"app/five.txt": "five\n", "app/shared.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
f.pr(7, "fix(app): seven", "", map[string]string{"app/shared.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
return f, mc5
|
||||
}
|
||||
|
||||
// An original that builds on a deferred conflict waits for it: check warns,
|
||||
// notify lists it after the conflict, and once the conflict lands, the next
|
||||
// run picks it.
|
||||
func TestWaitForADeferredDependency(t *testing.T) {
|
||||
f, mc5 := chainWorld(t)
|
||||
gh := &fakeGH{}
|
||||
code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--push")
|
||||
if code != 0 {
|
||||
t.Fatalf("run --push = %d\n%s", code, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, `{"original":7,"files":[],"needs":[5]}`) || !strings.Contains(stdout, "### Waiting on another original") {
|
||||
t.Errorf("#7 does not wait on #5:\n%s", stdout)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
code, stdout, stderr = f.exec(gh, "check", "--line", "release-1.1")
|
||||
if code != 0 || !strings.Contains(stderr, "warning: #7 waits on #5, a deferred conflict on #90: https://github.com/cozystack/cozystack/pull/7 ") {
|
||||
t.Errorf("check = %d, want a warning that #7 waits on #5:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
code, stdout, _ = f.exec(gh, "notify", "--line", "release-1.1", "--push")
|
||||
if code != 0 || !strings.Contains(gh.issueComments[len(gh.issueComments)-1].Body, "- [#7](https://github.com/cozystack/cozystack/pull/7), after [#5](https://github.com/cozystack/cozystack/pull/5)") {
|
||||
t.Errorf("notify = %d, want #7 listed after #5:\n%s\n%v", code, stdout, gh.issueComments)
|
||||
}
|
||||
// The batch merges, and #5 lands on the line by hand, resolved: the
|
||||
// next batch picks #7.
|
||||
mergeBatch(f, gh)
|
||||
f.onLine("release-1.1", "fix(app): five (#5)\n\n(cherry picked from commit "+mc5+")", map[string]string{"app/five.txt": "five\n", "app/shared.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
code, stdout, stderr = f.exec(gh, "run", "--line", "release-1.1", "--continue")
|
||||
if code != 0 || !strings.Contains(stdout, `"picked":[7]`) {
|
||||
t.Errorf("run --continue after #5 landed = %d, want #7 picked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// Of several prerequisites still to come, the strongest decides: one not on
|
||||
// the line at all, then one waiting for a maintainer, then a conflict or a
|
||||
// deferral, then one rule 6 holds; a chain inherits what its end decides.
|
||||
func TestWaitReduction(t *testing.T) {
|
||||
t.Run("a conflict and a workflow wait", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/five.txt": "old\n", "app/a.txt": appFile, "app/b.txt": appFile})
|
||||
f.lines()
|
||||
f.onLine("release-1.1", "fix(app): five, the line's way", map[string]string{"app/five.txt": "line\n"})
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/five.txt": "five\n", "app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(6, "fix(ci): six", "", map[string]string{".github/workflows/six.yaml": "on: push\n", "app/b.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(7, "fix(app): seven", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1), "app/b.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
f.pr(8, "fix(app): eight", "", map[string]string{"app/eight.txt": "8\n"})
|
||||
gh := &fakeGH{}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--no-workflow-files", "--push"); code != 0 || !strings.Contains(stdout, `{"original":7,"files":[],"needs":[6]}`) {
|
||||
t.Fatalf("run = %d, want #7 waiting on #6 alone:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1", "--cut"); code != 1 || !strings.Contains(stdout, "#7 waits on #6, which changes .github/workflows/ and waits on batch PR #90 for a maintainer") {
|
||||
t.Errorf("check --cut = %d, want #7 to hold the cut:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
if code, stdout, _ := f.exec(gh, "notify", "--line", "release-1.1"); code != 0 || !strings.Contains(stdout, "2 originals on #90 change .github/workflows/ or wait on one that does") {
|
||||
t.Errorf("notify = %d, want #7 among the waits:\n%s", code, stdout)
|
||||
}
|
||||
})
|
||||
t.Run("a conflict and one not on the line", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/five.txt": "old\n", "app/a.txt": appFile, "app/b.txt": appFile})
|
||||
f.lines()
|
||||
f.onLine("release-1.1", "fix(app): five, the line's way", map[string]string{"app/five.txt": "line\n"})
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/five.txt": "five\n", "app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
|
||||
gh := &fakeGH{}
|
||||
if code, _, stderr := f.exec(gh, "run", "--line", "release-1.1", "--push"); code != 0 {
|
||||
t.Fatalf("run = %d\n%s", code, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
f.pr(9, "fix(app): nine", "", map[string]string{"app/b.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(10, "fix(app): ten", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1), "app/b.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 1 || !strings.Contains(stdout, "/pull/10 fix(app): ten (it waits on #9, which is not on the line either)") {
|
||||
t.Errorf("check = %d, want #10 to fail it, waiting on #9:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
t.Run("a prerequisite on the open batch", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(7, "fix(app): seven", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
gh := &fakeGH{}
|
||||
if code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--push"); code != 0 || !strings.Contains(stdout, `"picked":[5,7]`) {
|
||||
t.Fatalf("run = %d, want #5 and #7 picked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1", "--cut"); code != 1 || !strings.Contains(stdout, "#5 is only on open batch PR #90") || strings.Contains(stdout+stderr, "waits on") {
|
||||
t.Errorf("check --cut = %d, want #5 and #7 only on the batch and no wait:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
t.Run("a direct reason", func(t *testing.T) {
|
||||
f := featWorld(t)
|
||||
gh := &fakeGH{}
|
||||
openBatch(t, f, gh)
|
||||
if code, _, stderr := f.exec(gh, "run", "--line", "release-1.1", "--defer", "5", "--reason", "needs the tap", "--push"); code != 0 {
|
||||
t.Fatalf("run --defer = %d\n%s", code, stderr)
|
||||
}
|
||||
reopen(f, gh)
|
||||
if code, stdout, stderr := f.exec(gh, "check", "--line", "release-1.1"); code != 0 || !strings.Contains(stderr, "warning: deferred on #90 to the next batch: https://github.com/cozystack/cozystack/pull/5 ") || strings.Contains(stderr, "parked") {
|
||||
t.Errorf("check = %d, want #5 deferred for its reason, not parked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
t.Run("a prerequisite rule 6 holds", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
mc7 := f.pr(7, "fix(app): seven", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1), "app/seven.txt": "7\n"})
|
||||
f.onLine("release-1.1", "fix(app): seven (#7)\n\n(cherry picked from commit "+mc7+")", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1), "app/seven.txt": "7\n"})
|
||||
if code, stdout, stderr := f.exec(nil, "check", "--line", "release-1.0"); code != 0 || !strings.Contains(stderr, "note: #7 waits on #5, which is not on release-1.1 yet") {
|
||||
t.Errorf("check of release-1.0 = %d, want a note that #7 waits on #5:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
t.Run("a chain", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(4, "fix(app): four", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
f.pr(5, "fix(app): five", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!", 1)})
|
||||
f.pr(7, "fix(app): seven", "", map[string]string{"app/a.txt": strings.Replace(appFile, "two", "TWO!!", 1)})
|
||||
if code, stdout, stderr := f.exec(nil, "check", "--line", "release-1.1"); code != 1 || !strings.Contains(stdout, "/pull/7 fix(app): seven (it waits on #5, which is not on the line either)") {
|
||||
t.Errorf("check = %d, want #7 failing it through #5:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// run's report, check and notify give an original one disposition: a
|
||||
// workflow original whose only missing dependency is a test waits for a
|
||||
// maintainer, and one deferred for a reason stays deferred, though it
|
||||
// builds on what never comes; neither is parked.
|
||||
func TestDispositionOrderIsSharedByRunCheckNotify(t *testing.T) {
|
||||
f := auxWorld(t)
|
||||
f.pr(20, "feat(app): tap", "", map[string]string{"app/tap.go": appFile})
|
||||
f.pr(7, "fix(app): fix the tap", "", map[string]string{"app/tap.go": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
gh := &fakeGH{}
|
||||
if code, _, stderr := f.exec(gh, "run", "--line", "release-1.1", "--no-workflow-files", "--push"); code != 0 {
|
||||
t.Fatalf("run = %d\n%s", code, stderr)
|
||||
}
|
||||
f.git("switch", "-q", "main")
|
||||
reopen(f, gh)
|
||||
code, stdout, stderr := f.exec(gh, "run", "--line", "release-1.1", "--defer", "7", "--reason", "waits for the tap", "--push")
|
||||
if code != 0 {
|
||||
t.Fatalf("run --defer = %d\n%s", code, stderr)
|
||||
}
|
||||
if strings.Contains(stdout, `"parked":[{`) || !strings.Contains(stdout, `{"original":5,"files":[".github/workflows/release.yaml"],"workflows":true}`) || !strings.Contains(stdout, `{"original":7,"files":[],"reason":"waits for the tap"}`) {
|
||||
t.Errorf("the report does not have #5 waiting and #7 deferred, unparked:\n%s", stdout)
|
||||
}
|
||||
reopen(f, gh)
|
||||
code, stdout, stderr = f.exec(gh, "check", "--line", "release-1.1")
|
||||
if code != 0 || strings.Contains(stderr, "parked") || !strings.Contains(stderr, "warning: waiting on #90 for a maintainer, since it changes .github/workflows/: https://github.com/cozystack/cozystack/pull/5 ") || !strings.Contains(stderr, "warning: deferred on #90 to the next batch: https://github.com/cozystack/cozystack/pull/7 ") {
|
||||
t.Errorf("check = %d, want #5 waiting and #7 deferred:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
code, stdout, _ = f.exec(gh, "notify", "--line", "release-1.1")
|
||||
if code != 0 || !strings.Contains(stdout, "1 originals on #90 change .github/workflows/") || strings.Contains(stdout, "parked") || strings.Contains(stdout, "conflicts") {
|
||||
t.Errorf("notify = %d, want #5 waiting and nothing for #7:\n%s", code, stdout)
|
||||
}
|
||||
}
|
||||
|
||||
// A never and a pending prerequisite together park.
|
||||
func TestParkWinsOverWait(t *testing.T) {
|
||||
f, _ := chainWorld(t)
|
||||
f.pr(20, "feat(app): tap", "", map[string]string{"app/tap.go": appFile})
|
||||
f.pr(8, "fix(app): eight", "", map[string]string{"app/shared.txt": strings.Replace(appFile, "two", "TWO!!", 1), "app/tap.go": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1")
|
||||
if code != 0 || !strings.Contains(stdout, `"kind":"dependency","needs":[20]`) || strings.Contains(stdout, `"original":8,"files":[],"needs"`) {
|
||||
t.Errorf("run = %d, want #8 parked on #20, not waiting on #7:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// A prerequisite picked earlier in the same batch satisfies what builds on
|
||||
// it, and so does one whose pick came out empty because an earlier pick
|
||||
// already carried it: #4280 and #3938.
|
||||
func TestDependencySatisfiedEarlierInTheBatch(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(3, "fix(kafka): delete hooks", "", map[string]string{"app/hooks.yaml": appFile})
|
||||
f.pr(4, "fix(kafka): fix the delete hook", "", map[string]string{"app/hooks.yaml": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1"); code != 0 || !strings.Contains(stdout, `"picked":[3,4]`) {
|
||||
t.Errorf("run = %d, want #3 and #4 picked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
|
||||
// #30 adds back the file #2 brought and a feat took away, so its pick
|
||||
// comes out empty after #2's, and #4 builds on #30.
|
||||
f = newFixture(t)
|
||||
f.squash(2, "chore: files", "", map[string]string{"app/a.txt": appFile})
|
||||
f.lines()
|
||||
f.pr(20, "fix(kafka): delete hooks, and two", "", map[string]string{"app/hooks.yaml": appFile, "app/two.txt": "2\n"})
|
||||
f.pr(21, "feat(kafka): no delete hooks", "", map[string]string{"app/hooks.yaml": ""})
|
||||
f.pr(30, "fix(kafka): delete hooks again", "", map[string]string{"app/hooks.yaml": appFile})
|
||||
f.pr(4, "fix(kafka): fix the delete hook", "", map[string]string{"app/hooks.yaml": strings.Replace(appFile, "two", "TWO", 1)})
|
||||
if code, stdout, stderr := f.exec(nil, "run", "--line", "release-1.1"); code != 0 || !strings.Contains(stdout, `"picked":[4,20]`) || strings.Contains(stdout, `"needs"`) {
|
||||
t.Errorf("run with #30's pick empty = %d, want #4 picked:\n%s\n%s", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ go build ./cmd/backport-batch
|
||||
./backport-batch check --line release-X.Y --cut
|
||||
```
|
||||
|
||||
[`backport-batch check`](../../cmd/backport-batch/README.md) applies the rules to every pull request merged into `main` since the line branched, and looks for each one they take on the line and then on the open batch pull request: by picks whose `-x` lines name its merge commit or every commit of its own, by a pick that would change nothing, and, on commits from before the policy's batch-only day, by what their text says, such as `Backport of #N`. With `--cut` a change found only on the open batch pull request fails the check too, since a cut tags the line and would not carry it: merge the batch pull request first. A conflict the batch deferred, or an original deferred to the next batch, prints as a warning without failing the check, also once that batch merged or closed. An original that waits on the open batch for a maintainer fails the cut, and so does a unit on the open batch that carries only part of its original. A change that reached the line by hand counts like any other, by what reached the line.
|
||||
[`backport-batch check`](../../cmd/backport-batch/README.md) applies the rules to every pull request merged into `main` since the line branched, and looks for each one they take on the line and then on the open batch pull request: by picks whose `-x` lines name its merge commit or every commit of its own, by a pick that would change nothing, and, on commits from before the policy's batch-only day, by what their text says, such as `Backport of #N`. With `--cut` a change found only on the open batch pull request fails the check too, since a cut tags the line and would not carry it: merge the batch pull request first. A conflict the batch deferred, or an original deferred to the next batch, prints as a warning without failing the check, also once that batch merged or closed. An original that waits on the open batch for a maintainer fails the cut, and so does a unit on the open batch that carries only part of its original. An original parked because it builds on a change the line never gets, or would land only in part, prints as a note; one that waits on another original fails, warns or notes by what it waits on. A change that reached the line by hand counts like any other, by what reached the line.
|
||||
|
||||
### Backporting code that touches monotonic counters
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ git add <resolved files>
|
||||
git -c core.hooksPath=/dev/null cherry-pick --continue --no-edit
|
||||
```
|
||||
|
||||
When the original builds on something the line does not have, a helper, a value or another pull request, the resolution would have to bring that along, which this task does not allow: abort with `git cherry-pick --abort`, go back with `git switch --detach "$base"`, and comment on the batch pull request which change the original depends on; it stays deferred until that change is on the line. When that change will never reach the line, drop the original there instead, with `backport-batch run --line <line> --drop N --reason "<builds on …>" --push`, so later batches stop trying it. A commit whose change the line already has stops the pick as empty; skip it with `git cherry-pick --skip`. A resolution that ports only what the line has and leaves a file of the original as it was, one the line does not have for instance, is refused by `fold`: such a port goes to the line as a pull request of its own, as [fixes that exist only on a release line](../backports.md#fixes-that-exist-only-on-a-release-line) describes, and the original is dropped there.
|
||||
When the original builds on something the line does not have, a helper, a value or another pull request, the resolution would have to bring that along, which this task does not allow: abort with `git cherry-pick --abort`, go back with `git switch --detach "$base"`, and comment on the batch pull request which change the original depends on; it stays deferred until that change is on the line. An original the batch parked because it builds on such a change is the same task, and lands only as a complete adaptation: every file it changes changed, unless the line already has that file as the original makes it. When that change will never reach the line, drop the original there instead, with `backport-batch run --line <line> --drop N --reason "<builds on …>" --push`, so later batches stop trying it. A commit whose change the line already has stops the pick as empty; skip it with `git cherry-pick --skip`. A resolution that ports only what the line has and leaves a file of the original as it was, one the line does not have for instance, is refused by `fold`: such a port goes to the line as a pull request of its own, as [fixes that exist only on a release line](../backports.md#fixes-that-exist-only-on-a-release-line) describes, and the original is dropped there.
|
||||
|
||||
For a merged pull request, join the picks to the batch head with the merge commit:
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ A pull request the rules take for every line can still be wrong for one of them,
|
||||
|
||||
The batch also leaves a pull request out of a line on its own when it cannot land there whole. A pick that would leave part of what the pull request does on `main` without effect on the line, a change to a file the line does not have, or the deletion of a file the line never had or already removed, is not made: the pull request is parked, the batch pull request lists it under "Parked" with those files, and `check` prints it as a note without failing. A file the line already has as the pull request makes it counts as there, and so does a file `main` or the line renamed, under its other name. A unit already on the open batch that does only part of its original fails `check --cut` and `backport-batch verify`, whatever its label says, until `backport-batch run --defer` takes it out. What applies of a parked pull request goes to the line as a pull request of its own, as [fixes that exist only on a release line](#fixes-that-exist-only-on-a-release-line) describes.
|
||||
|
||||
A pull request is parked too when it builds on a change the line never gets: it changes a file a `feat` added on `main`, say, or a line such a change wrote, and the line has neither. `backport-batch` reads that from git, as [its README](../../cmd/backport-batch/README.md#what-an-original-builds-on) describes, and names the change in the batch pull request. One that builds on a change that is still to come, a deferred conflict, one waiting for a maintainer, one rule 6 holds or one not tried yet, waits for it instead, listed under "Waiting on another original", and the batch tries it again once that change is on the line; one picked earlier in the same batch counts as there. A complete hand adaptation of a parked pull request, every file it changes changed, still lands on the batch through [resolving a conflict](./backport-tasks/resolve-conflict.md).
|
||||
|
||||
### What waits for the next minor
|
||||
|
||||
`feat`, `chore` and `docs` pull requests, and dependency bumps (scope `deps`), ship with the next minor, not in a patch release; only a maintainer's `backport/include`, below, takes one. If a class of fixes should also wait for a minor, it gets a new rule on this page; a single pull request that the rules get wrong is what the overrides below are for.
|
||||
@@ -103,7 +105,7 @@ Each run also reports where every pull request merged into `main` since the line
|
||||
|
||||
### Changes to workflows
|
||||
|
||||
The scheduled run's token may not push a commit that changes `.github/workflows/`, so the scheduled run leaves such an original out (`run --no-workflow-files`). The batch pull request lists it under "Waiting for a maintainer", with the workflow files it changes, and so does the batch's comment. It is no conflict. The policy still takes it: `check` warns about it while it waits, and `check --cut` fails on it. When nothing else is picked there is no batch pull request to list it on, and `check` reports it as missing.
|
||||
The scheduled run's token may not push a commit that changes `.github/workflows/`, so the scheduled run leaves such an original out (`run --no-workflow-files`). That holds also for one whose only missing dependency that never comes is a test or documentation, which a maintainer's run, with the token that may push the workflow, parks instead: what lands of it then is a pull request of its own; `check` reads which of the two the open batch was assembled as from its record, and with no batch open takes the scheduled run's. The batch pull request lists it under "Waiting for a maintainer", with the workflow files it changes, and so does the batch's comment. It is no conflict. The policy still takes it: `check` warns about it while it waits, and `check --cut` fails on it. When nothing else is picked there is no batch pull request to list it on, and `check` reports it as missing.
|
||||
|
||||
A maintainer brings it over with their own token, one that may push workflow changes (the Workflows permission, or the classic `workflow` scope), by continuing the open batch without the flag:
|
||||
|
||||
|
||||
Reference in new issue
Block a user