Skip to content

chore: release v0.1.0 changeset chore(changeset): add internal alpha … #12

chore: release v0.1.0 changeset chore(changeset): add internal alpha …

chore: release v0.1.0 changeset chore(changeset): add internal alpha … #12

Workflow file for this run

name: Version (Changesets)
on:
push:
branches:
- main
paths:
- '.changeset/**'
jobs:
version:
name: Create version commits and tags
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository (full)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: '10.15.0'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create version commits and tags (Changesets)
run: |
# Configure git user
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Get current CLI version before changesets
OLD_CLI_VERSION=$(node -e "console.log(require('./apps/pair-cli/package.json').version)")
echo "Old CLI version: $OLD_CLI_VERSION"
# Run changesets version (this updates package.json files and removes changeset files)
pnpm changeset version
# Get new CLI version after changesets
CLI_VERSION=$(node -e "console.log(require('./apps/pair-cli/package.json').version)")
echo "New CLI version: $CLI_VERSION"
# Check if there are any changes to commit
if [ -n "$(git status --porcelain)" ]; then
echo "Changes detected, creating commit..."
# Update root package.json version to match CLI version
node -e "const fs=require('fs'); const p=JSON.parse(fs.readFileSync('package.json','utf8')); p.version=process.argv[1]; fs.writeFileSync('package.json', JSON.stringify(p,null,2)+'\n');" "$CLI_VERSION"
# Stage all changes (updated package.json files and removed changeset files)
git add .
# Create the version commit
git commit -m "chore: release v$CLI_VERSION" -m "Version packages and remove changesets"
# Set environment variable for PR creation
echo "CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV
echo "HAS_CHANGES=true" >> $GITHUB_ENV
else
echo "No changes detected, skipping commit creation"
echo "HAS_CHANGES=false" >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push release branch
id: create_branch
if: ${{ env.HAS_CHANGES == 'true' }}
run: |
set -euo pipefail
# Create a new branch for the PR from current commit
BRANCH_NAME="changeset-release/v${{ env.CLI_VERSION }}-${{ github.run_number }}"
git checkout -b "$BRANCH_NAME"
# Push the new branch
git push origin "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Create release PR via REST API (no gh CLI) with retries
if: ${{ env.HAS_CHANGES == 'true' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch = '${{ steps.create_branch.outputs.branch_name }}'
const title = `chore: release v${{ env.CLI_VERSION }}`
const body = `Automated release PR for version ${{ env.CLI_VERSION }}.
This PR includes:
- Updated package versions based on changesets
- Removed processed changeset files
- Synchronized root package.json version
Created by the version workflow.`
const maxAttempts = 3
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
// Check for existing PR from branch
const existing = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${branch}`,
state: 'open'
})
if (existing.data && existing.data.length > 0) {
core.info(`Existing PR found: #${existing.data[0].number}`)
break
}
const response = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
head: branch,
base: 'main',
body,
})
core.info(`Created PR #${response.data.number}`)
break
} catch (err) {
core.warning(`Attempt ${attempt} failed to create PR: ${err.message}`)
if (attempt === maxAttempts) throw err
const delay = 5000 * attempt
core.info(`Retrying after ${delay}ms...`)
await new Promise(r => setTimeout(r, delay))
}
}
- name: No changes detected
if: ${{ env.HAS_CHANGES == 'false' }}
run: |
echo "No changesets were processed. This might happen if:"
echo "- Changeset files were already processed"
echo "- No valid changeset files exist"
echo "- Changeset files don't contain version bumps"
echo "Workflow completed without creating a PR."