AI Hints
Home›CI/CD with GitHub Actions Tutorial›Artifacts, Services and Timeouts
CI/CD with GitHub Actions · Lesson 52 of 138

Artifacts

Files from a run.

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

When a run ends, its machine is thrown away, with every file on it. But sometimes you want to keep something. A test report, a coverage page, or the package you just built. Artifacts are files you upload from a run, and download later.

Artifacts
From the video: Artifacts
  • The machine is thrown away
  • Keep some files
  • Artifacts

Uploading a report

Pytest, with junit XML, writes a test report into the reports folder. Then upload artifact saves that folder, with the name test report. If always makes sure it uploads even when the tests fail, which is exactly when you want the report most.

.github/workflows/reports.ymlyaml
name: Reports
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: mkdir -p reports && pytest -q --junitxml=reports/tests.xml
      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: test-report
          path: reports/

The report file

Here's the step that makes the report, run for real. Then grep pulls two facts out of the XML report. Zero failures, and three tests. On GitHub, you'd download it from the run's page, or another job could download it with download artifact.

Terminal
run-steps .github/workflows/reports.yml | tail -4
      ------------------ generated xml file: /home/sam/shop/reports/tests.xml ------------------
      3 passed in 0.01s
  ↷ uses actions/upload-artifact@v4  (GitHub only)
  Job succeeded
grep -o 'tests="[0-9]*"\|failures="[0-9]*"' reports/tests.xml
failures="0"
tests="3"

Summary

Upload artifact keeps files after a run ends, and download artifact fetches them in another job. Next, databases for your tests, with service containers.

Key takeaways
  • upload-artifact
  • if: always()
  • download-artifact
Next up: Service Containers — a database for tests