AI Hints
Home›CI/CD with GitHub Actions Tutorial›Projects: Releases and the Full Pipeline
CI/CD with GitHub Actions · Lesson 121 of 138

Project: Release Automation

Tags to releases.

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

Fourth project. When a version tag is pushed, test the code, write release notes from the commit messages since the last tag, and publish the release with a package attached.

Project: Release Automation
From the video: Project: Release Automation
  • Push a version tag
  • Notes from commits
  • Publish the release

release.yml

Fetch depth zero gets the full history, which we need for the notes. The tests run first. Then the notes step finds the previous tag with git describe, and lists every commit message since then. A package is built, and the release action publishes both.

.github/workflows/release.ymlyaml
name: Release
on:
  push: { tags: ["v*"] }
permissions: { contents: write }
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - run: pip install -q -r requirements.txt && pytest -q
      - name: Write release notes
        run: |
          prev=$(git describe --tags --abbrev=0 HEAD^)
          git log --pretty="- %s" $prev..HEAD > notes.md
          cat notes.md
      - run: tar -czf shop-${{ github.ref_name }}.tar.gz app.py
      - uses: softprops/action-gh-release@v2
        with: { body_path: notes.md, files: "shop-*.tar.gz" }

Running it

The repository has two tags. Our helper pretends v one point one point zero was pushed. The tests pass, and the release notes list the two commits since v one point zero point zero. Good commit messages make good release notes.

Terminal
git tag
v1.0.0
v1.1.0
run-steps .github/workflows/release.yml --tag v1.1.0 | grep -vE "^Workflow|↷|100%"
Job: release
  ✓ Run pip install -q -r requirements.txt && pytest -q
      3 passed in 0.01s
  ✓ Write release notes
      - Raise default tax to 25%
      - Add docs section
  ✓ Run tar -czf shop-v1.1.0.tar.gz app.py
  Job succeeded

Summary

Release automation turns a tag into tested notes and files, with no manual steps. Next, checks that run every night.

Key takeaways
  • fetch-depth: 0
  • Notes from git log
  • One tag, one release
Next up: Project: Nightly Checks — while you sleep