AI Hints
Home›CI/CD with GitHub Actions Tutorial›Building Blocks Practice
CI/CD with GitHub Actions · Lesson 58 of 138

Practice: Build Then Test

Jobs with artifacts.

⏱ 2 min read▶ Video at 1:05:32🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Next practice. A build job packs the code into an archive, and uploads it. A test job waits for the build, downloads the same archive, and checks it. Pause, and think about which keys you'd need.

Practice: Build Then Test
From the video: Practice: Build Then Test
  • Build packs the code
  • Test downloads it
  • Which keys?

One answer

The build job packs app dot py with tar. It writes the file name as a step output, and maps it to a job output. Upload artifact saves the archive. The test job needs build. It downloads the package. And it lists what's inside, using the job output for the file name.

.github/workflows/build.ymlyaml
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      file: ${{ steps.pack.outputs.file }}
    steps:
      - uses: actions/checkout@v4
      - id: pack
        run: tar -czf shop.tar.gz app.py && echo "file=shop.tar.gz" >> "$GITHUB_OUTPUT"
      - uses: actions/upload-artifact@v4
        with: { name: package, path: shop.tar.gz }
  test:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with: { name: package }
      - run: tar -tzf ${{ needs.build.outputs.file }}

Running it

Our helper runs build, then test. The upload and download steps are GitHub only, so locally both jobs share one folder, which stands in for the artifact store. Tar lists the archive's contents, app dot py. Build first, test second, passing one file.

Terminal
run-steps .github/workflows/build.yml
Workflow: build.yml  (event: push, branch: main)
Job: build
  ↷ uses actions/checkout@v4  (GitHub only)
  ✓ Run tar -czf shop.tar.gz app.py && echo "file=shop.tar.gz" >> "$GITHUB_OUTPUT"
  ↷ uses actions/upload-artifact@v4  (GitHub only)
  Job succeeded
Job: test
  ↷ uses actions/download-artifact@v4  (GitHub only)
  ✓ Run tar -tzf shop.tar.gz
      app.py
  Job succeeded

Summary

Needs orders the jobs, artifacts move files between them, and outputs move values. That's the backbone of most real pipelines. Next, debugging a broken pipeline.

Key takeaways
  • needs + artifacts
  • outputs for values
  • Build, then test
Next up: Practice: Debugging a Pipeline — find the bug