diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 0000000..eb37f64 --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -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 }}" \ No newline at end of file diff --git a/package.json b/package.json index 97b8e5c..45b5430 100644 --- a/package.json +++ b/package.json @@ -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": [