Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
80 changes: 57 additions & 23 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,78 @@ on:
workflow_run:
workflows: ["Integration Tests", "Unit Tests"]
types: [completed]
workflow_dispatch:

permissions:
contents: read

jobs:
finalize:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_sha == github.sha }}
# Needed for listWorkflowRunsForRepo and safe defaults for token scope
permissions:
actions: read
contents: read
statuses: write
# Prevent multiple concurrent finalizers for the same commit
concurrency:
group: coverage-${{ github.event.workflow_run.head_sha }}
cancel-in-progress: true
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
- id: check
name: Verify all prerequisite workflows succeeded
uses: actions/github-script@v7
with:
script: |
const workflows = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
head_sha: context.payload.workflow_run.head_sha,
const {owner, repo} = context.repo;
const headSha = context.payload.workflow_run?.head_sha || context.sha;

const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner,
repo,
head_sha: headSha,
status: 'completed',
per_page: 100
});

const bothComplete = ['Integration Tests', 'Unit Tests'].every(name =>
workflows.data.workflow_runs.some(
run => run.name === name && run.conclusion === 'success'
)
);
const findRun = (name) => runs.data.workflow_runs.find(r => r.name === name && r.conclusion === 'success');

const integration = findRun('Integration Tests');
const unit = findRun('Unit Tests');

const ok = Boolean(unit && integration);
core.info(ok ? 'All workflows completed successfully.' : 'Waiting for a remaining workflow to complete.');

core.setOutput('ready', String(ok));
if (ok) {
core.setOutput('unit_run_id', String(unit.id));
core.setOutput('integration_run_id', String(integration.id));
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Expose original head_sha and head_branch as outputs; use them in the Coveralls upload.

The goal is to “pass original context to Coveralls.” You already resolve headSha from the triggering run, but it isn’t exported for later steps; the Coveralls action will otherwise default to this workflow’s GITHUB_SHA/branch, which can mis-attribute coverage.

Apply:

       - id: check
         name: Verify all prerequisite workflows succeeded
         uses: actions/github-script@v7
         with:
           script: |
             const {owner, repo} = context.repo;
             const headSha = context.payload.workflow_run?.head_sha || context.sha;
+            const headBranch = context.payload.workflow_run?.head_branch || '';
 
             const runs = await github.rest.actions.listWorkflowRunsForRepo({
               owner,
               repo,
               head_sha: headSha,
               status: 'completed',
               per_page: 100
             });
 
             const findRun = (name) => runs.data.workflow_runs.find(r => r.name === name && r.conclusion === 'success');
             
             const integration = findRun('Integration Tests');
             const unit = findRun('Unit Tests');
 
             const ok = Boolean(unit && integration);
             core.info(ok ? 'All workflows completed successfully.' : 'Waiting for a remaining workflow to complete.');
 
             core.setOutput('ready', String(ok));
+            core.setOutput('head_sha', headSha);
+            core.setOutput('head_branch', headBranch);
             if (ok) {
               core.setOutput('unit_run_id', String(unit.id));
               core.setOutput('integration_run_id', String(integration.id));
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: Verify all prerequisite workflows succeeded
uses: actions/github-script@v7
with:
script: |
const workflows = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
head_sha: context.payload.workflow_run.head_sha,
const {owner, repo} = context.repo;
const headSha = context.payload.workflow_run?.head_sha || context.sha;
const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner,
repo,
head_sha: headSha,
status: 'completed',
per_page: 100
});
const bothComplete = ['Integration Tests', 'Unit Tests'].every(name =>
workflows.data.workflow_runs.some(
run => run.name === name && run.conclusion === 'success'
)
);
const findRun = (name) => runs.data.workflow_runs.find(r => r.name === name && r.conclusion === 'success');
const integration = findRun('Integration Tests');
const unit = findRun('Unit Tests');
const ok = Boolean(unit && integration);
core.info(ok ? 'All workflows completed successfully.' : 'Waiting for a remaining workflow to complete.');
core.setOutput('ready', String(ok));
if (ok) {
core.setOutput('unit_run_id', String(unit.id));
core.setOutput('integration_run_id', String(integration.id));
}
- id: check
name: Verify all prerequisite workflows succeeded
uses: actions/github-script@v7
with:
script: |
const {owner, repo} = context.repo;
const headSha = context.payload.workflow_run?.head_sha || context.sha;
const headBranch = context.payload.workflow_run?.head_branch || '';
const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner,
repo,
head_sha: headSha,
status: 'completed',
per_page: 100
});
const findRun = (name) => runs.data.workflow_runs.find(r => r.name === name && r.conclusion === 'success');
const integration = findRun('Integration Tests');
const unit = findRun('Unit Tests');
const ok = Boolean(unit && integration);
core.info(ok ? 'All workflows completed successfully.' : 'Waiting for a remaining workflow to complete.');
core.setOutput('ready', String(ok));
core.setOutput('head_sha', headSha);
core.setOutput('head_branch', headBranch);
if (ok) {
core.setOutput('unit_run_id', String(unit.id));
core.setOutput('integration_run_id', String(integration.id));
}
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 34-34: trailing spaces

(trailing-spaces)

🤖 Prompt for AI Agents
.github/workflows/coverage.yml around lines 18-46: the script computes headSha
from the triggering run but never exposes it (nor the originating head_branch),
so downstream steps (Coveralls upload) may use this workflow's SHA/branch and
mis-attribute coverage; add a headBranch variable by reading
context.payload.workflow_run?.head_branch || context.ref.split('/').pop(), and
call core.setOutput for both head_sha and head_branch (always, not only when ok)
so later steps can consume the original head commit and branch for the Coveralls
upload.

- if: ${{ steps.check.outputs.ready == 'true' }}
name: Download artifacts from Integration Tests run
uses: actions/download-artifact@v4
with:
name: coverage-integration-clover
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.check.outputs.integration_run_id }}
path: integration-coverage

- if: ${{ steps.check.outputs.ready == 'true' }}
name: Download artifacts from Unit Tests run
uses: actions/download-artifact@v4
with:
name: coverage-unit-clover
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.check.outputs.unit_run_id }}
path: unit-coverage

core.info(bothComplete ? 'Both workflows completed successfully.' : 'Waiting for other workflow to complete.');
core.setOutput('ready', String(bothComplete));
- if: ${{ steps.check.outputs.ready == 'true' }}
name: Merge Clover reports
uses: danielpalme/ReportGenerator-GitHub-Action@v5
with:
reports: |
unit-coverage/clover.xml;
integration-coverage/clover.xml
targetdir: merged-coverage
reporttypes: Clover

- if: ${{ steps.check.outputs.ready == 'true' }}
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b
name: Upload merged coverage to Coveralls
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
file: ./merged-coverage/Clover.xml
fail-on-error: false
13 changes: 6 additions & 7 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ jobs:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

- name: Upload coverage results to Coveralls
- name: Upload integration coverage artifact
if: matrix.calculate-code-coverage == true
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2
uses: actions/upload-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./var/logs/test-coverage/integration/clover.xml
parallel: true
flag-name: "Integration"
fail-on-error: false
name: coverage-integration-clover
path: ./var/logs/test-coverage/integration/clover.xml
if-no-files-found: error
retention-days: 7
13 changes: 6 additions & 7 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ jobs:
- name: Run unit test suite
run: composer run-unit-tests

- name: Upload coverage results to Coveralls
- name: Upload unit coverage artifact
if: matrix.calculate-code-coverage == true
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2
uses: actions/upload-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./var/logs/test-coverage/unit/clover.xml
parallel: true
flag-name: "Unit"
fail-on-error: false
name: coverage-unit-clover
path: ./var/logs/test-coverage/unit/clover.xml
if-no-files-found: error
retention-days: 7
Loading