CompCode Academy

Lesson 2 of 4 · Free to read

Exercises

Exercises — CI/CD: pipelines, environments, and AI-generated workflows

Watch & learn

Course video

Open on YouTube
GitHub Actions Tutorial — CI/CD Pipeline — Pipelines that gate AI-generated changes.

Keep a prompt log while you work. Speed without a trail is not a skill — it is luck.

How to use this file


Exercise 1 — Write a minimal CI workflow by hand

Goal: write a GH Actions workflow from scratch that installs deps and runs pytest for pipeline_lab/. No AI for this one. Time: 25 minutes Level: foundational Modules touched: [11-ci-cd]

Setup

  • Fork the cohort lab repo (or work in code-examples/python/pipeline_lab/).
  • Make sure .github/workflows/ exists.

Steps

  1. Create .github/workflows/ci.yml.
  2. Trigger on push and pull_request.
  3. One job, ubuntu-24.04, Python 3.11.
  4. Install deps (pip install -e ".[dev]").
  5. Run pytest.
  6. Push, watch it run.

Success criteria

  • Workflow runs green on main.
  • Job uses pinned action versions (@v4).
  • Runner is pinned (ubuntu-24.04, not ubuntu-latest).

AI prompt hints

  • (None for this one — the point is to internalise the YAML.)

Solution sketch

A 15-line YAML file. Most learners will reach for ubuntu-latest; the pinning rule is the catch.

Stretch

  • Add a cache step for pip wheels.

Exercise 2 — Add the test report as an artifact

Goal: extend Exercise 1 so pytest produces a JUnit XML and the workflow uploads it as an artifact. Time: 20 minutes Level: foundational Modules touched: [11-ci-cd]

Setup

  • Same as Exercise 1.

Steps

  1. Add pytest --junitxml=report.xml.
  2. Add a actions/upload-artifact@v4 step that uploads report.xml.
  3. Make if: always() so it uploads even on failure.
  4. Push, verify the artifact appears in the run UI.

Success criteria

  • Artifact report.xml available from the run page.
  • The upload step runs even when pytest fails.

AI prompt hints

  • "Ask Cursor: 'Add a JUnit XML upload step to this workflow that runs even on failure. Output a diff only.'"

Solution sketch

Two steps added. The if: always() is the easy-to-miss flag.

Stretch

  • Add a actions/upload-artifact@v4 for any coverage report.

Exercise 3 — Generate a full pipeline with AI and critique it

Goal: prompt Cursor for a full pipeline (build → test → security → package → deploy to staging) and apply the AI-pipeline checklist. Time: 80 minutes Level: intermediate Modules touched: [11-ci-cd, 02-ai-assisted-development, 15-security-and-supply-chain]

Setup

  • Work in pipeline_lab/. Read CHECKLIST.md before prompting.

Steps

  1. Prompt Cursor for the full pipeline. Use the Specify pattern; include the stages explicitly.
  2. Open the generated YAML alongside CHECKLIST.md.
  3. Score it: how many items pass / fail / unclear?
  4. Hand-edit to fix every failing item. Log each edit in PROMPTS.md with the reasoning.
  5. Push. If the deploy step needs cloud credentials you don't have, mark it if: false and explain in a comment.

Success criteria

  • Pipeline runs (deploy can be no-op).
  • All checklist items pass.
  • PROMPTS.md has ≥1 entry per checklist failure with the AI's original output, your fix, and why.

AI prompt hints

  • Specify: "Generate a GH Actions workflow for a FastAPI app. Stages: build, test, security (Trivy + secret scan), package (multi-stage Docker, sign with Cosign), deploy to staging on push to main with manual approval. Pin all actions to a specific tag. Use the staging environment for secrets."
  • Critique: "Here's the workflow. List 5 things a senior reviewer would flag. Reference my CHECKLIST.md."

Solution sketch

Common AI misses: @main actions, missing concurrency, secrets in plain env, missing artifact upload, no gate. Strong learners catch ≥5 and document each.

Stretch

  • Re-prompt with the checklist attached and compare to round-1 output.

Exercise 4 — Add an environment gate

Goal: add a deploy-prod job that requires manual approval, runs only after deploy-staging, and pulls secrets from the prod environment. Time: 35 minutes Level: intermediate Modules touched: [11-ci-cd]

Setup

  • In your fork's GitHub Settings → Environments, create staging and prod. On prod, require yourself as a reviewer.

Steps

  1. Add environment: prod to the deploy-prod job.
  2. Add needs: deploy-staging.
  3. Add if: github.ref == 'refs/heads/main'.
  4. Push and watch the run pause for approval.
  5. Approve via the GitHub UI; verify it proceeds.

Success criteria

  • The run pauses at deploy-prod until approved.
  • Approval shows your name in the timeline.

AI prompt hints

  • "Ask Cursor: 'Add a manual-approval deploy-prod job to this workflow. Reference the prod environment. Output a diff only.'"

Solution sketch

The pause is the demonstration. Many learners have never seen a CI workflow wait on a human.

Stretch

  • Add a wait timer of 5 minutes after staging deploy before prod is allowed.

Exercise 5 — Debug a deliberately broken pipeline (advanced)

Goal: open the planted-broken workflow in code-examples/python/pipeline_lab/.github/workflows/broken.yml and diagnose all 3 issues using logs only (no AI for diagnosis; AI allowed for fixes). Time: 45 minutes Level: advanced Modules touched: [11-ci-cd]

Setup

  • Push the planted broken workflow to your fork. Confirm it fails.

Steps

  1. Open the failed run. Read the logs.
  2. For each of the 3 failures, write in DIAGNOSIS.md: stage, symptom, root cause, fix.
  3. Apply the fixes (AI allowed; log every prompt in PROMPTS.md).
  4. Push, verify green.

Success criteria

  • DIAGNOSIS.md lists 3 issues with stage / symptom / root cause / fix.
  • Workflow runs green after the fixes.

AI prompt hints

  • Once diagnosed: "Here's the failing step. Fix the underlying issue without changing the test logic. Output a diff only."

Solution sketch

Planted issues include: missing actions/checkout, wrong Python version pin (mismatch with requires-python), secret referenced but not set. The discipline is the diagnosis step — many learners skip to AI and "fix" the wrong thing.

Stretch

  • Write a rerun-failed script: gh run rerun <run-id> --failed. When is this safe vs unsafe?

New free lessons and course updates. Unsubscribe from any email.