Homework — GitHub Actions Pipeline
Lesson 04 · Cloud Infrastructure & DevOps · 3 tasks
Task 1 — Add a code-coverage gate
Extend the test job to produce a combined coverage report and fail if coverage drops below 80%. The pipeline should not pass if any commit reduces test coverage below that threshold.
Modify the test steps to run pytest with pytest-cov:
pytest --cov=cloud-devops/sample-app/api \
--cov=cloud-devops/sample-app/worker \
--cov-report=term-missing \
--cov-fail-under=80
The --cov-fail-under=80 flag causes pytest to exit with a non-zero code if the combined coverage is below 80%, which makes the CI job fail.
Self-check:
- The CI log for the
testjob printsRequired test coverage of 80% reached. - If you intentionally delete test assertions to drop coverage below 80%, the
testjob turns red. - Reverting the deletion restores the green check.
Task 2 — Add a path-filter so doc-only edits skip CI
Add paths-ignore to both the push and pull_request triggers so that commits containing only Markdown files or documentation do not fire the pipeline.
on:
push:
branches: [main]
paths-ignore:
- '**.md'
- 'docs/**'
pull_request:
branches: [main]
paths-ignore:
- '**.md'
- 'docs/**'
Self-check:
- Commit a change to
README.mdonly. The GitHub Actions tab shows no new run for that commit. - Commit any
.pyfile change. CI runs normally. - Commit a mix of
.mdand.pychanges. CI runs (only all-ignored commits are skipped).
Task 3 — Add a “Summary” step to the build job
Use the $GITHUB_STEP_SUMMARY environment variable to append a brief Markdown block at the end of each build matrix job. The summary should list the image tag that was built.
Add a final step to the build job:
- name: Write build summary
run: |
echo "### Built images" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ matrix.service }}:ci-${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
Self-check:
- Open a completed workflow run on GitHub.
- Click the Summary link at the top of the run page (left sidebar).
- The summary section shows a “Built images” heading with a bullet for each service.