Day 1: The First Workflow
Goal: Write a workflow that runs the tests of notes-api on every push, follow the run with
ghand learn to read a red run. · Duration: approx. 60 min · Prerequisite: Day 0
Briefing
- A workflow consists of jobs, a job consists of steps. Every job runs on its own fresh runner – files from one job do not exist in the next.
- A step is either a command (
run:) or a ready-made action (uses:).actions/checkoutfetches the code,actions/setup-goinstalls Go. on:defines when the workflow starts. To begin with: on everypush.
.github/workflows/ci.yml
on: push
jobs:
test: ─► runner ubuntu-24.04 (fresh, gone after the run)
steps:
checkout ─► code from the repository
setup-go ─► Go in the version from go.mod
go test ./... ─► exit 0 = green, otherwise red
Drill 1: The workflow file
cd ~/gha-lab/notes-actions
mkdir -p .github/workflows
cat > .github/workflows/ci.yml <<'EOF'
name: ci
on: push
jobs:
test:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- run: go test ./...
EOF
git add .github
git commit -qm "ci: Tests bei jedem Push"
git push -qruns-on: ubuntu-24.04selects a GitHub runner with exactly this image.ubuntu-latestwould work too, but changes at some point without notice.@v7is the major version of the action. From Day 9 on you pin actions more precisely.go-version-file: go.modtakes the Go version from the project – one less place you can forget.
Save your progress? Sign up for free
Drill 2: Following the run
gh run list --limit 1Expected (ID, duration and time differ):
STATUS TITLE WORKFLOW BRANCH EVENT ID ELAPSED AGE
* ci: Tests bei jedem Push ci main push 41607177389 7s now
* means: still running. If nothing shows up yet, wait a
few seconds – GitHub needs a moment to create the run.
gh run watch follows the run until the end. For
<ID>, insert the number from the ID
column:
gh run watch --exit-status <ID>gh run watch refreshes the display every three seconds.
At the end it shows (shortened):
✓ main ci · 41607177389
Triggered via push less than a minute ago
JOBS
✓ test in 29s (ID 125819805658)
✓ Set up job
✓ Run actions/checkout@v7
✓ Run actions/setup-go@v7
✓ Run go test ./...
✓ Post Run actions/setup-go@v7
✓ Post Run actions/checkout@v7
✓ Complete job
- Without an ID,
gh run watchasks interactively for the run. With an ID it is clear which one you mean – and it also works in scripts. --exit-statusmakes the command end with the result of the run: 0 for green.
Save your progress? Sign up for free
Drill 3: Reading logs
gh run view <ID> --log | grep -E 'shell:|ok 'Expected (timestamps shortened):
test Run go test ./... 2026-11-03T08:57:55Z shell: /usr/bin/bash -e {0}
test Run go test ./... 2026-11-03T08:58:08Z ok example.com/notes-api 0.044s
--log delivers the whole log, grep picks
out the two interesting lines. Every line starts with job and step.
shell: /usr/bin/bash -e {0} shows how the runner executes
run:: in Bash with -e – the first failing
command ends the step.
Save your progress? Sign up for free
Drill 4: A red run
A test is supposed to fail:
sed -i 's/StatusCreated/StatusAccepted/' main_test.go
git commit -qam "Test kaputt"
git push -q
gh run list --limit 1With the new ID:
gh run watch --exit-status <ID>; echo "Exit: $?"Expected (shortened):
X main ci · 41607262782
Triggered via push less than a minute ago
JOBS
X test in 12s (ID 125820099540)
✓ Set up job
✓ Run actions/checkout@v7
✓ Run actions/setup-go@v7
X Run go test ./...
- Post Run actions/setup-go@v7
✓ Post Run actions/checkout@v7
✓ Complete job
ANNOTATIONS
X Process completed with exit code 1.
test: .github#12
Exit: 1
Only the failing lines:
gh run view <ID> --log-failed | grep -E 'FAIL|want' | head -3Expected (preceding columns shortened):
... --- FAIL: TestPostNotesRequiresKey (0.00s)
... main_test.go:75: key "lab-api-key-123": status 201, want 202
... FAIL
-in front of the post step ofsetup-gomeans: skipped. After a red step, only cleanup steps that explicitly ask for it still run.- The annotation also shows the cause on the summary page in the browser.
--log-failed shows only the steps that failed – with
long logs the fastest way to the cause. Fix it:
git revert --no-edit HEAD >/dev/null
git push -q
gh run list --limit 1
gh run watch --exit-status <ID> >/dev/null; echo "Exit: $?"Type the second line with gh run watch only once you
know the new ID from gh run list.
Expected:
Exit: 0
Save your progress? Sign up for free
Checkpoint
gh run list --limit 3 --json conclusion,displayTitle --jq '.[]'Expected:
{"conclusion":"success","displayTitle":"Revert \"Test kaputt\""}
{"conclusion":"failure","displayTitle":"Test kaputt"}
{"conclusion":"success","displayTitle":"ci: Tests bei jedem Push"}
head -2 .github/workflows/ci.ymlExpected:
name: ci
on: push
Challenge
Add a step go vet ./... to the job before the tests. In
the log it should carry its own name, “Statische Prüfung”.
Hint: Every step can have name:.
Solution
cat > .github/workflows/ci.yml <<'EOF'
name: ci
on: push
jobs:
test:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Statische Prüfung
run: go vet ./...
- run: go test ./...
EOF
git commit -qam "ci: go vet"
git push -q
gh run list --limit 1
gh run watch --exit-status <ID> >/dev/null
gh run view <ID> -v | grep -E 'Statische|go test'gh run view -v shows the steps of every job.
Expected:
✓ Statische Prüfung
✓ Run go test ./...
Save your progress? Sign up for free
Enterprise Note
- Workflows are code: They live in the repository, go
through reviews and have a history. Whoever changes
ci.ymlchanges what happens with every commit – that deserves the same care as application code. - Runner images change: On
ubuntu-24.04, GitHub updates the tools weekly. Whatever the build needs, the workflow installs itself (setup-go) instead of relying on the image. - Costs: Public repositories run for free, private ones have a quota of minutes. Large teams save with caches (Day 3) and their own runners (Days 5, 14).