Skip to content

Commit 14af4d5

Browse files
authored
Added tests and coverage report to ParparVM
* Refactor output routing into handler methods * Add clean target integration test * Add ByteCodeTranslator coverage reporting * Add coverage preview link to ByteCodeTranslator report
1 parent fcea7fa commit 14af4d5

File tree

8 files changed

+808
-317
lines changed

8 files changed

+808
-317
lines changed

.github/scripts/generate-quality-report.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
Path("maven/core-unittests/src/test/java"),
2626
]
2727

28+
DEFAULT_REPORT_TITLE = "✅ Continuous Quality Report"
29+
2830

2931
def _load_target_dirs() -> List[Path]:
3032
env_value = os.environ.get("QUALITY_REPORT_TARGET_DIRS")
@@ -618,6 +620,7 @@ def build_report(
618620
html_urls: Dict[str, Optional[str]],
619621
coverage_html_url: Optional[str],
620622
coverage_archive_url: Optional[str],
623+
title: str,
621624
) -> str:
622625
if HTML_REPORT_DIR.exists():
623626
for child in HTML_REPORT_DIR.iterdir():
@@ -650,7 +653,7 @@ def build_report(
650653
blob_base = f"{server_url.rstrip('/')}/{repository}/blob/{ref}"
651654

652655
lines = [
653-
"## ✅ Continuous Quality Report",
656+
f"## {title}",
654657
"",
655658
"### Test & Coverage",
656659
format_tests(tests),
@@ -714,7 +717,14 @@ def main() -> None:
714717
coverage_html_url = os.environ.get("JACOCO_HTML_URL")
715718
coverage_archive_url = os.environ.get("JACOCO_REPORT_URL")
716719
generate_html_only = os.environ.get("QUALITY_REPORT_GENERATE_HTML_ONLY") == "1"
717-
report = build_report(archive_urls, html_urls, coverage_html_url, coverage_archive_url)
720+
report_title = os.environ.get("QUALITY_REPORT_TITLE") or DEFAULT_REPORT_TITLE
721+
report = build_report(
722+
archive_urls,
723+
html_urls,
724+
coverage_html_url,
725+
coverage_archive_url,
726+
report_title,
727+
)
718728
if not generate_html_only:
719729
REPORT_PATH.write_text(report + "\n", encoding="utf-8")
720730

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const fs = require('fs');
2+
3+
/**
4+
* Publish or update a pull request comment containing a quality report.
5+
*
6+
* @param {{github: import('@actions/github').GitHub, context: any, core: any, marker?: string, reportPath?: string}} options
7+
*/
8+
async function publishQualityComment({ github, context, core, marker, reportPath }) {
9+
const effectiveMarker = marker || '<!-- quality-report -->';
10+
const report = reportPath || 'quality-report.md';
11+
12+
if (!fs.existsSync(report)) {
13+
core.warning(`${report} was not generated.`);
14+
return;
15+
}
16+
17+
const body = `${effectiveMarker}\n${fs.readFileSync(report, 'utf8')}`;
18+
const { owner, repo } = context.repo;
19+
const issue_number = context.issue.number;
20+
const { data: comments } = await github.rest.issues.listComments({
21+
owner,
22+
repo,
23+
issue_number,
24+
per_page: 100,
25+
});
26+
27+
const existing = comments.find(
28+
(comment) => comment.user?.type === 'Bot' && comment.body?.includes(effectiveMarker),
29+
);
30+
31+
if (existing) {
32+
await github.rest.issues.updateComment({
33+
owner,
34+
repo,
35+
comment_id: existing.id,
36+
body,
37+
});
38+
} else {
39+
await github.rest.issues.createComment({
40+
owner,
41+
repo,
42+
issue_number,
43+
body,
44+
});
45+
}
46+
}
47+
48+
module.exports = { publishQualityComment };

.github/workflows/parparvm-tests.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,85 @@ jobs:
2929
java-version: '8'
3030
cache: 'maven'
3131

32+
- name: Install native build tools
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install -y clang
36+
3237
- name: Run ParparVM JVM tests
3338
working-directory: vm/tests
3439
run: mvn -B test
40+
41+
- name: Publish ByteCodeTranslator quality previews
42+
if: ${{ always() && github.server_url == 'https://github.com' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
43+
id: publish-bytecode-quality-previews
44+
env:
45+
GITHUB_TOKEN: ${{ github.token }}
46+
SERVER_URL: ${{ github.server_url }}
47+
REPOSITORY: ${{ github.repository }}
48+
RUN_ID: ${{ github.run_id }}
49+
RUN_ATTEMPT: ${{ github.run_attempt }}
50+
run: |
51+
set -euo pipefail
52+
if [ "${SERVER_URL}" != "https://github.com" ]; then
53+
echo "HTML previews are only published for github.com instances."
54+
exit 0
55+
fi
56+
57+
coverage_dir="vm/tests/target/site/jacoco"
58+
if [ ! -f "${coverage_dir}/index.html" ]; then
59+
echo "No HTML outputs detected; skipping preview publishing."
60+
exit 0
61+
fi
62+
63+
run_dir="runs/${RUN_ID}-${RUN_ATTEMPT}"
64+
tmp_dir=$(mktemp -d)
65+
dest_dir="${tmp_dir}/${run_dir}/coverage"
66+
mkdir -p "${dest_dir}"
67+
cp -R "${coverage_dir}/." "${dest_dir}/"
68+
69+
printf '%s\n%s\n%s\n' \
70+
'# Quality report previews' \
71+
'' \
72+
'This branch is automatically managed by the PR CI workflow and may be force-pushed.' \
73+
> "${tmp_dir}/README.md"
74+
75+
git -C "${tmp_dir}" init -b previews >/dev/null
76+
git -C "${tmp_dir}" config user.name "github-actions[bot]"
77+
git -C "${tmp_dir}" config user.email "github-actions[bot]@users.noreply.github.com"
78+
git -C "${tmp_dir}" add .
79+
git -C "${tmp_dir}" commit -m "Publish quality report previews for run ${RUN_ID} (attempt ${RUN_ATTEMPT})" >/dev/null
80+
81+
remote_url="${SERVER_URL}/${REPOSITORY}.git"
82+
token_remote_url="${remote_url/https:\/\//https://x-access-token:${GITHUB_TOKEN}@}"
83+
git -C "${tmp_dir}" push --force "${token_remote_url}" previews:quality-report-previews >/dev/null
84+
85+
commit_sha=$(git -C "${tmp_dir}" rev-parse HEAD)
86+
raw_base="https://raw.githubusercontent.com/${REPOSITORY}/${commit_sha}/${run_dir}"
87+
preview_base="https://htmlpreview.github.io/?${raw_base}"
88+
echo "jacoco_url=${preview_base}/coverage/index.html" >> "$GITHUB_OUTPUT"
89+
90+
- name: Generate ByteCodeTranslator quality report
91+
if: ${{ always() }}
92+
env:
93+
QUALITY_REPORT_TARGET_DIRS: vm/tests/target
94+
QUALITY_REPORT_SERVER_URL: ${{ github.server_url }}
95+
QUALITY_REPORT_REPOSITORY: ${{ github.repository }}
96+
QUALITY_REPORT_REF: ${{ github.event.pull_request.head.sha || github.sha }}
97+
QUALITY_REPORT_TITLE: "✅ ByteCodeTranslator Quality Report"
98+
JACOCO_HTML_URL: ${{ steps.publish-bytecode-quality-previews.outputs.jacoco_url }}
99+
run: python3 .github/scripts/generate-quality-report.py
100+
101+
- name: Publish ByteCodeTranslator quality comment
102+
if: ${{ github.event_name == 'pull_request' }}
103+
uses: actions/github-script@v7
104+
with:
105+
script: |
106+
const { publishQualityComment } = require('./.github/scripts/publish-quality-comment.js');
107+
await publishQualityComment({
108+
github,
109+
context,
110+
core,
111+
marker: '<!-- bytecode-quality-report -->',
112+
reportPath: 'quality-report.md',
113+
});

.github/workflows/pr.yml

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -205,40 +205,8 @@ jobs:
205205
uses: actions/github-script@v7
206206
with:
207207
script: |
208-
const fs = require('fs');
209-
const marker = '<!-- quality-report -->';
210-
const reportPath = 'quality-report.md';
211-
if (!fs.existsSync(reportPath)) {
212-
core.warning('quality-report.md was not generated.');
213-
return;
214-
}
215-
const body = `${marker}\n${fs.readFileSync(reportPath, 'utf8')}`;
216-
const { owner, repo } = context.repo;
217-
const issue_number = context.issue.number;
218-
const { data: comments } = await github.rest.issues.listComments({
219-
owner,
220-
repo,
221-
issue_number,
222-
per_page: 100,
223-
});
224-
const existing = comments.find(
225-
(comment) => comment.user?.type === 'Bot' && comment.body?.includes(marker),
226-
);
227-
if (existing) {
228-
await github.rest.issues.updateComment({
229-
owner,
230-
repo,
231-
comment_id: existing.id,
232-
body,
233-
});
234-
} else {
235-
await github.rest.issues.createComment({
236-
owner,
237-
repo,
238-
issue_number,
239-
body,
240-
});
241-
}
208+
const { publishQualityComment } = require('./.github/scripts/publish-quality-comment.js');
209+
await publishQualityComment({ github, context, core });
242210
- name: Install dependencies
243211
run: |
244212
sudo apt-get update && sudo apt-get install xvfb

0 commit comments

Comments
 (0)