AI Hints
Home›CI/CD with GitHub Actions Tutorial›Versions and Releases
CI/CD with GitHub Actions · Lesson 84 of 138

Releases on Tags

One tag, one release.

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

A nice release flow is fully automatic. You push a version tag, and a workflow builds the package, and publishes a GitHub release with notes and files. No manual steps, no forgotten files.

Releases on Tags
From the video: Releases on Tags
  • Push a version tag
  • The workflow builds
  • The release appears

release.yml

This workflow runs only when a tag starting with v is pushed. It needs write permission on contents, to create the release. It builds a package named after the tag, using github dot ref name. And the release action creates the GitHub release, and attaches the file.

.github/workflows/release.ymlyaml
name: Release
on:
  push:
    tags: ["v*"]
permissions:
  contents: write
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build the package
        run: tar -czf shop-${{ github.ref_name }}.tar.gz app.py
      - name: Show it
        run: ls *.tar.gz
      - uses: softprops/action-gh-release@v2
        with:
          files: shop-*.tar.gz

Running it

Our helper can pretend a tag was pushed. First, a normal push to main. It isn't triggered, because the workflow only runs for tags. Now, with the tag v one point two point zero, it runs, and builds shop dash v one point two point zero dot tar dot GZ.

Terminal
run-steps .github/workflows/release.yml
Workflow: Release  (event: push, branch: main)
  Not triggered: this workflow only runs for tags
run-steps .github/workflows/release.yml --tag v1.2.0
Workflow: Release  (event: push, tag: v1.2.0)
Job: release
  ↷ uses actions/checkout@v4  (GitHub only)
  ✓ Build the package
  ✓ Show it
      shop-v1.2.0.tar.gz
  ↷ uses softprops/action-gh-release@v2  (GitHub only)
  Job succeeded

Summary

Release workflows run on tags, build the package, and publish the release automatically. Next, environments, like staging and production.

Key takeaways
  • on: push: tags
  • github.ref_name
  • contents: write
Next up: Environments — staging and production