Skip to content

ci: add more os runners (do not merge) #17

ci: add more os runners (do not merge)

ci: add more os runners (do not merge) #17

Workflow file for this run

name: PR Check
on:
pull_request:
branches: [ 'develop', 'release_**' ]
types: [ opened, edited, synchronize, reopened ]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
pr-lint:
name: PR Lint
runs-on: ubuntu-latest
steps:
- name: Check PR title format
uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title;
const errors = [];
// Title should not be empty or too short
if (!title || title.trim().length < 10) {
errors.push('PR title is too short (minimum 10 characters).');
}
// Title should not exceed 72 characters
if (title.length > 72) {
errors.push(`PR title is too long (${title.length}/72 characters).`);
}
// Title should follow conventional format: type: description
// Allowed types: feat, fix, refactor, docs, style, test, chore, ci, perf, build, revert
const conventionalRegex = /^(feat|fix|refactor|docs|style|test|chore|ci|perf|build|revert)(\(.+\))?:\s.+/;
if (!conventionalRegex.test(title)) {
errors.push(
'PR title must follow conventional format: `type: description`\n' +
'Allowed types: feat, fix, refactor, docs, style, test, chore, ci, perf, build, revert\n' +
'Example: `feat: add new transaction validation`'
);
}
if (errors.length > 0) {
const message = '### PR Title Check Failed\n\n' + errors.map(e => `- ${e}`).join('\n');
core.setFailed(message);
} else {
core.info('PR title format is valid.');
}
- name: Check PR description
uses: actions/github-script@v7
with:
script: |
const body = context.payload.pull_request.body;
if (!body || body.trim().length < 20) {
core.setFailed(
'### PR Description Check Failed\n\n' +
'PR description is too short or empty. Please describe what this PR does and why.'
);
} else {
core.info('PR description is valid.');
}
build:
name: Build ${{ matrix.os-name }}(JDK ${{ matrix.java }} / ${{ matrix.arch }})
needs: pr-lint
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
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:
- 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: Build
run: ./gradlew clean build --no-daemon
docker-build-centos8:
name: Build centos8 (JDK 8 / x86_64)
needs: pr-lint
runs-on: ubuntu-latest
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
- 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: eclipse-temurin:8-jdk
defaults:
run:
shell: bash
env:
GRADLE_USER_HOME: /github/home/.gradle
steps:
- name: Checkout code
uses: actions/checkout@v4
- 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: ${{ 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 --no-daemon
coverage-gate:
name: Coverage Gate (from centos8 build)
needs: docker-build-centos8
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
shell: bash
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
token: ${{ secrets.CODECOV_TOKEN }}
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 }}
# if ADDED_NUM is 0,skip 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) current commit coverage、parent commit coverage、patch coverage
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 branch head coverage(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 rule
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 # skip compare ?
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 # skip compare ?
fi
checkstyle:
name: Checkstyle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-
- name: Run Checkstyle
run: ./gradlew :framework:checkstyleMain :framework:checkstyleTest :plugins:checkstyleMain
- name: Upload Checkstyle reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: checkstyle-reports
path: |
framework/build/reports/checkstyle/
plugins/build/reports/checkstyle/