docs: updating readme badges #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test and Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| test: | |
| name: Run Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for changelog generation | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Build project | |
| run: bun run build | |
| - name: Run tests | |
| run: bun run test | |
| release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for version comparison | |
| fetch-tags: true | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Get current version | |
| id: current_version | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Current version: $VERSION" | |
| - name: Check if version tag exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse "v${{ steps.current_version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Version tag v${{ steps.current_version.outputs.version }} already exists" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "Version tag v${{ steps.current_version.outputs.version }} does not exist" | |
| fi | |
| - name: Get previous version tag | |
| id: previous_version | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$PREV_TAG" ]; then | |
| echo "tag=" >> $GITHUB_OUTPUT | |
| echo "No previous version tag found" | |
| else | |
| echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT | |
| echo "Previous version tag: $PREV_TAG" | |
| fi | |
| - name: Generate changelog | |
| id: changelog | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| VERSION="${{ steps.current_version.outputs.version }}" | |
| PREV_TAG="${{ steps.previous_version.outputs.tag }}" | |
| echo "Generating changelog from $PREV_TAG to HEAD" | |
| # Create changelog file | |
| CHANGELOG_FILE=$(mktemp) | |
| echo "## 🚀 What's Changed in v$VERSION" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| if [ -z "$PREV_TAG" ]; then | |
| # First release - list all commits | |
| echo "### All Changes" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| git log --pretty=format:"- %s (%h)" --reverse >> $CHANGELOG_FILE | |
| else | |
| # Generate changelog from previous tag | |
| COMMITS=$(git log $PREV_TAG..HEAD --pretty=format:"%s|%h|%an" --reverse) | |
| # Categorize commits | |
| FEATURES="" | |
| FIXES="" | |
| DOCS="" | |
| TESTS="" | |
| CHORES="" | |
| OTHER="" | |
| while IFS='|' read -r message hash author; do | |
| # Skip merge commits | |
| if [[ $message == Merge* ]]; then | |
| continue | |
| fi | |
| COMMIT_LINE="- $message ([${hash}](https://github.com/${{ github.repository }}/commit/${hash}))" | |
| if [[ $message == feat:* ]] || [[ $message == feature:* ]]; then | |
| FEATURES="$FEATURES$COMMIT_LINE"$'\n' | |
| elif [[ $message == fix:* ]]; then | |
| FIXES="$FIXES$COMMIT_LINE"$'\n' | |
| elif [[ $message == docs:* ]]; then | |
| DOCS="$DOCS$COMMIT_LINE"$'\n' | |
| elif [[ $message == test:* ]]; then | |
| TESTS="$TESTS$COMMIT_LINE"$'\n' | |
| elif [[ $message == chore:* ]] || [[ $message == build:* ]] || [[ $message == ci:* ]]; then | |
| CHORES="$CHORES$COMMIT_LINE"$'\n' | |
| else | |
| OTHER="$OTHER$COMMIT_LINE"$'\n' | |
| fi | |
| done <<< "$COMMITS" | |
| # Add sections to changelog if they have content | |
| if [ ! -z "$FEATURES" ]; then | |
| echo "### ✨ Features" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "$FEATURES" >> $CHANGELOG_FILE | |
| fi | |
| if [ ! -z "$FIXES" ]; then | |
| echo "### 🐛 Bug Fixes" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "$FIXES" >> $CHANGELOG_FILE | |
| fi | |
| if [ ! -z "$TESTS" ]; then | |
| echo "### 🧪 Tests" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "$TESTS" >> $CHANGELOG_FILE | |
| fi | |
| if [ ! -z "$DOCS" ]; then | |
| echo "### 📚 Documentation" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "$DOCS" >> $CHANGELOG_FILE | |
| fi | |
| if [ ! -z "$OTHER" ]; then | |
| echo "### 🔄 Other Changes" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "$OTHER" >> $CHANGELOG_FILE | |
| fi | |
| if [ ! -z "$CHORES" ]; then | |
| echo "### 🔧 Maintenance" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "$CHORES" >> $CHANGELOG_FILE | |
| fi | |
| fi | |
| echo "" >> $CHANGELOG_FILE | |
| echo "---" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$PREV_TAG...v$VERSION" >> $CHANGELOG_FILE | |
| # Output for GitHub Actions | |
| { | |
| echo 'body<<EOF' | |
| cat $CHANGELOG_FILE | |
| echo EOF | |
| } >> $GITHUB_OUTPUT | |
| echo "Changelog:" | |
| cat $CHANGELOG_FILE | |
| - name: Create Release | |
| if: steps.check_tag.outputs.exists == 'false' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.current_version.outputs.version }} | |
| name: v${{ steps.current_version.outputs.version }} | |
| body: ${{ steps.changelog.outputs.body }} | |
| draft: false | |
| prerelease: false | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Skip release | |
| if: steps.check_tag.outputs.exists == 'true' | |
| run: | | |
| echo "⏭️ Skipping release - version v${{ steps.current_version.outputs.version }} already exists" |