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
14 changes: 12 additions & 2 deletions .github/scripts/generate-quality-report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
Path("maven/core-unittests/src/test/java"),
]

DEFAULT_REPORT_TITLE = "✅ Continuous Quality Report"


def _load_target_dirs() -> List[Path]:
env_value = os.environ.get("QUALITY_REPORT_TARGET_DIRS")
Expand Down Expand Up @@ -618,6 +620,7 @@ def build_report(
html_urls: Dict[str, Optional[str]],
coverage_html_url: Optional[str],
coverage_archive_url: Optional[str],
title: str,
) -> str:
if HTML_REPORT_DIR.exists():
for child in HTML_REPORT_DIR.iterdir():
Expand Down Expand Up @@ -650,7 +653,7 @@ def build_report(
blob_base = f"{server_url.rstrip('/')}/{repository}/blob/{ref}"

lines = [
"## ✅ Continuous Quality Report",
f"## {title}",
"",
"### Test & Coverage",
format_tests(tests),
Expand Down Expand Up @@ -714,7 +717,14 @@ def main() -> None:
coverage_html_url = os.environ.get("JACOCO_HTML_URL")
coverage_archive_url = os.environ.get("JACOCO_REPORT_URL")
generate_html_only = os.environ.get("QUALITY_REPORT_GENERATE_HTML_ONLY") == "1"
report = build_report(archive_urls, html_urls, coverage_html_url, coverage_archive_url)
report_title = os.environ.get("QUALITY_REPORT_TITLE") or DEFAULT_REPORT_TITLE
report = build_report(
archive_urls,
html_urls,
coverage_html_url,
coverage_archive_url,
report_title,
)
if not generate_html_only:
REPORT_PATH.write_text(report + "\n", encoding="utf-8")

Expand Down
48 changes: 48 additions & 0 deletions .github/scripts/publish-quality-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('fs');

/**
* Publish or update a pull request comment containing a quality report.
*
* @param {{github: import('@actions/github').GitHub, context: any, core: any, marker?: string, reportPath?: string}} options
*/
async function publishQualityComment({ github, context, core, marker, reportPath }) {
const effectiveMarker = marker || '<!-- quality-report -->';
const report = reportPath || 'quality-report.md';

if (!fs.existsSync(report)) {
core.warning(`${report} was not generated.`);
return;
}

const body = `${effectiveMarker}\n${fs.readFileSync(report, 'utf8')}`;
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
per_page: 100,
});

const existing = comments.find(
(comment) => comment.user?.type === 'Bot' && comment.body?.includes(effectiveMarker),
);

if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
}

module.exports = { publishQualityComment };
79 changes: 79 additions & 0 deletions .github/workflows/parparvm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,85 @@ jobs:
java-version: '8'
cache: 'maven'

- name: Install native build tools
run: |
sudo apt-get update
sudo apt-get install -y clang

- name: Run ParparVM JVM tests
working-directory: vm/tests
run: mvn -B test

- name: Publish ByteCodeTranslator quality previews
if: ${{ always() && github.server_url == 'https://github.com' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
id: publish-bytecode-quality-previews
env:
GITHUB_TOKEN: ${{ github.token }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
set -euo pipefail
if [ "${SERVER_URL}" != "https://github.com" ]; then
echo "HTML previews are only published for github.com instances."
exit 0
fi

coverage_dir="vm/tests/target/site/jacoco"
if [ ! -f "${coverage_dir}/index.html" ]; then
echo "No HTML outputs detected; skipping preview publishing."
exit 0
fi

run_dir="runs/${RUN_ID}-${RUN_ATTEMPT}"
tmp_dir=$(mktemp -d)
dest_dir="${tmp_dir}/${run_dir}/coverage"
mkdir -p "${dest_dir}"
cp -R "${coverage_dir}/." "${dest_dir}/"

printf '%s\n%s\n%s\n' \
'# Quality report previews' \
'' \
'This branch is automatically managed by the PR CI workflow and may be force-pushed.' \
> "${tmp_dir}/README.md"

git -C "${tmp_dir}" init -b previews >/dev/null
git -C "${tmp_dir}" config user.name "github-actions[bot]"
git -C "${tmp_dir}" config user.email "github-actions[bot]@users.noreply.github.com"
git -C "${tmp_dir}" add .
git -C "${tmp_dir}" commit -m "Publish quality report previews for run ${RUN_ID} (attempt ${RUN_ATTEMPT})" >/dev/null

remote_url="${SERVER_URL}/${REPOSITORY}.git"
token_remote_url="${remote_url/https:\/\//https://x-access-token:${GITHUB_TOKEN}@}"
git -C "${tmp_dir}" push --force "${token_remote_url}" previews:quality-report-previews >/dev/null

commit_sha=$(git -C "${tmp_dir}" rev-parse HEAD)
raw_base="https://raw.githubusercontent.com/${REPOSITORY}/${commit_sha}/${run_dir}"
preview_base="https://htmlpreview.github.io/?${raw_base}"
echo "jacoco_url=${preview_base}/coverage/index.html" >> "$GITHUB_OUTPUT"

- name: Generate ByteCodeTranslator quality report
if: ${{ always() }}
env:
QUALITY_REPORT_TARGET_DIRS: vm/tests/target
QUALITY_REPORT_SERVER_URL: ${{ github.server_url }}
QUALITY_REPORT_REPOSITORY: ${{ github.repository }}
QUALITY_REPORT_REF: ${{ github.event.pull_request.head.sha || github.sha }}
QUALITY_REPORT_TITLE: "✅ ByteCodeTranslator Quality Report"
JACOCO_HTML_URL: ${{ steps.publish-bytecode-quality-previews.outputs.jacoco_url }}
run: python3 .github/scripts/generate-quality-report.py

- name: Publish ByteCodeTranslator quality comment
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
script: |
const { publishQualityComment } = require('./.github/scripts/publish-quality-comment.js');
await publishQualityComment({
github,
context,
core,
marker: '<!-- bytecode-quality-report -->',
reportPath: 'quality-report.md',
});
36 changes: 2 additions & 34 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,40 +205,8 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const marker = '<!-- quality-report -->';
const reportPath = 'quality-report.md';
if (!fs.existsSync(reportPath)) {
core.warning('quality-report.md was not generated.');
return;
}
const body = `${marker}\n${fs.readFileSync(reportPath, 'utf8')}`;
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
per_page: 100,
});
const existing = comments.find(
(comment) => comment.user?.type === 'Bot' && comment.body?.includes(marker),
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
const { publishQualityComment } = require('./.github/scripts/publish-quality-comment.js');
await publishQualityComment({ github, context, core });
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install xvfb
Expand Down
Loading
Loading