Skip to content

0.3.2

0.3.2 #8

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate tag format
run: |
if [[ ! $GITHUB_REF_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
echo "❌ Invalid tag format: $GITHUB_REF_NAME"
echo "Expected format: v{major}.{minor}.{patch} (e.g., v1.2.3)"
exit 1
fi
echo "✅ Valid tag format: $GITHUB_REF_NAME"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install web-preview dependencies (for build check)
working-directory: ./web-preview
run: npm ci
- name: Run tests
run: npm test
- name: Build project
run: npm run build
- name: Build web-preview (validation)
working-directory: ./web-preview
run: npm run build
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
- name: Verify package.json version matches tag
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG_VERSION="${{ steps.version.outputs.version }}"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "❌ Version mismatch!"
echo "package.json: $PACKAGE_VERSION"
echo "Git tag: $TAG_VERSION"
exit 1
fi
echo "✅ Version verified: $PACKAGE_VERSION"
- name: Generate changelog
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
CHANGELOG_CONTENT=""
# Try to extract from CHANGELOG.md first
if [ -f "CHANGELOG.md" ]; then
# Extract changelog for current version
awk "/^## \[$VERSION\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md > current_changelog.md
if [ -s current_changelog.md ]; then
echo "📋 **What's Changed**" > release_notes.md
echo "" >> release_notes.md
cat current_changelog.md >> release_notes.md
echo "" >> release_notes.md
fi
fi
# Generate commit-based changelog since last tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
echo "## 📝 Commits since $PREV_TAG" >> release_notes.md
echo "" >> release_notes.md
git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD >> release_notes.md
echo "" >> release_notes.md
fi
# Add package info
echo "" >> release_notes.md
echo "## 📦 Installation" >> release_notes.md
echo "" >> release_notes.md
echo "\`\`\`bash" >> release_notes.md
echo "npm install commit-from-branch@$VERSION" >> release_notes.md
echo "\`\`\`" >> release_notes.md
if [ -f "release_notes.md" ]; then
echo "changelog<<EOF" >> $GITHUB_OUTPUT
cat release_notes.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "changelog=🚀 Release $VERSION" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: "🚀 Release v${{ steps.version.outputs.version }}"
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to NPM
run: |
echo "📦 Publishing to NPM..."
if [[ "${{ steps.version.outputs.version }}" == *"-"* ]]; then
echo "🔄 Pre-release version detected, publishing with 'next' tag"
npm publish --tag next
else
echo "✅ Stable version, publishing with 'latest' tag"
npm publish
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Success notification
run: |
echo "🎉 Release completed successfully!"
echo "📦 Package: https://www.npmjs.com/package/commit-from-branch"
echo "🏷️ Release: https://github.com/$GITHUB_REPOSITORY/releases/tag/${{ steps.version.outputs.tag }}"