Merge pull request #69 from taroj1205/changeset-release/main #73
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: Version PR | |
on: | |
push: | |
branches: | |
- main | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
version: | |
permissions: | |
contents: write | |
pull-requests: write | |
issues: write | |
runs-on: ubuntu-latest | |
outputs: | |
has_changesets: ${{ steps.check-changesets.outputs.has_changesets }} | |
pr_number: ${{ steps.changeset-action.outputs.pullRequestNumber }} | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Install Dependencies | |
run: pnpm install | |
- name: Check for changesets | |
id: check-changesets | |
run: | | |
if [ -n "$(find .changeset -name '*.md' -not -name 'README.md')" ] || [ -n "$(find .changelog -name '*.mdx' -newer CHANGELOG.md)" ]; then | |
echo "has_changesets=true" >> $GITHUB_OUTPUT | |
else | |
echo "has_changesets=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Create PR or Merge | |
id: changeset-action | |
if: steps.check-changesets.outputs.has_changesets == 'true' | |
uses: changesets/action@v1 | |
with: | |
version: pnpm run version-packages | |
commit: "chore: version packages" | |
title: "Version Packages" | |
createGithubReleases: false | |
publish: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Update PR Description | |
if: steps.check-changesets.outputs.has_changesets == 'true' | |
run: | | |
PR_NUMBER="${{ steps.changeset-action.outputs.pullRequestNumber }}" | |
if [ -n "$PR_NUMBER" ]; then | |
# Get the latest version from package.json | |
VERSION=$(node -p "require('./package.json').version") | |
# Create .changelog directory if it doesn't exist | |
mkdir -p .changelog | |
# Copy the latest changes to version-specific MDX file | |
LATEST_CHANGES=$(awk '/^## / {count++} count==1 {print} count>1 {exit}' CHANGELOG.md | sed '1d') | |
echo "--- | |
title: Version $VERSION | |
date: $(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
--- | |
$LATEST_CHANGES" > ".changelog/$VERSION.mdx" | |
# Update PR description with changelog content | |
gh pr edit $PR_NUMBER --body "This PR was automatically created by the Version PR workflow to update versions and changelogs. | |
Changes in this version: | |
$LATEST_CHANGES" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |