Open Factory Flooropen source

Guides

The builder

On this page

The builder picks one waiting item up from a hopper, has a model build it, and opens a pull request. It is the one part of the factory that starts work without a person handing it over.

What it builds goes onto the line by the front door, like anybody's work: the same tests, the same review, the same release gate. The builder merges nothing and releases nothing.

#What it may start

Only what each hopper's rule lets start:

  • an item a person has given the go label; or
  • an item in a hopper that says pick_up: agent, written by someone who may write to the repository, or by the factory itself.

Anybody else's request waits for a person. One item is built each time the builder runs, the oldest first, and none while builder.at_once items are already in progress.

#What happens to an item

  1. It is built. The model works on a copy of your main branch. It can read and edit files there. It cannot run a command, run your tests, or reach the network.
  2. A pull request is opened from the branch factory/item-<number>, saying Fixes #<number>, what the model says it did, and what it says it could not check. The item shows in the report as "Being built as #N".
  3. The line judges it. The builder starts your test workflows and the automatic reviewer on it. From here it is an ordinary change: it merges when your rules let it, by whoever merges for you.
  4. Or it goes to the bin. If the model judges the request too large or too unclear, or what it made cannot be used, the item is given the bin's label with the reason as a comment, for a person to decide. Take the label off to have it tried again.

A built change that is sent back goes back to its builder first. Before it starts anything new, each run looks at the changes the builder has open; one whose tests failed, or whose review found problems, is taken up again: the model is given the request, its own earlier change, and why it was sent back (which checks failed, or the review record), and a new version is pushed onto the same pull request, with a comment saying what it changed. The tests and the review then judge that version afresh.

It stops there after bin.sent_back versions in all (three unless you say otherwise): a change sent back that often is left for a person. The report lists it in the bin when a review has sent it back that many times, or when it has then waited unanswered hours. If a try comes to nothing (the model cannot see what is wrong, runs out of steps, or makes something that cannot be used) the pull request is given the bin's label with the reason, and the builder leaves it alone until a person takes the label off.

A built change that is closed without being accepted leaves its branch behind. The builder will not build that item twice: it goes to the bin. Delete the branch to have it tried again.

#What a built change may not touch

  • Anything under .github/ (your workflows), and factory.yml: the rules the change will be judged by.
  • More than 40 files, or more than about 60,000 characters of change.
  • Anything but ordinary text files: no binary file, no link, no submodule.

A change that breaks one of these is not used, and the item goes to the bin. They are checked twice, once by each job.

#Setting it up

  1. In factory.yml, give a hopper pick_up: agent (or name a builder.go label) and give the bin a label (how). Create those labels in the repository.
  2. Give the builder an account of its own. Add a repository secret FACTORY_BUILDER_TOKEN: a fine-grained personal access token with Contents and Pull requests set to read and write on this repository, from an account that may write to it. A token of your own works, and the built changes then show as opened by you; an account kept for the purpose keeps them apart from yours. (A GitHub App's token lasts an hour, so it cannot be stored as a secret; the starter has no step that makes a fresh one.)
  3. Copy starter/factory-builder.yml to .github/workflows/factory-builder.yml and replace COMMIT, in both places, with the commit id of the Open Factory Floor version you use (0.27.0 or later). Coming from an earlier version, also add checks: read to the permissions in your copy, as the starter now has: the builder reads a built change's check results, and GitHub refuses the workflow without it.
  4. That is all the builder needs to start your checks: a change opened by its own account starts the workflows you run on a pull request, as anybody's does.
  5. It needs one repository secret for the model, the same one the automatic reviewer uses.

The starter runs hourly and whenever you start it by hand, optionally for one item by number. An item named by hand must still be one its hopper's rule lets start.

#Without an account of its own

It works, with a person in the loop. Switch on Settings, Actions, General, "Allow GitHub Actions to create and approve pull requests", and set start: in the starter to the file names of your test workflows, each with a workflow_dispatch: trigger. The builder opens the pull request with the workflow's own token and starts those workflows by name. But GitHub holds the pull request's own workflow runs until a person presses "Approve workflows to run", on every built change, and while they are held a required check does not count as passed. Found on the first real builds: approving once does not lift it for the next.

#What to know

  • Cost. Building is a much bigger job than reviewing: one build is many model calls, up to 80 steps and 40 minutes. at_once: 1 and one item a run keep it to one at a time. A run with nothing to start asks the model nothing.
  • The model cannot run your tests, so a first version fails them more often than a person's would. Your tests and review are the check. Whether its first versions are good enough is the thing to learn from real use.
  • Your tests run the built code, as they run any pull request's from a branch in your repository. If a test workflow holds secrets, a built change's code runs beside them, exactly as a collaborator's would.
  • The same model family builds and reviews. The automatic reviewer is a fresh model that has seen nothing but the change, and its pass counts only for the levels your factory file says (passes); a high-risk change still needs a person. If you want a person to look at every built change, require a person's review in your branch rules.
  • A go label is a person vouching for the request as it reads then. If its author rewrites it afterwards, the builder builds what it says now. The result is still only a pull request, judged like any other.
  • The two jobs. The job that asks the model holds the model's credential and can only read your repository. The job that pushes the branch and opens the pull request never holds the credential, checks the first job's result again, and asks the hopper's rule again before it writes anything. The workflow's token cannot change workflow files, whatever a change says.
  • A build that comes to nothing is not repeated. If the model runs out of steps or time, or does not finish properly, a build has been spent, so the item goes to the bin and a person decides whether it is tried again. Only a failure that cost nothing (no credential, a refused credential, the provider failing) leaves the item waiting for the next run, with a warning on that run.
  • One stuck change stops the builder. With at_once: 1, a built change that has used up its tries, or is marked with the bin's label, still counts as in progress, so nothing else is built until a person fixes or closes it.
  • For a failed check the model is told which check failed, not shown its output. It reads its change and the tests again. A project whose test failures are hard to guess from the code will see it give up, and say so.
  • A new version costs a build, like the first. The limit of bin.sent_back versions is what bounds it.
  • Without an account of its own, if a workflow named in start cannot be started, the pull request is still opened and the run fails saying which, so you can start it by hand and add its workflow_dispatch: trigger.
  • If your main branch moves while an item is being built and the change no longer fits, nothing is opened and the next run builds it again.

#What is not built

  • Showing the model the output of a failed check.
  • Running your tests before opening the pull request.
  • Building more than one item in a run.

This guide is docs/BUILDER.md in the repository, and this page is made from it. Something wrong or unclear? Open an issue or send a pull request. Next: The Open Factory Floor app.