Repository navigation
ci(common): coverage easy #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
5582cfc
84362f1
ef3f792
4f38388
039821c
b6bbf91
c455d43
4649e3b
c67ab3f
5945543
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| name: PR Build | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ 'master','develop', 'release_**' ] | ||
| types: [ opened, synchronize, reopened ] | ||
| paths: | ||
| - '**/*.java' | ||
| - '**/*.gradle' | ||
| - 'build.gradle' | ||
| - 'settings.gradle' | ||
| - 'gradle.properties' | ||
| - 'gradle/**' | ||
| - 'gradlew' | ||
| - 'gradlew.bat' | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| docker-build-debian11: | ||
| name: Build debian11 (JDK 8 / x86_64) | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 60 | ||
|
|
||
| container: | ||
| image: eclipse-temurin:8-jdk # base image is Debian 11 (Bullseye) | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| env: | ||
| GRADLE_USER_HOME: /github/home/.gradle | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Install dependencies (Debian + build tools) | ||
| run: | | ||
| set -euxo pipefail | ||
| apt-get update | ||
| apt-get install -y git wget unzip build-essential curl jq | ||
|
|
||
| - name: Check Java version | ||
| run: java -version | ||
|
|
||
| - name: Cache Gradle | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| /github/home/.gradle/caches | ||
| /github/home/.gradle/wrapper | ||
| key: debian11-x86_64-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} | ||
| restore-keys: | | ||
| debian11-x86_64-gradle- | ||
|
|
||
| - name: Build (no tests) | ||
| run: ./gradlew clean assemble --no-daemon | ||
|
|
||
| - name: Run smoke unit tests | ||
| run: | | ||
| ./gradlew \ | ||
| :framework:test --tests "org.tron.common.ParameterTest" --tests "org.tron.common.ComparatorTest" \ | ||
| :plugins:test --tests "org.tron.plugins.utils.ByteArrayTest" \ | ||
| --no-daemon | ||
|
|
||
| - name: Generate module coverage reports | ||
| run: | | ||
| ./gradlew jacocoTestReport --no-daemon | ||
|
|
||
| - name: Upload coverage reports | ||
| if: always() | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: jacoco-coverage-reports | ||
| path: | | ||
| **/build/reports/jacoco/test/jacocoTestReport.xml | ||
| if-no-files-found: error | ||
|
|
||
| coverage: | ||
| name: Coverage Check | ||
| needs: docker-build-debian11 | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| pull-requests: write | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Add Prompt for AI agents |
||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Download coverage reports | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: jacoco-coverage-reports | ||
| path: coverage-input | ||
|
|
||
| - name: Collect coverage report paths | ||
| id: collect-xml | ||
| run: | | ||
| XMLS=$(find coverage-input -name "jacocoTestReport.xml" | sort | paste -sd, -) | ||
| if [ -z "$XMLS" ]; then | ||
| echo "No jacocoTestReport.xml files found." | ||
| exit 1 | ||
| fi | ||
| echo "xmls=$XMLS" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Add coverage to PR | ||
| id: jacoco | ||
| uses: madrapps/jacoco-report@v1.7.2 | ||
| with: | ||
| paths: ${{ steps.collect-xml.outputs.xmls }} | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| min-coverage-overall: 0 | ||
| min-coverage-changed-files: 0 | ||
| skip-if-no-changes: true | ||
| title: '## Code Coverage Report' | ||
| update-comment: true | ||
|
|
||
| - name: Coverage summary | ||
| run: | | ||
| echo "Overall Coverage: ${{ steps.jacoco.outputs.coverage-overall }}" | ||
| echo "Changed Files Coverage: ${{ steps.jacoco.outputs.coverage-changed-files }}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: Cancel PR Workflows on Close | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [ closed ] | ||
|
|
||
| permissions: | ||
| actions: write | ||
|
|
||
| jobs: | ||
| cancel: | ||
| name: Cancel In-Progress Workflows | ||
| if: github.event.pull_request.merged == false | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Cancel PR Build and System Test | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| const workflows = ['pr-build.yml', 'system-test.yml', 'codeql.yml']; | ||
| const headSha = context.payload.pull_request.head.sha; | ||
| const prNumber = context.payload.pull_request.number; | ||
|
|
||
| for (const workflowId of workflows) { | ||
| for (const status of ['in_progress', 'queued']) { | ||
| const runs = await github.paginate( | ||
| github.rest.actions.listWorkflowRuns, | ||
| { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: workflowId, | ||
| status, | ||
| event: 'pull_request', | ||
| per_page: 100, | ||
| }, | ||
| (response) => response.data.workflow_runs | ||
| ); | ||
|
|
||
| for (const run of runs) { | ||
| const isTargetPr = !run.pull_requests?.length || run.pull_requests.some((pr) => pr.number === prNumber); | ||
| if (run.head_sha === headSha && isTargetPr) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The SHA equality check only cancels runs for the latest commit, so older in-flight runs from the same PR can keep running after the PR is closed. Prompt for AI agents |
||
| await github.rest.actions.cancelWorkflowRun({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| run_id: run.id, | ||
| }); | ||
| console.log(`Cancelled ${workflowId} run #${run.id} (${status})`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Pin GitHub Actions to immutable commit SHAs instead of major tags to reduce workflow supply-chain risk.
Prompt for AI agents