chore: bump version to 1.0.9 #65
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: Auto Changelog | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag version (optional)' | |
| required: false | |
| type: string | |
| jobs: | |
| auto-changelog: | |
| runs-on: ubuntu-latest | |
| # Skip if commit is from github-actions bot or contains [skip ci] | |
| if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'github-actions[bot]'" | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GA_TOKEN }} | |
| # Always checkout main branch for consistency | |
| ref: main | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| # Remove cache since we're using pnpm and installing globally | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: latest | |
| - name: Install auto-changelog | |
| run: npm install -g auto-changelog | |
| - name: Determine version bump | |
| id: version-bump | |
| run: | | |
| # Get current version from package.json | |
| CURRENT_VERSION=$(node -e "console.log(require('./package.json').version)") | |
| echo "Current version: $CURRENT_VERSION" | |
| # Parse current version | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | |
| # Check commits since last tag for version bump type | |
| if git tag --list | grep -q "v"; then | |
| LAST_TAG=$(git tag --list "v*" | sort -V | tail -n1) | |
| COMMITS=$(git log ${LAST_TAG}..HEAD --oneline) | |
| else | |
| COMMITS=$(git log --oneline) | |
| fi | |
| echo "Commits to analyze:" | |
| echo "$COMMITS" | |
| # Determine bump type based on conventional commits | |
| BUMP_TYPE="none" | |
| if echo "$COMMITS" | grep -qE "^[a-f0-9]+ (feat|fix|perf)(\(.+\))?!:"; then | |
| BUMP_TYPE="major" | |
| elif echo "$COMMITS" | grep -qE "BREAKING CHANGE"; then | |
| BUMP_TYPE="major" | |
| elif echo "$COMMITS" | grep -qE "^[a-f0-9]+ feat(\(.+\))?:"; then | |
| BUMP_TYPE="minor" | |
| elif echo "$COMMITS" | grep -qE "^[a-f0-9]+ (fix|perf)(\(.+\))?:"; then | |
| BUMP_TYPE="patch" | |
| fi | |
| echo "Detected bump type: $BUMP_TYPE" | |
| # Calculate new version | |
| case $BUMP_TYPE in | |
| major) | |
| NEW_VERSION="$((MAJOR + 1)).0.0" | |
| ;; | |
| minor) | |
| NEW_VERSION="${MAJOR}.$((MINOR + 1)).0" | |
| ;; | |
| patch) | |
| NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" | |
| ;; | |
| none) | |
| NEW_VERSION="$CURRENT_VERSION" | |
| ;; | |
| esac | |
| echo "New version: $NEW_VERSION" | |
| echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update package.json version (auto-bump) | |
| if: steps.version-bump.outputs.bump_type != 'none' | |
| run: | | |
| NEW_VERSION="${{ steps.version-bump.outputs.new_version }}" | |
| echo "Updating package.json version to $NEW_VERSION" | |
| # Update package.json version using node | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.version = '$NEW_VERSION'; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| - name: Update package.json version from manual tag | |
| if: github.event.inputs.tag != '' && steps.version-bump.outputs.bump_type == 'none' | |
| run: | | |
| # Extract version from input tag (remove 'v' prefix if present) | |
| TAG_VERSION="${{ github.event.inputs.tag }}" | |
| TAG_VERSION=${TAG_VERSION#v} | |
| echo "Updating package.json version to $TAG_VERSION" | |
| # Update package.json version using node | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.version = '$TAG_VERSION'; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| - name: Create git tag for new version | |
| if: steps.version-bump.outputs.bump_type != 'none' | |
| run: | | |
| NEW_VERSION="${{ steps.version-bump.outputs.new_version }}" | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| # Create and push tag | |
| git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION" | |
| git push origin "v$NEW_VERSION" | |
| - name: Generate CHANGELOG.md | |
| run: | | |
| # Generate changelog using auto-changelog | |
| auto-changelog --template keepachangelog \ | |
| --commit-limit false \ | |
| --unreleased \ | |
| --sort-commits date \ | |
| --ignore-commit-pattern "docs: auto-update|\\[skip ci\\]" \ | |
| --commit-url "https://github.com/chess-labs/chessboard/commit/{id}" \ | |
| --compare-url "https://github.com/chess-labs/chessboard/compare/{from}...{to}" \ | |
| --issue-url "https://github.com/chess-labs/chessboard/issues/{id}" | |
| - name: Check for changes | |
| id: check-changes | |
| run: | | |
| if git diff --quiet; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "No changes to commit" | |
| else | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Changes detected" | |
| echo "Git diff:" | |
| git diff | |
| fi | |
| - name: Commit and push changes | |
| if: steps.check-changes.outputs.changed == 'true' | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| # Ensure we're on a branch before committing | |
| CURRENT_BRANCH=$(git branch --show-current) | |
| if [ -z "$CURRENT_BRANCH" ]; then | |
| echo "Currently in detached HEAD state, checking out main branch" | |
| git checkout -B main | |
| fi | |
| git add . | |
| # Create commit message based on version bump | |
| if [ "${{ steps.version-bump.outputs.bump_type }}" != "none" ]; then | |
| COMMIT_MSG="docs: auto-update changelog and version to v${{ steps.version-bump.outputs.new_version }} [skip ci]" | |
| else | |
| COMMIT_MSG="docs: auto-update changelog [skip ci]" | |
| fi | |
| git commit -m "$COMMIT_MSG" | |
| # Push to the current branch or main if in detached HEAD | |
| if [ -n "$CURRENT_BRANCH" ]; then | |
| git push origin "$CURRENT_BRANCH" | |
| else | |
| git push origin main | |
| fi |