Course contents · Lesson 16 of 16

From Laptop to Production: The Life of a Code Change

GitHub Actions Lab · Lesson 16 of 16 · 11 min Hands-on

You change one line, and later that day real users see it, without anyone copying files to a server. What happened in between? This lesson follows one change from laptop to production: each hand-off and its check, what can still go wrong after release, and four numbers that measure the whole path. Then you send a change of your own down it.

Before the merge: from your laptop to main

Follow one change: a new greeting for the sample app from lessons 13 to 15. Your commit is the recipe, CI the tasting, code review the head chef's reading, the image the plate and the approval the pass. The figure numbers the twelve steps and names the lesson behind each.

Twelve numbered cards in three rows. Before the merge, in purple: 1 edit, change one line, lesson 2; 2 commit on a new branch, lessons 1 and 4; 3 push the branch to GitHub, lesson 12; 4 pull request, ask to merge, lessons 1 and 4; 5 CI checks, test and build with no push, lessons 5 and 13; 6 review, a teammate reads it, lessons 4 and 11; 7 merge into main, lesson 4. After the merge, in cyan: 8 build once, image tag equals the SHA, lessons 6 and 13; 9 registry, push to ghcr.io, lessons 7 and 15; 10 staging, deploy and smoke test, lessons 2 and 15; 11 approval, a reviewer says yes, lesson 14; 12 production, the same image, lesson 15. A footer: after release, monitor, flag or canary, roll back if worse, lessons 8 to 10
Steps 1 to 7 check the change; steps 8 to 12 ship one artifact made from it.

Steps 1 to 3. You edit a file on your laptop, the development environment of lesson 2, and commit it on a new branch, the separate line of work from lesson 4. Then you push the branch to GitHub. Nothing has reached users, or even main.

Steps 4 and 5. You open a pull request, asking to merge your branch into main. That starts CI: the test and build jobs run, and each reports a status check, the pass or fail result from lesson 5. The image is built but not pushed, because nobody has reviewed the code yet (lesson 13).

Steps 6 and 7. A teammate reads the diff, the lines you changed, and approves it or asks for changes; GitHub does not let authors approve their own pull requests. With green checks and an approval, you merge. The aha: by step 7, machines and a person have checked the change, and no user has seen it.

After the merge: build once, promote, approve

Steps 8 and 9. A merge is a push to main, so the pipeline runs again, this time to deliver. The build job makes the artifact once: a container image tagged with the merge commit's SHA (lesson 6). It pushes the image to the registry, ghcr.io (lesson 7). From here on, every step pulls those same bytes.

Steps 10 to 12. The staging job deploys the image to staging and runs a smoke test, a quick check that the app answers with the version it should. The production job then waits for a required reviewer (lesson 14). Once approved, it deploys the same image to production and runs the smoke test again (lesson 15).

The swim lanes show who does each step. People decide twice, at the review and at the approval; machines do everything in between. A red check sends the change back to you, never on to users.

Swim-lane flowchart with four lanes: Developer and teammates, CI system, Registry and Environments. Time flows down. Steps 1 to 4, the developer pushes a branch and opens a pull request. Step 5, CI tests and builds with no push; red sends it back to the developer to fix and push again, green leads to steps 6 and 7, review, then merge. The merge is a push to main. Step 8, CI builds the image once and pushes it to step 9, the registry stores the image. Staging pulls it, step 10, staging and smoke test. The job waits for approval: step 11, a reviewer approves. Step 12, production runs the same image, then the release is monitored. Footer: each hand-off leaves a record: a commit, a check, a review, a deployment
People decide at two gates; every other hand-off is automatic, and all of them are recorded.

After release: watch, limit, undo

Deployed is not done. Monitoring, from lesson 1, watches the running app's error rate and latency and alerts someone when they get worse. It catches what earlier checks cannot, because only production has real users and real traffic.

To limit how many users a bad change can hurt, ship it behind a feature flag that stays off until you release it, or as a canary that gets a small share of traffic first. If the numbers worsen, roll back: redeploy the previous image, revert the commit or switch the flag off (lesson 10). With GitOps, step 12 is instead a commit that an agent in the cluster applies.

Each stage catches mistakes that the earlier ones cannot. Here is where four kinds of failure are caught on this path:

FailureExampleCaught atWhat you see
TypoA misspelled nameYour laptop, or the pull request's checksAn editor warning or a red test
Failing testTwo lines in message.txtThe pull request's checksA red test; build never runs
Bad configA wrong port or image nameStaging, if it is set up like productionThe deploy or smoke test fails; production never starts
Performance regressionSlower pages under real trafficProduction monitoring, ideally during a canaryLatency rises; you roll back

A red check costs you minutes; a production regression costs your users. That is why the cheap, fast checks come first.

Four delivery metrics for the whole path

How do you know whether the path works well? DORA (DevOps Research and Assessment), a research programme that studies how software teams deliver, started with four key measures:

  • Deployment frequency: how often you deploy to production.
  • Lead time for changes: how long a change takes from commit to running in production.
  • Change failure rate: the share of deployments that need immediate fixing, such as a rollback.
  • Time to restore service: how long recovering from such a failed deployment takes. DORA renamed it failed deployment recovery time in 2023, and in 2024 added a fifth metric, deployment rework rate.

This path moves all four. Automated checks make each deploy cheap, so you can ship small changes often. Lead time is the sum of every wait in the first figure; in the lab, much of it is you, at the review and the approval. Tests and the smoke test keep the failure rate down, and an image kept in the registry turns recovery into re-running an older deploy.

DORA's research finds that speed and stability are not trade-offs: small changes, shipped often, tend to improve all four together. Track them per service to improve over time, not as targets for ranking teams, which people learn to game.

Capstone lab: get your fork ready

The capstone puts lessons 12 to 15 together. The folder course-labs/ci-cd-and-devops-fundamentals/05-capstone holds lesson 15's sample app, a web server on port 8080, with compose.yaml and capstone.yml, the same pipeline as deploy.yml. You need your fork, gh, and Docker with Compose v2.

First, remove any earlier lab workflow from .github/workflows. Check under Settings, Environments that production exists with you as a required reviewer, as in lesson 15. And point gh at your fork: gh repo fork --clone made datsabk/course-labs the default repository, so gh pr create would open your pull request there. From the top of your clone:

gh repo set-default your-name/course-labs
mkdir -p .github/workflows
cp ci-cd-and-devops-fundamentals/05-capstone/capstone.yml .github/workflows/
git add .github/workflows/capstone.yml
git commit -m "add capstone workflow"
git push

gh should print ✓ Set your-name/course-labs as the default repository for the current directory; does not correspond to any git remotes means a mistyped name. The push starts a Capstone run in the Actions tab. When production waits, click Review deployments and approve it: the old greeting goes live as your before picture.

Check yourself

The pull request built an image, but production runs one built after the merge. Does that break "build once"?

No. The pull request's image was never pushed; it only proved the code builds. The shipped artifact is built once from the merged commit, and that one image reaches staging and production.

Every check passed, yet the next day pages load twice as slowly. Which stage could catch this, and what do you do?

Production monitoring, because tests and a staging copy without real traffic rarely show slowness. Roll back or switch the flag off, then fix it; a canary would have limited who noticed.

A team's CI takes ten minutes, but its lead time for changes is three days. Where do you look first?

At the waits: pull requests waiting for review and deploys waiting for approval. Lead time runs from commit to production, so idle time counts as much as CI time.