From fd1dd4e52838cfdd6b1bd19f41dbf1c895c18068 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Tue, 31 Mar 2026 22:23:49 +0530 Subject: [PATCH] added --- .github/workflows/check-changeset.yml | 56 +++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-changeset.yml b/.github/workflows/check-changeset.yml index 68154007..cf43d2e5 100644 --- a/.github/workflows/check-changeset.yml +++ b/.github/workflows/check-changeset.yml @@ -1,32 +1,82 @@ +name: Check Changeset + on: pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] branches: - main # Avoid triggering this check for automated versioning PRs. # These PRs only update metadata and delete changesets, so they # don't require a new changeset file to be added. paths-ignore: - - "package.json" + - "package*.json" - "CHANGELOG.md" - ".changeset/**" +permissions: + pull-requests: write # Required for leaving comments + contents: read + jobs: changeset-check: runs-on: ubuntu-latest steps: + - name: Check for Bypass Label + id: check-label + run: | + if [[ "${{ contains(github.event.pull_request.labels.*.name, 'skip changeset') }}" == "true" ]]; then + echo "skip=true" >> "$GITHUB_OUTPUT" + echo "✅ 'skip changeset' label found. Bypassing check." + else + echo "skip=false" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@v4 + if: steps.check-label.outputs.skip != 'true' with: fetch-depth: 0 - name: Check for changeset + id: check + if: steps.check-label.outputs.skip != 'true' run: | CHANGED=$(git diff --name-only origin/main...HEAD | grep "^.changeset/.*\.md$" || true) if [ -z "$CHANGED" ]; then + echo "found=false" >> "$GITHUB_OUTPUT" echo "❌ No changeset found. Run 'npx changeset' locally to create one for your changes." exit 1 + else + echo "found=true" >> "$GITHUB_OUTPUT" + echo "✅ Changeset detected:" + echo "$CHANGED" fi - echo "✅ Changeset detected:" - echo "$CHANGED" + - name: Comment on PR if missing + if: failure() && steps.check.outputs.found == 'false' + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + const { owner, repo } = context.repo; + const issue_number = context.issue.number; + + // Fetch existing comments on the PR + const comments = await github.rest.issues.listComments({ + owner, + repo, + issue_number + }); + + const hasCommented = comments.data.some(c => c.body.includes(marker)); + + // Only comment if we haven't already + if (!hasCommented) { + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body: `${marker}\n### ⚠️ Changeset Missing\n\nThis PR does not have a changeset file. To help us effectively version these updates, please run the following command locally:\n\n\`\`\`bash\nnpx changeset\n\`\`\`\n\nFollow the prompts to select the version bump and write a short summary. Run:\n\n\`\`\`bash\ngit add ./.changeset/\n\`\`\`\n\nThen commit and push the changes to this branch.\n\n_If this PR doesn't require a version bump (e.g., docs, CI updates), maintainers can apply the \`skip changeset\` label to bypass this check._` + }); + } \ No newline at end of file