From 24dbe96e0d38e243bd014cd41dfbeaa30d1b8a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Galley?= Date: Thu, 7 Nov 2024 15:40:09 -0500 Subject: [PATCH] fix script (#1223) --- .github/workflows/file-size-checker.yml | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/workflows/file-size-checker.yml b/.github/workflows/file-size-checker.yml index 18fbc30..a8c438e 100644 --- a/.github/workflows/file-size-checker.yml +++ b/.github/workflows/file-size-checker.yml @@ -85,22 +85,20 @@ jobs: const largeFiles = `${{ steps.check-sizes.outputs.large_files }}`; try { - console.log('Repository:', context.payload.repository.name); - console.log('Owner:', context.payload.repository.owner.login); - console.log('SHA:', context.payload.pull_request.head.sha); - - // Set status check that will be used by branch protection - await github.rest.repos.createCommitStatus({ - owner: context.payload.repository.owner.login, - repo: context.payload.repository.name, - sha: context.payload.pull_request.head.sha, - state: hugeFiles ? 'failure' : 'success', - context: 'File Size Check', - description: hugeFiles ? 'Files over 40MB found' : 'All files within size limits', - target_url: `https://github.com/${context.payload.repository.owner.login}/${context.payload.repository.name}/actions/runs/${context.runId}` - }); + // Only create status check if we have permission (not a fork PR) + if (context.payload.pull_request.head.repo.full_name === context.payload.repository.full_name) { + await github.rest.repos.createCommitStatus({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + sha: context.payload.pull_request.head.sha, + state: hugeFiles ? 'failure' : 'success', + context: 'File Size Check', + description: hugeFiles ? 'Files over 40MB found' : 'All files within size limits', + target_url: `https://github.com/${context.payload.repository.owner.login}/${context.payload.repository.name}/actions/runs/${context.runId}` + }); + } - // Only comment if issues were found + // Comments should work for both fork and non-fork PRs if (hugeFiles || largeFiles) { let comment = '## ⚠️ File Size Check Results\n\n'; @@ -124,5 +122,10 @@ jobs: } catch (error) { console.error('Error:', error); console.error('Context:', JSON.stringify(context.payload, null, 2)); - core.setFailed(error.message); + // Only ignore status check permission errors for fork PRs + if (error.status === 403 && context.payload.pull_request.head.repo.full_name !== context.payload.repository.full_name) { + console.log('Ignoring status check permission error for fork PR'); + } else { + core.setFailed(error.message); + } }