Skip to content

Merge pull request #3 from shakcho/fix/release-2 #3

Merge pull request #3 from shakcho/fix/release-2

Merge pull request #3 from shakcho/fix/release-2 #3

Workflow file for this run

name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
release_type:
description: 'Release type (patch, minor, major)'
required: true
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
# Skip release commits to avoid infinite loops
if: >-
github.event_name == 'workflow_dispatch' ||
!startsWith(github.event.head_commit.message, 'release:')
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: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Determine version bump
id: bump
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "type=${{ inputs.release_type }}" >> "$GITHUB_OUTPUT"
exit 0
fi
# Get all commit messages since the last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
COMMITS=$(git log --pretty=format:"%s" --no-merges)
else
COMMITS=$(git log "${LAST_TAG}..HEAD" --pretty=format:"%s" --no-merges)
fi
echo "Commits since last release:"
echo "$COMMITS"
# Determine bump type from commit messages
# Conventional Commits: feat: = minor, fix: = patch, BREAKING CHANGE = major
BUMP="none"
if echo "$COMMITS" | grep -qiE "BREAKING CHANGE|^[a-z]+(\(.+\))?!:"; then
BUMP="major"
elif echo "$COMMITS" | grep -qE "^feat(\(.+\))?:"; then
BUMP="minor"
elif echo "$COMMITS" | grep -qE "^fix(\(.+\))?:"; then
BUMP="patch"
fi
echo "type=$BUMP" >> "$GITHUB_OUTPUT"
- name: Bump version
id: version
if: steps.bump.outputs.type != 'none'
run: |
npm version ${{ steps.bump.outputs.type }} --no-git-tag-version
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Commit and tag
if: steps.bump.outputs.type != 'none'
run: |
git add package.json package-lock.json
git commit -m "release: v${{ steps.version.outputs.version }}"
git tag "v${{ steps.version.outputs.version }}"
git push origin main --tags
- name: Publish to npm
if: steps.bump.outputs.type != 'none'
run: |
VERSION=${{ steps.version.outputs.version }}
PUBLISHED=$(npm view react-driftkit version 2>/dev/null || echo "")
if [ "$PUBLISHED" = "$VERSION" ]; then
echo "Version $VERSION is already published to npm. Skipping."
exit 0
fi
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.bump.outputs.type != 'none'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
generate_release_notes: true
- name: Skip release
if: steps.bump.outputs.type == 'none'
run: echo "No release-triggering commits found (feat:/fix:/BREAKING CHANGE). Skipping release."