Skip to content

add package readme

add package readme #14

name: Check Changeset
on:
pull_request:
types: [opened, synchronize, edited]
branches:
- main
jobs:
changeset-check:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Check for skip changeset flag
id: skip_check
uses: actions/github-script@v7
with:
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const prBody = pr.body || '';
const shouldSkip = prBody.includes('#skip-changeset');
if (shouldSkip) {
console.log('🔄 Found #skip-changeset in PR description. Skipping changeset check.');
}
return { skip: shouldSkip };
- name: Comment on PR - Skipped
if: fromJSON(steps.skip_check.outputs.result).skip == true
uses: actions/github-script@v7
with:
script: |
const commentBody = `## 🔄 Changeset Check Skipped
This PR has been marked to skip the changeset requirement using \`#skip-changeset\`.
**Note:** This should only be used for changes that don't affect the published package, such as:
- Documentation updates
- CI/CD changes
- Development tooling changes
- README updates
If this PR contains code changes that affect the public API, please remove \`#skip-changeset\` and add a proper changeset.
<!-- changeset-check-comment -->`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.body.includes('<!-- changeset-check-comment -->')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Exit early if skipped
if: fromJSON(steps.skip_check.outputs.result).skip == true
run: |
echo "✅ Changeset check skipped via PR description flag"
exit 0
- name: Install pnpm
if: fromJSON(steps.skip_check.outputs.result).skip != true
uses: pnpm/action-setup@v2
with:
version: 10
run_install: false
- name: Get pnpm store directory
if: fromJSON(steps.skip_check.outputs.result).skip != true
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
if: fromJSON(steps.skip_check.outputs.result).skip != true
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
if: fromJSON(steps.skip_check.outputs.result).skip != true
run: pnpm install --frozen-lockfile
- name: Check for changeset
if: fromJSON(steps.skip_check.outputs.result).skip != true
id: changeset_check
run: |
echo "Checking if this PR added a changeset file..."
# Check if this PR has added any new changeset files compared to main
git fetch origin main:main
# Look for new changeset files added in this PR (excluding README.md)
new_changesets=$(git diff --name-only --diff-filter=A main...HEAD | grep '^\.changeset/.*\.md$' | grep -v 'README\.md' || true)
if [ -n "$new_changesets" ]; then
echo "✅ This PR added the following changeset(s):"
echo "$new_changesets" | while read -r file; do
echo " - $(basename "$file")"
done
echo "status=success" >> $GITHUB_OUTPUT
else
echo "❌ This PR has not added any changeset files."
# Check if there are actually package changes that would require a changeset
status_output=$(pnpm changeset status --since=main 2>&1 || true)
echo "Changeset status output:"
echo "$status_output"
# If changeset status indicates changes but no changesets, we need one
if echo "$status_output" | grep -q "The following packages are changed but have no changesets"; then
echo "❌ Changes detected in packages but no changeset found in this PR!"
echo "status=missing" >> $GITHUB_OUTPUT
elif echo "$status_output" | grep -q "No changesets present"; then
echo "✅ No changeset needed (no package changes detected)"
echo "status=no_changes" >> $GITHUB_OUTPUT
else
echo "❌ Unable to determine status, requiring changeset for safety"
echo "status=missing" >> $GITHUB_OUTPUT
fi
fi
- name: Comment on PR - Missing Changeset
if: fromJSON(steps.skip_check.outputs.result).skip != true && steps.changeset_check.outputs.status == 'missing'
uses: actions/github-script@v7
with:
script: |
const commentBody = `## ❌ Missing Changeset
This PR appears to have changes but is missing a changeset.
**What you need to do:**
1. Run \`pnpm changeset\` in your local repository
2. Follow the prompts to describe your changes
3. Commit the generated changeset file
4. Push the changes to this PR
**Why changesets?**
Changesets help us:
- Track what changed between versions
- Generate accurate changelogs
- Determine appropriate version bumps
- Ensure nothing gets released without proper documentation
[Learn more about changesets](https://github.com/changesets/changesets)
<!-- changeset-check-comment -->`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.body.includes('<!-- changeset-check-comment -->')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Comment on PR - Changeset Found
if: fromJSON(steps.skip_check.outputs.result).skip != true && steps.changeset_check.outputs.status == 'success'
uses: actions/github-script@v7
with:
script: |
const commentBody = `## ✅ Changeset Found
Great! This PR includes the required changeset(s). The changes are properly documented and ready for review.
<!-- changeset-check-comment -->`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.body.includes('<!-- changeset-check-comment -->')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Fail if changeset is missing
if: fromJSON(steps.skip_check.outputs.result).skip != true && steps.changeset_check.outputs.status == 'missing'
run: |
echo "❌ This PR requires a changeset. Please add one and push the changes."
exit 1