Skip to content

Record Changeset

Record Changeset #12

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@v3
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@v3
with:
node-version: "18.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 changeset and capture the output
CHANGESET_OUTPUT=$(npx changeset add --empty --message "${COMMIT_MESSAGE}" --type "${{ github.event.inputs.version_type }}")
# Extract filename from changeset output
CHANGESET_FILE=$(echo "$CHANGESET_OUTPUT" | grep -o '[a-z0-9\-]\+\.md')
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
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"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.changeset.outputs.changeset_file }}
title: "Add changeset for ${COMMIT_MSG}"
body: "This pull request adds a changeset for ${COMMIT_MSG}. Please review."
labels: ["changeset"]

Check failure on line 81 in .github/workflows/record-changeset.yml

View workflow run for this annotation

GitHub Actions / Record Changeset

Invalid workflow file

The workflow is not valid. .github/workflows/record-changeset.yml (Line: 81, Col: 19): A sequence was not expected
permissions:
contents: write
pull-requests: write