fix script (#1223)

This commit is contained in:
Léo Galley
2024-11-07 15:40:09 -05:00
committed by GitHub
parent ce51c6e33d
commit 24dbe96e0d

View File

@@ -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);
}
}