Record Changeset #10
This file contains 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: 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: "changeset-${{ steps.changeset.outputs.changeset_file }}" | ||
title: "Add changeset for ${{ github.event.head_commit.message }}" | ||
body: "This pull request adds a changeset for ${{ github.event.head_commit.message }}. Please review." | ||
labels: ["changeset"] | ||
permissions: | ||
contents: write | ||
pull-requests: write |