Task 2: The Pipeline, Empty
In this task you write three workflow files, one per event:
| Workflow | Runs on | Its part |
|---|---|---|
| Branch | a push to a topic branch | the developer's own loop: fast feedback while they work; it blocks nothing |
| Pull request | a pull request to main, and every new commit on it | the gate: its checks and the approval decide whether a change reaches main |
| Merge | a merge into main | delivery: what passed the gate becomes an image and is deployed |
- The pull request workflow is the one gate. The branch workflow runs whether or not a pull request ever follows.
- Nobody pushes to
mainonce Task 3 protects it: the only writes tomainare merges of approved pull requests. GitHub records a merge as a push, so the merge workflow sayson: pushtomain. - The merge workflow reruns no tests: the pull request already tested the merged code. It checks only that the deployment works.
None of them does real work yet:
- Every job just prints what it will do.
- You learn which event runs which jobs, and in what order, while the jobs still take seconds.
- Later tasks replace one placeholder at a time with real work.
Refresh your workflow knowledge: GitHub Actions Workflows: the Structure of the File.
Write the branch workflow
.github/workflows/branch.yml,on: pushto every branch butmain.- Jobs:
lint,unit-tests. TODO: the file.
Write the pull request workflow
.github/workflows/pr.yml,on: pull_requesttomain.- Jobs:
lint,unit-tests,integration-tests,security,image-build. needs:orders them: TODO: which waits for which, and the graph it draws.
Write the merge workflow
.github/workflows/merge.yml,on: pushtomain: a merge, from Task 3 on.- Jobs:
image-push,deploy,smoke-test, in a chain ofneeds:.image-pushbuilds the image from the merged commit and tags it with its SHA.smoke-testcalls the deployed app:GET /healthz, then one book created, read and deleted.
Push a branch, and read its run
- Open an issue, "Try the pipeline": say it is #3.
- Create its branch,
ci/3-try-the-pipeline, as The Plan names branches; change a line, commit it, push. - Only the branch workflow runs. TODO: what the Actions tab shows.
Open a pull request, and read its run
- The pull request workflow runs; its jobs appear as checks on the pull request.
- Merge it: nothing stops you yet. Task 3 adds the gate.
Read the merge run
- The merge writes to
main, so the merge workflow runs. - The job graph: image, then deploy, then the smoke test.