From 828e7fb4a31ca5a22e2e04cd7708f0af0ef160e0 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Thu, 2 Apr 2026 13:22:37 +0530 Subject: [PATCH] fix(ci): use pull_request_target and github api to check changeset --- .github/workflows/check-changeset.yml | 41 +++++++++++++++------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/.github/workflows/check-changeset.yml b/.github/workflows/check-changeset.yml index 9d2dd2d6..cf16a9c6 100644 --- a/.github/workflows/check-changeset.yml +++ b/.github/workflows/check-changeset.yml @@ -1,7 +1,7 @@ name: Check Changeset on: - pull_request: + pull_request_target: types: [opened, synchronize, reopened, labeled, unlabeled] branches: - main @@ -32,26 +32,31 @@ jobs: 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 + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const pull_number = context.issue.number; + + // Fetch list of files changed in the PR + const files = await github.paginate(github.rest.pulls.listFiles, { + owner, + repo, + pull_number + }); + + const changesetFiles = files.filter(f => f.filename.startsWith('.changeset/') && f.filename.endsWith('.md')); + + if (changesetFiles.length === 0) { + core.setOutput('found', 'false'); + core.setFailed("❌ No changeset found. Run 'npx changeset' locally to create one for your changes."); + } else { + core.setOutput('found', 'true'); + console.log('✅ Changeset detected:\n' + changesetFiles.map(f => f.filename).join('\n')); + } - name: Comment on PR if missing if: failure() && steps.check.outputs.found == 'false'