Fix #679 (#1556) #3231
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Deploy Snapshot | |
| on: | |
| push: | |
| branches: ['3.*'] | |
| paths-ignore: | |
| - "README.md" | |
| - "release-notes/*" | |
| pull_request: | |
| paths-ignore: | |
| - "README.md" | |
| - "release-notes/*" | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| java_version: ['17', '21', '25'] | |
| # We will actually need "os" as Matrix to have Windows build | |
| os: ['ubuntu-24.04'] | |
| include: | |
| - java_version: '17' | |
| os: 'ubuntu-24.04' | |
| release_build: 'R' | |
| - java_version: '17' | |
| os: 'windows-latest' | |
| is_windows: 'W' | |
| env: | |
| JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Set up JDK (without deployment credentials) | |
| if: ${{ github.event_name == 'pull_request' || github.repository != 'FasterXML/jackson-core' }} | |
| uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 | |
| with: | |
| distribution: 'temurin' | |
| java-version: ${{ matrix.java_version }} | |
| cache: 'maven' | |
| - name: Set up JDK with deployment credentials | |
| if: ${{ github.event_name != 'pull_request' && github.repository == 'FasterXML/jackson-core' }} | |
| uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 | |
| with: | |
| distribution: 'temurin' | |
| java-version: ${{ matrix.java_version }} | |
| cache: 'maven' | |
| server-id: central-snapshots | |
| server-username: CI_DEPLOY_USERNAME | |
| server-password: CI_DEPLOY_PASSWORD | |
| # See https://github.com/actions/setup-java/blob/v2/docs/advanced-usage.md#Publishing-using-Apache-Maven | |
| # gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import | |
| # gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase | |
| - name: Build and Test | |
| run: ./mvnw -B -ff -ntp verify | |
| - name: Extract project Maven version | |
| id: projectVersion | |
| # for some reason fails on Windows; we don't need it so skip: | |
| if: ${{ !matrix.is_windows }} | |
| run: echo "version=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.5.1:evaluate -DforceStdout -Dexpression=project.version -q)" >>$GITHUB_OUTPUT | |
| - name: Verify Android SDK Compatibility | |
| if: ${{ matrix.release_build }} | |
| run: ./mvnw -B -q -ff -ntp -DskipTests animal-sniffer:check | |
| - name: Deploy snapshot | |
| if: ${{ matrix.release_build && github.event_name != 'pull_request' && github.repository == 'FasterXML/jackson-core' && endsWith(steps.projectVersion.outputs.version, '-SNAPSHOT') }} | |
| env: | |
| CI_DEPLOY_USERNAME: ${{ secrets.CENTRAL_DEPLOY_USERNAME }} | |
| CI_DEPLOY_PASSWORD: ${{ secrets.CENTRAL_DEPLOY_PASSWORD }} | |
| # MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} | |
| run: ./mvnw -B -q -ff -DskipTests -ntp source:jar deploy | |
| - name: Generate code coverage | |
| if: ${{ matrix.release_build }} | |
| run: ./mvnw -B -q -ff -ntp test jacoco:report | |
| - name: Publish code coverage | |
| if: ${{ matrix.release_build && github.event_name != 'pull_request' && github.repository == 'FasterXML/jackson-core' }} | |
| uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./target/site/jacoco/jacoco.xml | |
| flags: unittests | |
| - name: Upload coverage report as artifact | |
| if: ${{ matrix.release_build && github.event_name != 'pull_request' && github.repository == 'FasterXML/jackson-core' }} | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: jacoco-report | |
| path: target/site/jacoco/jacoco.csv | |
| retention-days: 30 | |
| - name: Download base branch coverage | |
| if: ${{ matrix.release_build && github.event_name == 'pull_request' }} | |
| uses: dawidd6/action-download-artifact@883bc3da0e2f55ddd0a8fc8e99378551c1991a55 # v13 | |
| continue-on-error: true | |
| with: | |
| workflow: main.yml | |
| branch: ${{ github.event.pull_request.base.ref }} | |
| name: jacoco-report | |
| path: base-coverage/ | |
| - name: Generate coverage summary | |
| if: ${{ matrix.release_build && github.event_name == 'pull_request' }} | |
| id: jacoco | |
| uses: cicirello/jacoco-badge-generator@72266185b7ee48a6fd74eaf0238395cc8b14fef8 # v2.12.1 | |
| with: | |
| jacoco-csv-file: target/site/jacoco/jacoco.csv | |
| generate-coverage-badge: false | |
| generate-branches-badge: false | |
| generate-summary: true | |
| - name: Generate coverage comment | |
| if: ${{ matrix.release_build && github.event_name == 'pull_request' }} | |
| run: | | |
| # Helper functions | |
| parse_coverage() { | |
| local csv_file=$1 col_missed=$2 col_covered=$3 | |
| awk -F',' -v m="$col_missed" -v c="$col_covered" \ | |
| 'NR>1 && $1=="Jackson-core" { | |
| total_missed += $m; | |
| total_covered += $c; | |
| } | |
| END { | |
| if (total_missed + total_covered > 0) | |
| printf "%.2f", (total_covered * 100.0) / (total_missed + total_covered) | |
| }' "$csv_file" | |
| } | |
| format_delta() { | |
| local delta=$1 | |
| if awk -v d="$delta" 'BEGIN { exit (d >= 0) ? 0 : 1 }'; then | |
| echo "+${delta}%|📈" | |
| else | |
| echo "${delta}%|📉" | |
| fi | |
| } | |
| get_color() { | |
| awk -v v="$1" 'BEGIN { | |
| if (v >= 80) print "brightgreen" | |
| else if (v >= 60) print "green" | |
| else if (v >= 40) print "yellow" | |
| else print "red" | |
| }' | |
| } | |
| # Convert decimal to percentage and round to 2 decimal places | |
| COVERAGE=$(awk -v cov="${{ steps.jacoco.outputs.coverage }}" 'BEGIN { printf "%.2f", cov * 100 }') | |
| BRANCHES=$(awk -v br="${{ steps.jacoco.outputs.branches }}" 'BEGIN { printf "%.2f", br * 100 }') | |
| # Check if base coverage artifact was downloaded and calculate deltas | |
| HAS_DELTA=false | |
| if [ -f "base-coverage/jacoco.csv" ]; then | |
| echo "Found base branch coverage from artifact" | |
| BASE_COVERAGE=$(parse_coverage "base-coverage/jacoco.csv" 4 5) | |
| BASE_BRANCHES=$(parse_coverage "base-coverage/jacoco.csv" 6 7) | |
| echo "DEBUG: Current coverage: ${COVERAGE}%, branches: ${BRANCHES}%" | |
| echo "DEBUG: Base coverage: ${BASE_COVERAGE}%, branches: ${BASE_BRANCHES}%" | |
| if [ -n "$BASE_COVERAGE" ] && [ -n "$BASE_BRANCHES" ]; then | |
| COV_DELTA=$(awk -v curr="$COVERAGE" -v base="$BASE_COVERAGE" 'BEGIN { printf "%.3f", curr - base }') | |
| BR_DELTA=$(awk -v curr="$BRANCHES" -v base="$BASE_BRANCHES" 'BEGIN { printf "%.3f", curr - base }') | |
| echo "DEBUG: Coverage delta: ${COV_DELTA}%, branches delta: ${BR_DELTA}%" | |
| IFS='|' read -r COV_DELTA_STR COV_DELTA_EMOJI <<< "$(format_delta "$COV_DELTA")" | |
| IFS='|' read -r BR_DELTA_STR BR_DELTA_EMOJI <<< "$(format_delta "$BR_DELTA")" | |
| HAS_DELTA=true | |
| fi | |
| else | |
| echo "No base branch coverage artifact found" | |
| fi | |
| # Determine badge colors | |
| COV_COLOR=$(get_color "$COVERAGE") | |
| BR_COLOR=$(get_color "$BRANCHES") | |
| # Build coverage table with or without deltas | |
| if [ "$HAS_DELTA" = "true" ]; then | |
| COVERAGE_TABLE="| Metric | Coverage | Change | | |
| |--------|----------|--------| | |
| | **Instructions** |  **${COVERAGE}%** | ${COV_DELTA_EMOJI} **${COV_DELTA_STR}** | | |
| | **Branches** |  **${BRANCHES}%** | ${BR_DELTA_EMOJI} **${BR_DELTA_STR}** |" | |
| else | |
| COVERAGE_TABLE="| Metric | Coverage | | |
| |--------|----------| | |
| | **Instructions** |  **${COVERAGE}%** | | |
| | **Branches** |  **${BRANCHES}%** |" | |
| fi | |
| COMMENT_BODY="## :chart_with_upwards_trend: Overall Code Coverage | |
| $COVERAGE_TABLE | |
| > Overall project coverage from JaCoCo test results. Change values compare against the latest base branch build. | |
| <!-- jacoco-coverage-comment -->" | |
| # Save comment for the workflow_run | |
| mkdir -p pr-comment | |
| echo "${{ github.event.pull_request.number }}" > pr-comment/pr-number.txt | |
| echo "$COMMENT_BODY" > pr-comment/comment-body.txt | |
| - name: Upload PR comment | |
| if: ${{ matrix.release_build && github.event_name == 'pull_request' }} | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | |
| with: | |
| name: pr-comment | |
| path: pr-comment/ | |
| retention-days: 1 | |
| trigger-dep-builds-v2: | |
| name: Trigger downstream builds for v2 | |
| needs: [build] | |
| # Only for pushes to default branch | |
| if: ${{ github.event_name == 'push' && github.ref_name == '2.x' }} | |
| uses: ./.github/workflows/trigger_dep_builds_v2.yml | |
| secrets: | |
| token: ${{ secrets.REPO_DISPATCH }} | |
| trigger-dep-builds-v3: | |
| name: Trigger downstream builds for v3 | |
| needs: [build] | |
| # Only for pushes to 3.x branch | |
| if: ${{ github.event_name == 'push' && github.ref_name == '3.x' }} | |
| uses: ./.github/workflows/trigger_dep_builds_v3.yml | |
| secrets: | |
| token: ${{ secrets.REPO_DISPATCH }} | |