Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

本项目使用两步 workflow 实现跨仓库 PR 的评论功能。

> 测试评论功能:验证 PR Check Comment workflow 是否正常工作。

## Workflows

### 1. PR Check (`pr-check.yml`)
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/pr-check-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ jobs:
const marker = '<!-- duckcoding-pr-check -->';
const platforms = ['ubuntu-22.04', 'windows-latest', 'macos-arm64', 'macos-x64'];

const prNumber = context.payload.workflow_run.pull_requests[0]?.number;
let prNumber = context.payload.workflow_run.pull_requests[0]?.number;

if (!prNumber) {
console.log('No PR number found');
return;
console.log('PR number not in workflow_run payload, trying to extract from artifacts...');
}

console.log('Updating comment for PR', prNumber);
console.log('Updating comment for PR', prNumber || '(to be determined)');

const defaultState = () => Object.fromEntries(
platforms.map(p => [p, {
Expand All @@ -96,13 +96,23 @@ jobs:
const platformState = JSON.parse(fs.readFileSync(stateFile, 'utf8'));
state[platform] = platformState;
console.log('Loaded state for', platform);

if (!prNumber && platformState.pr_number) {
prNumber = parseInt(platformState.pr_number, 10);
console.log('Extracted PR number from artifact:', prNumber);
}
} catch (e) {
console.error('Failed to parse state for', platform, e);
}
}
}
}

if (!prNumber) {
console.log('No PR number found in payload or artifacts');
return;
}

const statusLabelZh = (entry) => {
if (entry.status === 'pending') return '⏳ 运行中...';
if (entry.status === 'success') return '✅ 直接通过';
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ jobs:
"recheck": "${{ steps.recheck.outcome }}",
"artifact": "pr-check-${{ matrix.name }}",
"run_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"status": "${{ steps.check.outcome == 'success' && 'success' || (steps.check.outcome == 'failure' && steps.recheck.outcome == 'success' && 'fix_pass' || 'failed') }}"
"status": "${{ steps.check.outcome == 'success' && 'success' || (steps.check.outcome == 'failure' && steps.recheck.outcome == 'success' && 'fix_pass' || 'failed') }}",
"pr_number": "${{ github.event.pull_request.number }}"
}
EOF
cat state.json
Expand Down