Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 33 additions & 46 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
# Use a personal access token to bypass branch protection
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- name: 🟢 Setup Bun
uses: oven-sh/setup-bun@v1
Expand All @@ -67,39 +65,29 @@ jobs:
- name: 🏗️ Build package
run: bun run build

- name: 🔖 Determine version bump
id: version
- name: 📋 Get package info
id: package_info
run: |
# Get the last commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Commit message: $COMMIT_MSG"

# Determine version bump based on conventional commits
if echo "$COMMIT_MSG" | grep -q "BREAKING CHANGE\|!:"; then
echo "bump=major" >> $GITHUB_OUTPUT
echo "🔥 Major version bump detected"
elif echo "$COMMIT_MSG" | grep -q "^feat"; then
echo "bump=minor" >> $GITHUB_OUTPUT
echo "✨ Minor version bump detected"
elif echo "$COMMIT_MSG" | grep -q "^fix\|^perf\|^refactor"; then
echo "bump=patch" >> $GITHUB_OUTPUT
echo "🐛 Patch version bump detected"
else
echo "bump=patch" >> $GITHUB_OUTPUT
echo "📝 Default patch version bump"
fi

- name: 🔖 Bump version
run: |
npm version ${{ steps.version.outputs.bump }} --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "📈 Version bumped to $NEW_VERSION"
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "📦 Package: $PACKAGE_NAME@$CURRENT_VERSION"

- name: 🔍 Check if package exists on NPM
id: npm_check
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_NAME="${{ steps.package_info.outputs.name }}"
CURRENT_VERSION="${{ steps.package_info.outputs.version }}"

if npm view $PACKAGE_NAME@$CURRENT_VERSION version 2>/dev/null; then
echo "published=true" >> $GITHUB_OUTPUT
echo "🔄 Version $CURRENT_VERSION already published to NPM"
else
echo "published=false" >> $GITHUB_OUTPUT
echo "🆕 Version $CURRENT_VERSION not yet published to NPM"
fi

if npm view $PACKAGE_NAME version 2>/dev/null; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "📦 Package exists on NPM"
Expand All @@ -108,51 +96,50 @@ jobs:
echo "🆕 Package does not exist on NPM - will be first publish"
fi

- name: 🏷️ Create Git tag and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add package.json
git commit -m "🔖 chore: bump version to $NEW_VERSION [skip ci]"
git tag "v$NEW_VERSION"
git push origin master --tags

- name: 📦 Publish to NPM (First Time)
if: steps.npm_check.outputs.exists == 'false'
if: steps.npm_check.outputs.exists == 'false' && steps.npm_check.outputs.published == 'false'
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
echo "🆕 Publishing package for the first time..."
npm publish --access public
echo "✅ Successfully published to NPM!"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: 📦 Publish to NPM (Update)
if: steps.npm_check.outputs.exists == 'true'
if: steps.npm_check.outputs.exists == 'true' && steps.npm_check.outputs.published == 'false'
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
echo "📈 Publishing package update..."
npm publish --access public
echo "✅ Successfully published to NPM!"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: 📝 Create GitHub Release
- name: 📝 Create GitHub Release and Tag
if: steps.npm_check.outputs.published == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.NEW_VERSION }}
release_name: Release v${{ env.NEW_VERSION }}
tag_name: v${{ steps.package_info.outputs.version }}
release_name: Release v${{ steps.package_info.outputs.version }}
body: |
## 🎉 What's Changed

This release was automatically generated from the latest changes in master.

### 📦 Installation
```bash
npm install mini-react@${{ env.NEW_VERSION }}
npm install ${{ steps.package_info.outputs.name }}@${{ steps.package_info.outputs.version }}
```

### 🔗 NPM Package
https://www.npmjs.com/package/mini-react/v/${{ env.NEW_VERSION }}
https://www.npmjs.com/package/${{ steps.package_info.outputs.name }}/v/${{ steps.package_info.outputs.version }}
draft: false
prerelease: false

- name: ⏭️ Skip publishing
if: steps.npm_check.outputs.published == 'true'
run: |
echo "⏭️ Version ${{ steps.package_info.outputs.version }} already published - skipping"