diff --git a/.github/workflows/_ci.yml b/.github/workflows/_ci.yml index fd26f8f..9051d54 100644 --- a/.github/workflows/_ci.yml +++ b/.github/workflows/_ci.yml @@ -15,6 +15,44 @@ jobs: pull-requests: write runs-on: ubuntu-latest steps: + - name: Mark lint run in progress + if: >- + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + script: | + const marker = ''; + const workflowUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number }); + const existing = comments.find((comment) => comment.body?.includes(marker)); + let previous = ''; + if (existing) { + if (existing.body.includes('this comment will be updated when the run completes')) { + const match = existing.body.match(/
Previous run output<\/summary>\n\n([\s\S]*)\n\n<\/details>\s*$/); + previous = match ? match[1].trim() : ''; + } else { + previous = existing.body.replace(marker, '').trim(); + } + } + const parts = [ + marker, + '#### Shared Workflows CI', + '', + 'Shared workflows CI is in progress; this comment will be updated when the run completes.', + '', + `[View the workflow run](${workflowUrl}).`, + ]; + if (previous) { + parts.push('', '
Previous run output', '', previous, '', '
'); + } + const body = parts.join('\n'); + if (existing) { + await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: existing.id, body }); + } else { + await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body }); + } + - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -47,13 +85,27 @@ jobs: const maxLength = 12000; const output = fs.existsSync('validation.log') ? fs.readFileSync('validation.log', 'utf8') - .replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '') .replace(/\b(?:gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/g, '***REDACTED***') .replace(/````/g, '\\`\\`\\`\\`') : 'No validation output was captured.'; const excerpt = output.length > maxLength ? output.slice(-maxLength) : output; const status = failed ? 'failed' : 'passed'; - const body = `${marker}\n## Shared workflows CI ${status}\n\n[View the workflow run](${workflowUrl}).\n\n#### Validation output (redacted, last ${maxLength} characters)\n\n\`\`\`\`text\n${excerpt}\n\`\`\`\``; + const body = [ + marker, + '#### Shared Workflows CI', + '', + `Shared workflows CI ${status}.`, + '', + `[View the workflow run](${workflowUrl}).`, + '', + '
View run output', + '', + '````text', + excerpt, + '````', + '', + '
', + ].join('\n'); const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo,