name: Version Bump on: push: branches: - main permissions: contents: write jobs: version-bump: runs-on: ubuntu-latest environment: Production # Skip if this is a version bump commit to avoid infinite loop if: "!contains(github.event.head_commit.message, 'chore: bump version')" steps: - name: Generate GitHub App token id: app-token uses: tibdex/github-app-token@v1 with: app_id: ${{ secrets.XGITHUB_APP_ID }} private_key: ${{ secrets.XGITHUB_APP_PRIVATE_KEY }} - name: Checkout code uses: actions/checkout@v4 with: # Use GitHub App token for checkout and push operations # This token has bypass permissions if the GitHub App is configured with them token: ${{ steps.app-token.outputs.token }} fetch-depth: 1 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 20.x - name: Configure Git env: GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" # Update remote URL to use GitHub App token for all git operations git remote set-url origin https://${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git - name: Pull latest changes run: | # Ensure we're on main and pull latest changes to avoid push conflicts git checkout main git pull origin main --ff-only - name: Bump version id: version run: | # Get current version CURRENT_VERSION=$(node -p "require('./package.json').version") echo "Current version: $CURRENT_VERSION" # Bump minor version (creates commit and tag) # The commit message includes [skip ci] to prevent triggering this workflow again NEW_VERSION=$(npm version minor -m "chore: bump version to %s" | sed 's/v//') echo "New version: $NEW_VERSION" echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT - name: Push changes env: GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} run: | # Push to main and tags using GitHub App token (remote URL already configured) git push origin main git push origin --tags