Automated Release with Changelog

Automate GitHub Releases with changelog generation, version tagging, and asset uploads using GitHub Actions. Covers semantic versioning, release drafts, and npm publishing.

Advanced

Detailed Explanation

Automated Release Workflow

Automating releases removes human error from the release process and ensures every release has consistent notes, tags, and assets. This workflow triggers when a version tag is pushed.

Workflow YAML

name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: 'https://registry.npmjs.org'

      - name: Install and build
        run: |
          npm ci
          npm run build

      - name: Generate changelog
        id: changelog
        run: |
          PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
          if [ -n "$PREV_TAG" ]; then
            CHANGES=$(git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)" --no-merges)
          else
            CHANGES=$(git log --pretty=format:"- %s (%h)" --no-merges -20)
          fi
          echo "changes<<EOF" >> $GITHUB_OUTPUT
          echo "$CHANGES" >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          body: |
            ## Changes
            ${{ steps.changelog.outputs.changes }}
          files: |
            dist/*.tar.gz
            dist/*.zip
          draft: false
          prerelease: ${{ contains(github.ref, '-beta') || contains(github.ref, '-rc') }}

      - name: Publish to npm
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

How It Works

  1. Tag trigger: Pushing a tag like v1.2.3 triggers the workflow
  2. Full history: fetch-depth: 0 fetches all Git history for changelog generation
  3. Changelog: Extracts commit messages between the previous tag and the current one
  4. Release creation: softprops/action-gh-release creates the GitHub Release with notes and file attachments
  5. npm publish: Publishes the package to npm using a stored auth token

Version Tag Workflow

# Bump version in package.json
npm version patch  # or minor, major
# This creates a commit and tag
git push origin main --tags

Pre-release Detection

The prerelease field automatically marks releases as pre-release when the tag contains -beta or -rc (e.g., v2.0.0-beta.1).

Adding Release Assets

Use the files field to attach binaries, archives, or other build outputs to the release. Glob patterns are supported.

Use Case

Automating the release process for open-source libraries, CLI tools, or applications. Ensures every release has consistent changelog notes, proper version tags, and published artifacts without manual steps.

Try It — GitHub Actions Workflow Builder

Open full tool