Skip to content

Merge branch 'break/2.0.0-venus-version-v3' into break/2.0.0-venus-ve… #42

Merge branch 'break/2.0.0-venus-version-v3' into break/2.0.0-venus-ve…

Merge branch 'break/2.0.0-venus-version-v3' into break/2.0.0-venus-ve… #42

name: Auto Publish Beta to NPM (Monorepo)
# This workflow automatically publishes beta versions on push to break/* branches
# Beta versions follow the pattern: X.Y.Z-beta.N (e.g., 2.0.0-beta.38)
#
# Required secrets:
# 1. NPM_TOKEN: NPM automation token for publishing packages
# 2. RELEASE_TOKEN: GitHub PAT with bypass permissions (optional)
on:
push:
branches:
- 'break/**'
permissions:
contents: write
pull-requests: write
packages: write
actions: read
id-token: write # Required for NPM provenance
jobs:
auto-publish-beta:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup Turbo cache
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Install dependencies
run: |
echo "Installing monorepo dependencies..."
pnpm install --frozen-lockfile
- name: Detect changed packages
id: changes
run: |
echo "Detecting changes in packages compared to base branch..."
# For push events, compare with the branch this was pushed from
# For PR events, compare with the PR base
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
echo "PR detected - comparing with base: $BASE_BRANCH"
else
# For push to break/*, compare with main
BASE_BRANCH="main"
echo "Push detected - comparing with: $BASE_BRANCH"
fi
# Fetch base branch for comparison
git fetch origin $BASE_BRANCH
BASE_REF="origin/$BASE_BRANCH"
# Check for changes in each package
DESIGN_SYSTEM_CHANGED=false
COMPONENTS_CHANGED=false
if git diff --name-only HEAD $BASE_REF | grep -q "^packages/design-system/"; then
DESIGN_SYSTEM_CHANGED=true
echo "✅ Changes detected in design-system"
else
echo "⏭️ No changes in design-system"
fi
if git diff --name-only HEAD $BASE_REF | grep -q "^packages/components/"; then
COMPONENTS_CHANGED=true
echo "✅ Changes detected in react-components"
else
echo "⏭️ No changes in react-components"
fi
echo "design_system_changed=$DESIGN_SYSTEM_CHANGED" >> $GITHUB_OUTPUT
echo "components_changed=$COMPONENTS_CHANGED" >> $GITHUB_OUTPUT
# If no changes, skip publish
if [ "$DESIGN_SYSTEM_CHANGED" = "false" ] && [ "$COMPONENTS_CHANGED" = "false" ]; then
echo "should_publish=false" >> $GITHUB_OUTPUT
echo "⏭️ No changes detected in publishable packages, skipping publish"
else
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Run quality checks
if: steps.changes.outputs.should_publish == 'true'
run: |
echo "Running quality checks with Turbo..."
pnpm lint --filter=@kubit-ui-web/react-components --filter=@kubit-ui-web/design-system
pnpm typecheck --filter=@kubit-ui-web/react-components --filter=@kubit-ui-web/design-system
- name: Run tests
if: steps.changes.outputs.should_publish == 'true'
run: |
echo "Running tests with Turbo..."
pnpm test
- name: Build packages
if: steps.changes.outputs.should_publish == 'true'
run: |
echo "Building packages with Turbo..."
pnpm build
- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "Kubit Release Bot"
- name: Verify NPM authentication
run: |
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
echo "❌ NPM_TOKEN not configured"
exit 1
fi
npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Determine and publish beta versions
if: steps.changes.outputs.should_publish == 'true'
id: beta-publish
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
echo "Branch: $BRANCH_NAME"
PUBLISHED=""
HAS_PUBLISHED=false
# Function to calculate next beta version
calc_beta_version() {
local current=$1
node -e "
const current = '$current';
const betaMatch = current.match(/^(\d+\.\d+\.\d+)-beta\.(\d+)$/);
if (betaMatch) {
const base = betaMatch[1];
const num = parseInt(betaMatch[2]) + 1;
console.log(\`\${base}-beta.\${num}\`);
} else {
const parts = current.split('.').map(Number);
parts[0]++;
parts[1] = 0;
parts[2] = 0;
console.log(\`\${parts.join('.')}-beta.1\`);
}
"
}
# Publish design-system beta if changed
if [ "${{ steps.changes.outputs.design_system_changed }}" = "true" ]; then
echo "📦 Publishing @kubit-ui-web/design-system beta..."
cd packages/design-system
CURRENT=$(node -p "require('./package.json').version")
NEW=$(calc_beta_version "$CURRENT")
echo " $CURRENT → $NEW"
npm version $NEW --no-git-tag-version
pnpm publish --no-git-checks --access public --tag beta --provenance
PUBLISHED="$PUBLISHED\n- @kubit-ui-web/design-system@$NEW"
echo "design_system_version=$NEW" >> $GITHUB_OUTPUT
HAS_PUBLISHED=true
cd ../..
else
echo "⏭️ Skipping design-system (no changes)"
fi
# Publish components beta if changed
if [ "${{ steps.changes.outputs.components_changed }}" = "true" ]; then
echo "📦 Publishing @kubit-ui-web/react-components beta..."
cd packages/components
CURRENT=$(node -p "require('./package.json').version")
NEW=$(calc_beta_version "$CURRENT")
echo " $CURRENT → $NEW"
npm version $NEW --no-git-tag-version
pnpm publish --no-git-checks --access public --tag beta --provenance
PUBLISHED="$PUBLISHED\n- @kubit-ui-web/react-components@$NEW"
echo "components_version=$NEW" >> $GITHUB_OUTPUT
HAS_PUBLISHED=true
cd ../..
else
echo "⏭️ Skipping react-components (no changes)"
fi
echo "published=$PUBLISHED" >> $GITHUB_OUTPUT
echo "has_published=$HAS_PUBLISHED" >> $GITHUB_OUTPUT
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit version bumps
if: steps.beta-publish.outputs.has_published == 'true'
run: |
git add packages/*/package.json pnpm-lock.yaml
git commit -m "chore(beta): bump beta versions [skip ci]" || echo "No changes"
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
git push origin "$BRANCH_NAME" || echo "Push failed, continuing..."
- name: Create GitHub Release
if: steps.beta-publish.outputs.has_published == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.beta-publish.outputs.components_version }}
name: Beta Release v${{ steps.beta-publish.outputs.components_version }}
body: |
## 🧪 Beta Release
**Type:** Beta (experimental)
**Branch:** `${{ github.ref_name }}`
**Commit:** `${{ github.sha }}`
### ⚠️ Beta Notice
This is a **beta release** for testing purposes. Not recommended for production.
### 📦 Published Packages
${{ steps.beta-publish.outputs.published }}
### 📥 Installation
```bash
# Install specific versions
npm install @kubit-ui-web/react-components@${{ steps.beta-publish.outputs.components_version }}
npm install @kubit-ui-web/design-system@${{ steps.beta-publish.outputs.design_system_version }}
# Or install latest betas
npm install @kubit-ui-web/react-components@beta
npm install @kubit-ui-web/design-system@beta
```
### ✅ Quality Checks
- Linting passed
- Type checking passed
- Tests passed
- Builds successful
- Published with provenance 🔒
draft: false
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Success Summary
if: steps.beta-publish.outputs.has_published == 'true'
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🎉 BETA RELEASE SUCCESSFUL"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "📦 Published Packages:"
if [ "${{ steps.changes.outputs.design_system_changed }}" = "true" ]; then
echo " - @kubit-ui-web/design-system@${{ steps.beta-publish.outputs.design_system_version }}"
fi
if [ "${{ steps.changes.outputs.components_changed }}" = "true" ]; then
echo " - @kubit-ui-web/react-components@${{ steps.beta-publish.outputs.components_version }}"
fi
echo ""
echo "🔖 Tag: beta"
echo "🌿 Branch: ${{ github.ref_name }}"
echo "🔒 Provenance: Enabled"
echo "⚡ Built with Turbo cache"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: No changes summary
if: steps.changes.outputs.should_publish == 'false'
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "⏭️ NO CHANGES DETECTED"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "No changes detected in publishable packages."
echo "Skipping beta release."
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: Failure notification
if: failure()
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "❌ BETA RELEASE FAILED"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "🔍 Check logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo ""
echo "🔧 Common issues:"
echo " • NPM_TOKEN not configured or invalid"
echo " • Version already exists in NPM"
echo " • Tests or build failures"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"