name: 🚀 Auto Versioning the App concurrency: group: ${{ github.ref }} cancel-in-progress: true permissions: contents: write pull-requests: read on: push: branches: - prod jobs: bump-version: name: App Versioning Auto Bump runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Bump version based on last PR title id: bump run: | VERSION_FILE="src/documentation/version.ts" CURRENT_VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' $VERSION_FILE) BASE=$(echo $CURRENT_VERSION | cut -d. -f1,2) PATCH=$(echo $CURRENT_VERSION | cut -d. -f3) MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) echo "Current Version: $CURRENT_VERSION" PR_TITLE=$(gh pr list \ --state merged \ --base prod \ --limit 10 \ --json title,createdAt \ | jq -r 'sort_by(.createdAt) | last.title') echo "Last PR Title: $PR_TITLE" if [[ "$PR_TITLE" =~ ^(Fix|Enhance): ]]; then PATCH=$((PATCH + 1)) NEW_VERSION="$MAJOR.$MINOR.$PATCH" elif [[ "$PR_TITLE" =~ ^Build: ]]; then MINOR=$((MINOR + 1)) NEW_VERSION="$MAJOR.$MINOR.0" elif [[ "$PR_TITLE" =~ ^Upgrade: ]]; then MAJOR=$((MAJOR + 1)) NEW_VERSION="$MAJOR.0.0" else echo "No bump. Title doesn't match Fix:, Enhance:, Build:, or Upgrade:" exit 0 fi echo "export const APP_VERSION = \"$NEW_VERSION\";" > $VERSION_FILE echo "🔢 Bumped version to $NEW_VERSION" echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Update CHANGELOG.md if: steps.bump.outputs.new_version != '' run: | VERSION=${{ steps.bump.outputs.new_version }} DATE=$(date +"%Y-%m-%d") # Get last tag LAST_TAG=$(git tag --sort=-creatordate | head -n 1 || echo "") if [ -z "$LAST_TAG" ]; then LOG=$(git log -n 10 --pretty=format:"- %s") else LOG=$(git log "$LAST_TAG"..HEAD --pretty=format:"- %s") fi mkdir -p src/documentation # Ensure folder exists { echo "## v$VERSION - $DATE" echo "" echo "$LOG" echo "" } >> src/documentation/CHANGELOG.md - name: Commit and push version bump if: steps.bump.outputs.new_version != '' run: | git config user.name "Makkahwi Bot" git config user.email "SuhaibAhmadAi@hotmail.com" git add src/documentation/version.ts src/documentation/CHANGELOG.md git commit -m "chore(code): bump version to ${{ steps.bump.outputs.new_version }} [ci skip]" || echo "Nothing to commit" git push origin prod - name: Generate changelog from recent commits id: changelog run: | LAST_TAG=$(git tag --sort=-creatordate | head -n 1 || echo "") if [ -z "$LAST_TAG" ]; then echo "No previous tag found. Showing last 10 commits." LOG=$(git log -n 10 --pretty=format:"- %s") else echo "Previous tag: $LAST_TAG" LOG=$(git log "$LAST_TAG"..HEAD --pretty=format:"- %s") fi echo "log<> $GITHUB_OUTPUT echo "$LOG" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - name: Create GitHub Release if: steps.bump.outputs.new_version != '' uses: softprops/action-gh-release@v1 with: tag_name: v${{ steps.bump.outputs.new_version }} name: Release v${{ steps.bump.outputs.new_version }} body: | 🚀 Auto-generated release based on recent commits: ${{ steps.changelog.outputs.log }} **Full Changelog**: https://github.com/your-account/your-repo/commits/v${{ steps.bump.outputs.new_version }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}