Skip to content
Merged
Show file tree
Hide file tree
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
169 changes: 169 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: πŸš€ Automated Release on PR Merge

on:
pull_request:
types: [closed]
branches: [master, main]

jobs:
auto-release:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master'
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: read

steps:
- name: πŸ›’ Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: πŸ“¦ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: πŸ“₯ Install dependencies
run: npm ci

- name: πŸ§ͺ Run tests
run: npm test

- name: πŸ—οΈ Build package
run: npm run build

- name: πŸ” Safe version detection with manual override
id: version
run: |
PR_TITLE="${{ github.event.pull_request.title }}"

echo "πŸ” Analyzing PR: $PR_TITLE"

# 🎯 1. MANUAL OVERRIDE (highest priority)
if echo "$PR_TITLE" | grep -E "\[(patch|minor|major)\]"; then
MANUAL_VERSION=$(echo "$PR_TITLE" | grep -oE "(patch|minor|major)")
echo "bump=$MANUAL_VERSION" >> $GITHUB_OUTPUT
echo "🎯 MANUAL OVERRIDE: $MANUAL_VERSION"

# πŸ”΄ 2. MAJOR - Exact prefix match only
elif [[ "$PR_TITLE" == "BREAKING CHANGE:"* ]] || \
[[ "$PR_TITLE" == "breaking:"* ]] || \
[[ "$PR_TITLE" == "MAJOR:"* ]] || \
[[ "$PR_TITLE" == "NEW VERSION:"* ]]; then
echo "bump=major" >> $GITHUB_OUTPUT
echo "πŸ”΄ MAJOR: Breaking change or new version"

# 🟑 3. MINOR - Exact prefix match only
elif [[ "$PR_TITLE" == "feat:"* ]] || \
[[ "$PR_TITLE" == "feature:"* ]] || \
[[ "$PR_TITLE" == "add:"* ]] || \
[[ "$PR_TITLE" == "enhance:"* ]]; then
echo "bump=minor" >> $GITHUB_OUTPUT
echo "🟑 MINOR: New feature"

# 🟒 4. PATCH - Safe default
else
echo "bump=patch" >> $GITHUB_OUTPUT
echo "🟒 PATCH: Bug fix or maintenance (safe default)"
fi

- name: πŸ“ˆ Bump version
id: bump
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")

# πŸŽ‰ FIRST RELEASE LOGIC: If 0.0.0, always go to 1.0.0
if [ "$CURRENT_VERSION" = "0.0.0" ]; then
NEW_VERSION=$(npm version 1.0.0 --no-git-tag-version)
echo "πŸŽ‰ FIRST RELEASE: Bumping directly to v1.0.0"
else
NEW_VERSION=$(npm version ${{ steps.version.outputs.bump }} --no-git-tag-version)
echo "πŸ“ˆ Regular version bump: ${{ steps.version.outputs.bump }}"
fi

echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "current_version=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "πŸ“¦ Version bump: v$CURRENT_VERSION β†’ $NEW_VERSION"

- name: πŸ“ Generate release notes
id: release_notes
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
PR_TITLE="${{ github.event.pull_request.title }}"
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
PR_BODY="${{ github.event.pull_request.body }}"
NEW_VERSION="${{ steps.bump.outputs.version }}"

RELEASE_NOTES="## πŸŽ‰ Release $NEW_VERSION

**Merged PR:** $PR_TITLE (#$PR_NUMBER)
**Author:** @$PR_AUTHOR
**Version Bump:** ${{ steps.version.outputs.bump }}

### πŸ“‹ Changes:
$PR_BODY

---

### πŸ“¦ Installation:
\`\`\`bash
npm install @codechu/flow-core-container@$NEW_VERSION
\`\`\`

### πŸ”— Links:
- **NPM Package:** https://www.npmjs.com/package/@codechu/flow-core-container
- **Full Changelog:** https://github.com/${{ github.repository }}/compare/${{ steps.bump.outputs.current_version }}...$NEW_VERSION"

# Save to file to avoid shell escaping issues
cat > release_notes.md << 'EOF'
$RELEASE_NOTES
EOF

echo "Generated release notes for $NEW_VERSION"

- name: πŸ’Ύ Commit version bump
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"

git add package.json package-lock.json
git commit -m "πŸ”– Release ${{ steps.bump.outputs.version }}

Automated version bump from PR merge (#${{ github.event.pull_request.number }})
Author: @${{ github.event.pull_request.user.login }}
Type: ${{ steps.version.outputs.bump }}"

git push origin master

- name: 🏷️ Create tag and GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_VERSION="${{ steps.bump.outputs.version }}"

# Create and push tag
git tag $NEW_VERSION
git push origin $NEW_VERSION

# Create GitHub release
gh release create $NEW_VERSION \
--title "🏷️ $NEW_VERSION - Auto Release" \
--notes-file release_notes.md \
--latest

- name: πŸ“¦ Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: πŸŽ‰ Success notification
run: |
NEW_VERSION="${{ steps.bump.outputs.version }}"
echo "βœ… Successfully released $NEW_VERSION"
echo "πŸ“¦ NPM: https://www.npmjs.com/package/@codechu/flow-core-container"
echo "πŸ”— Release: https://github.com/${{ github.repository }}/releases/tag/$NEW_VERSION"
echo "πŸ“‹ PR: https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codechu/flow-core-container",
"version": "1.0.0",
"version": "0.0.0",
"type": "module",
"description": "Flow ecosystem container abstractions - Pure interfaces for dependency injection and service location with zero logic",
"keywords": [
Expand Down
Loading