Skip to content

ci: add coverage check workflow#6582

Merged
kuny0707 merged 9 commits intotronprotocol:developfrom
0xbigapple:feature/migrate_ci_8
Mar 26, 2026
Merged

ci: add coverage check workflow#6582
kuny0707 merged 9 commits intotronprotocol:developfrom
0xbigapple:feature/migrate_ci_8

Conversation

@0xbigapple
Copy link
Copy Markdown
Contributor

Summary

This PR improves the CI pipeline by adding a complete coverage reporting workflow and reorganizing PR checks.

Changes

  • Add PR coverage workflow to generate and upload JaCoCo reports to Codecov
  • Add base coverage upload workflow for develop and release_* branches
  • Add a workflow to wait for Codecov project status to produce a stable PR check result
  • Move multi-platform build checks into a separate workflow
  • Add codecov.yml configuration for project coverage checks
  • Upgrade some action version to use NodeJs 24

Coverage Check Sequence Diagram(s)

sequenceDiagram
    participant GH as GitHub (PR Event)
    participant CGB as Coverage Build<br/>(PR Gen Artifact)
    participant AS as Artifact Storage
    participant CUP as Codecov Upload<br/>(PR Upload)
    participant CV as Codecov API
    participant CPW as Coverage Project<br/>(Waiting)

    GH->>CGB: Trigger on PR to develop/<br/>release_*
    CGB->>CGB: Checkout, setup JDK 8,<br/>build project
    CGB->>CGB: Generate JaCoCo<br/>reports
    CGB->>AS: Upload jacoco-coverage<br/>artifact
    CGB-->>CUP: Workflow complete signal
    
    CUP->>AS: Download jacoco-coverage<br/>artifact
    CUP->>GH: Fetch PR details<br/>(PR number, SHA, branch)
    CUP->>CV: Upload coverage data<br/>with PR context
    CV-->>CUP: Coverage upload<br/>acknowledged

    CPW->>CV: Poll codecov/project<br/>status (every 30s)
    CV-->>CPW: Return status<br/>(pending/success/failure)
    CPW->>CPW: Check legacy commit<br/>statuses & check-runs
    
    alt Status Success
        CPW-->>GH: Job succeeds
    else Status Failure
        CPW-->>GH: Job fails
    else Still Pending
        CPW->>CPW: Wait 30s,<br/>retry (max 120x)
    end
Loading

Notes

The coverage comparison report only take effect starting from the next PR.

if-no-files-found: error

upload-base-coverage:
name: Upload Base Coverage to Codecov
Copy link
Copy Markdown
Contributor

@bladehan1 bladehan1 Mar 17, 2026

Choose a reason for hiding this comment

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

Base coverage should be queried first, and regenerated only if coverage for a corresponding commit is not found. This improves efficiency.

Copy link
Copy Markdown

@liuyifei001 liuyifei001 Mar 17, 2026

Choose a reason for hiding this comment

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

Let’s clarify the roles of the two secrets that only access in tronprotocol environment:

  • secrets.CODECOV_TOKEN: used to upload coverage artifacts
  • secrets.CODECOV_API_TOKEN: used to query coverage reports

Due to GitHub’s permission restrictions, secrets.CODECOV_API_TOKEN is not available in forked pull requests, which prevents querying the base repository’s coverage first.

In addition, the maintainers of java-tron have not configured secrets.CODECOV_API_TOKEN; only the upload token (secrets.CODECOV_TOKEN) is set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree with @bladehan1 — running a full build + test on every push to develop is expensive. Consider querying Codecov API first to check if coverage for this commit already exists, and skip the build if it does. This could save significant CI minutes, especially on active branches with frequent merges.

Copy link
Copy Markdown

@liuyifei001 liuyifei001 Mar 22, 2026

Choose a reason for hiding this comment

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

The Codecov API was evaluated and validated during the initial design phase. But, the maintainers of java-tron refuse to configure secrets.CODECOV_API_TOKEN. Therefore, the procedure has to be changed and seems to be quite complex. Actually, push operations (mainly include merge operation) to develop are not very frequent, so it may be acceptable.

@@ -0,0 +1,58 @@
name: Coverage Build
Copy link
Copy Markdown
Contributor

@bladehan1 bladehan1 Mar 17, 2026

Choose a reason for hiding this comment

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

It is recommended to merge the PR code coverage workflow files.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Codecov Upload & Compare runs in tron-protocol environment triggered by another workflow, but Coverage Build can only runs in user' environment.

timeout-minutes: 70

steps:
- name: Wait for codecov/project status
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After uploading the coverage event, check whether it was successful.

Copy link
Copy Markdown

@liuyifei001 liuyifei001 Mar 17, 2026

Choose a reason for hiding this comment

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

Workflow Codecov Upload & Compare replies on Coverage Build. If we merge Coverage Build and Waiting Coverage project, Codecov Upload & Compare can never be triggered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The polling approach occupies a runner for up to 60 minutes just to check a status. Consider using workflow_run event to react to the Codecov upload completion instead of active polling, which would free up the runner slot. If polling is necessary (e.g., Codecov doesn't trigger workflow events), consider reducing intervalMs to 60s and maxAttempts to 30 (30 min total) — Codecov usually reports within 10-15 minutes.

Copy link
Copy Markdown

@liuyifei001 liuyifei001 Mar 22, 2026

Choose a reason for hiding this comment

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

The purpose of introducing a waiting job is to ensure developers are clearly notified: a PR must not be merged unless the Codecov report is available.

Without this waiting mechanism when ci starts, all CI checks may appear green when Codecov report is generating, which can mislead developers into thinking that all validations have passed successfully prematurely.

The waiting time is set to 70 minutes for the following reasons:

  1. The Codecov report depends on the completion of the Coverage Build job.
  2. The Coverage Build job is configured with a maximum runtime of 60 minutes.
  3. Therefore, the waiting job must exceed this duration.

Why does the Coverage Build job require up to 60 minutes? In practice, its execution time is highly variable, typically ranging from 18 to 40 minutes depending on current load of runner, and can occasionally be longer.

If the waiting time is set too short, it may fail prematurely, before the Codecov report is generated.

Copy link
Copy Markdown
Contributor

@vividctrlalt vividctrlalt left a comment

Choose a reason for hiding this comment

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

Minor: several new files are missing a trailing newline (pr-cancel.yml, coverage-waiting.yml, codecov.yml). Not functional, but violates POSIX convention and may cause noisy diffs when lines are appended later.

Copy link
Copy Markdown
Contributor

@vividctrlalt vividctrlalt left a comment

Choose a reason for hiding this comment

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

pr-build.yml runs independently without depending on pr-lint or checkstyle from pr-check.yml. In the previous setup, build jobs had needs: [pr-lint, checkstyle] so they'd skip if lint failed. Now that builds are in a separate workflow, a PR with lint errors will still trigger all platform builds, wasting CI resources. Consider adding a lightweight lint check step or using workflow_run to gate builds on pr-check success.

@liuyifei001
Copy link
Copy Markdown

Minor: several new files are missing a trailing newline (pr-cancel.yml, coverage-waiting.yml, codecov.yml). Not functional, but violates POSIX convention and may cause noisy diffs when lines are appended later.

Good suggestion, append trailing newline to 3 files.

@liuyifei001
Copy link
Copy Markdown

liuyifei001 commented Mar 22, 2026

pr-build.yml runs independently without depending on pr-lint or checkstyle from pr-check.yml. In the previous setup, build jobs had needs: [pr-lint, checkstyle] so they'd skip if lint failed. Now that builds are in a separate workflow, a PR with lint errors will still trigger all platform builds, wasting CI resources. Consider adding a lightweight lint check step or using workflow_run to gate builds on pr-check success.

PR Build and PR Check have different trigger conditions. PR Build cannot be triggered by pull_request edited and push operation, it's hard to combine them. Change the PR title or PR description should not trigger PR Build. Maybe can we move the checkstyle job from PR Check to PR Build?

@kuny0707 kuny0707 merged commit 4f38388 into tronprotocol:develop Mar 26, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants