Task 2: The Pipeline, Empty

In this task you write three workflow files, one per event:

WorkflowRuns onIts part
Brancha push to a topic branchthe developer's own loop: fast feedback while they work; it blocks nothing
Pull requesta pull request to main, and every new commit on itthe gate: its checks and the approval decide whether a change reaches main
Mergea merge into maindelivery: 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 main once Task 3 protects it: the only writes to main are merges of approved pull requests. GitHub records a merge as a push, so the merge workflow says on: push to main.
  • 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: push to every branch but main.
  • Jobs: lint, unit-tests. TODO: the file.

Write the pull request workflow

  • .github/workflows/pr.yml, on: pull_request to main.
  • 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: push to main: a merge, from Task 3 on.
  • Jobs: image-push, deploy, smoke-test, in a chain of needs:.
    • image-push builds the image from the merged commit and tags it with its SHA.
    • smoke-test calls 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.

Translations: