Skip to content

Record Changeset

Record Changeset #24

name: Record Changeset
on:
workflow_dispatch:
inputs:
version_type:
description: "Change type"
required: true
type: choice
options:
- patch
- minor
- major
default: "patch"
jobs:
changeset:
name: Create Changeset
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Fetch main branch
run: |
git fetch origin main
git merge-base --is-ancestor origin/main HEAD || echo "Main branch is ahead"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Create Changeset
id: changeset
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "Creating changeset for: ${COMMIT_MESSAGE}"
# Create the changeset file first
CHANGESET_OUTPUT=$(npx changeset add --empty)
# Get the generated changeset filename
CHANGESET_FILE=$(echo "$CHANGESET_OUTPUT" | grep -o '[a-z0-9\-]\+\.md')
# Modify the changeset file to include the package
cat > ".changeset/${CHANGESET_FILE}" << EOF
---
"@avaprotocol/sdk-js": ${{ github.event.inputs.version_type }}
---
${COMMIT_MESSAGE}
EOF
echo "changeset_file=${CHANGESET_FILE}" >> $GITHUB_OUTPUT
# Verify changeset creation
if [ ! -d ".changeset" ]; then
echo "Error: .changeset directory not created"
exit 1
fi
- name: Commit and push changes
id: commit_and_push
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Add changeset files to commit
git add .changeset/
git commit -m "chore: add changeset for ${COMMIT_MSG}" || exit 1
# Create and checkout new branch using changeset filename
BRANCH_NAME="changeset-$(basename ${{ steps.changeset.outputs.changeset_file }} .md)"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
# Set commit message as output for later use
echo "commit_message=${COMMIT_MSG}" >> $GITHUB_ENV
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_ENV
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: ${{ env.commit_message }}
BRANCH_NAME: ${{ env.branch_name }}
run: |
gh pr create \
--title "Add changeset for ${COMMIT_MESSAGE}" \
--body "This pull request adds a changeset for ${COMMIT_MESSAGE}. Please review." \
--base main \
--head "$BRANCH_NAME"
permissions:
contents: write
pull-requests: write