From e9c8b4c5616a2a8ea1df8b1a1840ea870c7d5f90 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 16:40:05 +0800 Subject: [PATCH 01/10] test github action --- .github/workflows/pr-check.yml | 108 +++++++++++++++++++-------------- gradle.properties | 2 + 2 files changed, 64 insertions(+), 46 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 731bfbbce90..8ea9045fd5c 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -67,7 +67,7 @@ jobs: } build: - name: Build (JDK ${{ matrix.java }} / ${{ matrix.arch }}) + name: Build ${{ matrix.os-name }}(JDK ${{ matrix.java }} / ${{ matrix.arch }}) needs: pr-lint runs-on: ${{ matrix.runner }} strategy: @@ -76,9 +76,19 @@ jobs: include: - java: '8' runner: ubuntu-latest + os-name: ubuntu arch: x86_64 - java: '17' runner: ubuntu-24.04-arm + os-name: ubuntu + arch: aarch64 + - java: '8' + runner: macos-26-intel + os-name: macos + arch: x86_64 + - java: '17' + runner: macos-latest + os-name: macos arch: aarch64 steps: @@ -100,7 +110,57 @@ jobs: restore-keys: ${{ runner.os }}-${{ matrix.arch }}-gradle- - name: Build - run: ./gradlew clean build -x test + run: ./gradlew clean build + + docker-build: + name: Build ${{ matrix.image }}(JDK 8 / x86_64) + needs: pr-lint + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + image: + - centos:7 + - debian:11 + + container: + image: ${{ matrix.image }} + + env: + GRADLE_USER_HOME: /github/home/.gradle + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + if [ -f /etc/redhat-release ]; then + yum install -y java-1.8.0-openjdk-devel git wget unzip which + yum groupinstall -y "Development Tools" + else + apt update + apt install -y openjdk-8-jdk git wget unzip build-essential + fi + + - name: Check Java version + run: java -version + + - name: Cache Gradle + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-${{ matrix.arch }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} + restore-keys: ${{ runner.os }}-${{ matrix.arch }}-gradle- + + - name: Grant execute permission + run: chmod +x gradlew + + - name: Build + run: ./gradlew clean build checkstyle: name: Checkstyle @@ -136,47 +196,3 @@ jobs: framework/build/reports/checkstyle/ plugins/build/reports/checkstyle/ - test: - name: Unit Tests (JDK ${{ matrix.java }} / ${{ matrix.arch }}) - runs-on: ${{ matrix.runner }} - needs: build - timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - include: - - java: '8' - runner: ubuntu-latest - arch: x86_64 - - java: '17' - runner: ubuntu-24.04-arm - arch: aarch64 - - steps: - - uses: actions/checkout@v4 - - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v4 - with: - java-version: ${{ matrix.java }} - distribution: 'temurin' - - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-${{ matrix.arch }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-${{ matrix.arch }}-gradle- - - - name: Run tests - run: ./gradlew test - - - name: Upload test reports - if: failure() - uses: actions/upload-artifact@v4 - with: - name: test-reports-${{ matrix.arch }} - path: | - **/build/reports/tests/ diff --git a/gradle.properties b/gradle.properties index 031a8cddc89..09532810ad4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,4 @@ org.gradle.parallel=true org.gradle.jvmargs=-Xms1g +org.gradle.caching=true +org.gradle.daemon=false \ No newline at end of file From e5f4edbbc0cc944c4babdacb208ebfdb2d1c9a98 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 17:19:29 +0800 Subject: [PATCH 02/10] fix bug --- .github/workflows/pr-check.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 8ea9045fd5c..3c848026454 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -113,16 +113,19 @@ jobs: run: ./gradlew clean build docker-build: - name: Build ${{ matrix.image }}(JDK 8 / x86_64) + name: Build ${{ matrix.os-name }}(JDK 8 / x86_64) needs: pr-lint runs-on: ubuntu-latest strategy: fail-fast: false matrix: - image: - - centos:7 - - debian:11 + include: + - os-name: centos8 + image: quay.io/centos/centos:stream8 + + - os-name: debian11 + image: eclipse-temurin:8-jdk container: image: ${{ matrix.image }} @@ -141,7 +144,7 @@ jobs: yum groupinstall -y "Development Tools" else apt update - apt install -y openjdk-8-jdk git wget unzip build-essential + apt-get install -y git wget unzip build-essential fi - name: Check Java version From c2812414875dfac7677c966d973519824d2ce1d9 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 17:34:47 +0800 Subject: [PATCH 03/10] update image --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 3c848026454..32ed03fb3c2 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -122,7 +122,7 @@ jobs: matrix: include: - os-name: centos8 - image: quay.io/centos/centos:stream8 + image: rockylinux:8 - os-name: debian11 image: eclipse-temurin:8-jdk From fe978098d6b5d180794b39b709168952d1b61b38 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 18:17:04 +0800 Subject: [PATCH 04/10] fix the bug of testHelpMessage --- framework/src/main/java/org/tron/core/config/args/Args.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/main/java/org/tron/core/config/args/Args.java b/framework/src/main/java/org/tron/core/config/args/Args.java index 46695986c1f..45b1a63f1f8 100644 --- a/framework/src/main/java/org/tron/core/config/args/Args.java +++ b/framework/src/main/java/org/tron/core/config/args/Args.java @@ -343,7 +343,7 @@ private static String getCommitIdAbbrev() { InputStream in = Thread.currentThread() .getContextClassLoader().getResourceAsStream("git.properties"); properties.load(in); - } catch (IOException e) { + } catch (Exception e) { logger.warn("Load resource failed,git.properties {}", e.getMessage()); } return properties.getProperty("git.commit.id.abbrev"); From f4bb11cf2da29784c3ed2aa087b6a922a5fea1d7 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 18:53:39 +0800 Subject: [PATCH 05/10] add task coverage-gate --- .github/workflows/pr-check.yml | 208 +++++++++++++++++++++++++++++---- 1 file changed, 184 insertions(+), 24 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 32ed03fb3c2..653713a4a11 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -112,23 +112,75 @@ jobs: - name: Build run: ./gradlew clean build - docker-build: - name: Build ${{ matrix.os-name }}(JDK 8 / x86_64) + docker-build-centos8: + name: Build centos8 (JDK 8 / x86_64) needs: pr-lint runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - os-name: centos8 - image: rockylinux:8 + container: + image: rockylinux:8 + + env: + GRADLE_USER_HOME: /github/home/.gradle + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies (Rocky 8 + JDK8) + run: | + set -euxo pipefail + dnf -y install java-1.8.0-openjdk-devel git wget unzip which jq bc curl + dnf -y groupinstall "Development Tools" + + - 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: ${{ runner.os }}-centos8-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-centos8-gradle- + + - name: Prepare checkstyle config copy + run: | + set -euxo pipefail + cp -f config/checkstyle/checkStyle.xml config/checkstyle/checkStyleAll.xml || true - - os-name: debian11 - image: eclipse-temurin:8-jdk + - name: Grant execute permission + run: chmod +x gradlew + + - name: Stop Gradle daemon + run: ./gradlew --stop || true + + - name: Build + run: ./gradlew clean build --no-daemon + + - name: Generate JaCoCo report + run: ./gradlew jacocoTestReport --no-daemon + + - name: Upload JaCoCo artifacts + uses: actions/upload-artifact@v4 + with: + name: jacoco-centos8 + path: | + **/build/reports/jacoco/test/jacocoTestReport.xml + **/build/reports/** + **/build/test-results/** + if-no-files-found: error + + + docker-build-debian11: + name: Build debian11 (JDK 8 / x86_64) + needs: pr-lint + runs-on: ubuntu-latest container: - image: ${{ matrix.image }} + image: eclipse-temurin:8-jdk env: GRADLE_USER_HOME: /github/home/.gradle @@ -137,15 +189,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Install dependencies + - name: Install dependencies (Debian + build tools) run: | - if [ -f /etc/redhat-release ]; then - yum install -y java-1.8.0-openjdk-devel git wget unzip which - yum groupinstall -y "Development Tools" - else - apt update - apt-get install -y git wget unzip build-essential - fi + set -euxo pipefail + apt-get update + apt-get install -y git wget unzip build-essential curl jq - name: Check Java version run: java -version @@ -154,16 +202,128 @@ jobs: uses: actions/cache@v4 with: path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-${{ matrix.arch }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-${{ matrix.arch }}-gradle- + /github/home/.gradle/caches + /github/home/.gradle/wrapper + key: ${{ runner.os }}-debian11-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-debian11-gradle- - name: Grant execute permission run: chmod +x gradlew - name: Build - run: ./gradlew clean build + run: ./gradlew clean build --no-daemon + + + coverage-gate: + name: Coverage Gate (from centos8 build) + needs: docker-build-centos8 + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - name: Download JaCoCo artifacts (centos8) + uses: actions/download-artifact@v4 + with: + name: jacoco-centos8 + path: artifacts/jacoco-centos8 + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + files: | + artifacts/jacoco-centos8/**/jacocoTestReport.xml + fail_ci_if_error: true + + - name: Wait for Codecov processing + run: sleep 3m + + - name: Coverage gate via Codecov GraphQL + env: + CODECOV_OWNER: tronprotocol + CODECOV_REPO: java-tron + COMMIT_ID: ${{ github.event.pull_request.head.sha }} + BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + # 与你原脚本一致:不算新增行数就保持 0,跳过 patch coverage gate + ADDED_NUM: "0" + run: | + set -euxo pipefail + sudo apt-get update + sudo apt-get install -y jq bc curl + + echo "commit: $COMMIT_ID" + echo "base branch: $BASE_BRANCH" + + # 1) 当前 commit 覆盖率、父 commit 覆盖率、patch 覆盖率 + currentRes=$( + curl -sS 'https://api.codecov.io/graphql/github' \ + -H 'content-type: application/json' \ + --data '{ + "query": "query Commit($owner: String!, $repo: String!, $commitid: String!, $filters: ImpactedFilesFilters, $isTeamPlan: Boolean!) { owner(username: $owner) { repository(name: $repo) { ... on Repository { commit(id: $commitid) { coverageAnalytics { totals { coverage: percentCovered } } parent { coverageAnalytics { totals { coverage: percentCovered } } } compareWithParent { ... on Comparison { patchTotals { coverage: percentCovered } } } } } } } }", + "variables": { + "provider": "github", + "owner": "'"$CODECOV_OWNER"'", + "repo": "'"$CODECOV_REPO"'", + "commitid": "'"$COMMIT_ID"'", + "filters": {}, + "isTeamPlan": false + } + }' | jq -r '.data.owner.repository.commit' + ) + + self_cov=$(echo "$currentRes" | jq -r '.coverageAnalytics.totals.coverage // 0') + base_cov=$(echo "$currentRes" | jq -r '.parent.coverageAnalytics.totals.coverage // 0') + patch_cov=$(echo "$currentRes" | jq -r '.compareWithParent.patchTotals.coverage // 0') + + echo "self_cov=$self_cov" + echo "base_cov(parent commit)=$base_cov" + echo "patch_cov=$patch_cov" + + # 2) base 分支 head 覆盖率(target) + parent_cov=$( + curl -sS 'https://api.codecov.io/graphql/github' \ + -H 'content-type: application/json; charset=utf-8' \ + --data '{ + "query": "query GetRepoCoverage($owner: String!, $repo: String!, $branch: String!) { owner(username: $owner) { repository(name: $repo) { ... on Repository { branch(name: $branch) { head { coverageAnalytics { totals { percentCovered } } } } } } } }", + "variables": { + "owner": "'"$CODECOV_OWNER"'", + "repo": "'"$CODECOV_REPO"'", + "branch": "'"$BASE_BRANCH"'" + } + }' | jq -r '.data.owner.repository.branch.head.coverageAnalytics.totals.percentCovered // 0' + ) + + echo "parent_cov(base branch head)=$parent_cov" + + # 3) Gate 规则(复刻你原脚本) + if [ "$(echo "$self_cov <= 0" | bc)" -eq 1 ]; then + echo "get current commit coverage failed !!!!" + exit 1 + fi + + if [ "$(echo "$self_cov - $parent_cov < 0" | bc)" -eq 1 ]; then + echo "self_cov: $self_cov target: $parent_cov" + echo "111-target code coverage has decreased, please add unit test!" + exit 1 + fi + + if [ "$(echo "$self_cov - $base_cov < 0" | bc)" -eq 1 ]; then + echo "self_cov: $self_cov parent: $base_cov" + echo "222-parent code coverage has decreased, please add unit test!" + # exit 1 # 原脚本是注释掉的,这里保持一致 + fi + + if [ "$ADDED_NUM" -eq 0 ]; then + echo "no need to compare patch coverage ............" + exit 0 + fi + + if [ "$(echo "$patch_cov <= 80" | bc)" -eq 1 ]; then + echo "patch coverage is too low !!!!" + # exit 1 # 原脚本注释掉了,这里保持一致 + fi checkstyle: name: Checkstyle From 16bdef430bbe05f8c2e26edbf4bccc9b743ef67b Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 19:02:36 +0800 Subject: [PATCH 06/10] use bash shell default --- .github/workflows/pr-check.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 653713a4a11..31423a94da1 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -182,6 +182,10 @@ jobs: container: image: eclipse-temurin:8-jdk + defaults: + run: + shell: bash + env: GRADLE_USER_HOME: /github/home/.gradle @@ -223,6 +227,10 @@ jobs: permissions: contents: read + defaults: + run: + shell: bash + steps: - name: Download JaCoCo artifacts (centos8) uses: actions/download-artifact@v4 From 183f3b15cf719e48d5c9c2ff8f0b307af779dcff Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 19:07:15 +0800 Subject: [PATCH 07/10] test again --- .github/workflows/pr-check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 31423a94da1..2db143edbc2 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -173,7 +173,6 @@ jobs: **/build/test-results/** if-no-files-found: error - docker-build-debian11: name: Build debian11 (JDK 8 / x86_64) needs: pr-lint From b8579a10c7b022a77b3d198e518617141d2b147b Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 20:38:43 +0800 Subject: [PATCH 08/10] add token when Upload coverage to Codecov --- .github/workflows/pr-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 2db143edbc2..cfc2b08b81b 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -242,6 +242,7 @@ jobs: with: files: | artifacts/jacoco-centos8/**/jacocoTestReport.xml + token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true - name: Wait for Codecov processing From abeb9a47bcb12a895cc6fab5a6604f10605a9df7 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 20:58:00 +0800 Subject: [PATCH 09/10] optimize comment --- .github/workflows/pr-check.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index cfc2b08b81b..4ca6d5a0aa5 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -254,7 +254,7 @@ jobs: CODECOV_REPO: java-tron COMMIT_ID: ${{ github.event.pull_request.head.sha }} BASE_BRANCH: ${{ github.event.pull_request.base.ref }} - # 与你原脚本一致:不算新增行数就保持 0,跳过 patch coverage gate + # if ADDED_NUM is 0,skip patch coverage gate ADDED_NUM: "0" run: | set -euxo pipefail @@ -264,7 +264,7 @@ jobs: echo "commit: $COMMIT_ID" echo "base branch: $BASE_BRANCH" - # 1) 当前 commit 覆盖率、父 commit 覆盖率、patch 覆盖率 + # 1) current commit coverage、parent commit coverage、patch coverage currentRes=$( curl -sS 'https://api.codecov.io/graphql/github' \ -H 'content-type: application/json' \ @@ -289,7 +289,7 @@ jobs: echo "base_cov(parent commit)=$base_cov" echo "patch_cov=$patch_cov" - # 2) base 分支 head 覆盖率(target) + # 2) base branch head coverage(target) parent_cov=$( curl -sS 'https://api.codecov.io/graphql/github' \ -H 'content-type: application/json; charset=utf-8' \ @@ -305,7 +305,7 @@ jobs: echo "parent_cov(base branch head)=$parent_cov" - # 3) Gate 规则(复刻你原脚本) + # 3) Gate rule if [ "$(echo "$self_cov <= 0" | bc)" -eq 1 ]; then echo "get current commit coverage failed !!!!" exit 1 @@ -320,7 +320,7 @@ jobs: if [ "$(echo "$self_cov - $base_cov < 0" | bc)" -eq 1 ]; then echo "self_cov: $self_cov parent: $base_cov" echo "222-parent code coverage has decreased, please add unit test!" - # exit 1 # 原脚本是注释掉的,这里保持一致 + # exit 1 # skip compare ? fi if [ "$ADDED_NUM" -eq 0 ]; then @@ -330,7 +330,7 @@ jobs: if [ "$(echo "$patch_cov <= 80" | bc)" -eq 1 ]; then echo "patch coverage is too low !!!!" - # exit 1 # 原脚本注释掉了,这里保持一致 + # exit 1 # skip compare ? fi checkstyle: From 86e918b822612661388c79ed79a04d51765c0944 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Feb 2026 21:26:05 +0800 Subject: [PATCH 10/10] use --no-daemon --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 4ca6d5a0aa5..fafcbebf233 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -110,7 +110,7 @@ jobs: restore-keys: ${{ runner.os }}-${{ matrix.arch }}-gradle- - name: Build - run: ./gradlew clean build + run: ./gradlew clean build --no-daemon docker-build-centos8: name: Build centos8 (JDK 8 / x86_64)