run on pr on non-fork #44
This file contains 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 | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
permissions: | |
checks: write | |
env: | |
BUILD_JAVA_VERSION: '17' | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ ubuntu-latest ] | |
java: [ '11', '17' ] | |
arch: [ 'x64' ] | |
# include: | |
# - os: windows-latest | |
# java: '17' | |
# arch: x86 | |
name: Java ${{ matrix.java }}/${{ matrix.arch }}/${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK ${{ matrix.java }} | |
uses: actions/setup-java@v3 | |
with: | |
java-version: ${{ matrix.java }} | |
architecture: ${{ matrix.arch }} | |
distribution: temurin | |
cache: maven | |
- name: Build with Maven | |
run: | | |
mvn verify \ | |
-B \ | |
-Dsurefire.rerunFailingTestsCount=2 \ | |
-"Dgpg.skip" \ | |
jacoco:report | |
cd target | |
mv jacoco.exec jacoco-${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.os }}.exec | |
mv surefire-reports surefire-reports-${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.os }} | |
- name: Upload classes | |
uses: ./.github/actions/upload-artifact | |
if: always() && matrix.java == env.BUILD_JAVA_VERSION && matrix.arch == 'x64' && matrix.os == 'ubuntu-latest' | |
with: | |
name: classes | |
path: target/*classes | |
- name: Upload JUnit Reports | |
uses: ./.github/actions/upload-artifact | |
if: always() # always run even if the previous step fails | |
with: | |
name: reports | |
filename: ${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.os }} | |
path: target/surefire-reports-*/TEST-*.xml | |
- name: Upload Coverage Reports | |
uses: ./.github/actions/upload-artifact | |
if: always() # always run even if the previous step fails | |
with: | |
name: coverage | |
filename: ${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.os }} | |
path: target/jacoco-${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.os }}.exec | |
coverage: | |
name: JaCoCo Report | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: echo | |
run: | | |
cat << EOF | |
${{ toJson(github) }} | |
EOF | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: ${{ env.BUILD_JAVA_VERSION }} | |
distribution: temurin | |
cache: maven | |
- name: Get coverage artifact | |
uses: ./.github/actions/download-artifact | |
with: | |
name: coverage | |
- name: Get classes | |
uses: ./.github/actions/download-artifact | |
with: | |
name: classes | |
- name: Merge and output | |
run: mvn -B jacoco:merge jacoco:report | |
- name: Upload | |
uses: ./.github/actions/upload-artifact | |
with: | |
name: merged-coverage | |
path: | | |
target/site/jacoco | |
target/jacoco.exec | |
- name: Save PR number to file | |
if: github.event_name == 'pull_request' | |
run: echo ${{ github.event.number }} > pr_number.txt | |
- name: Archive PR number | |
if: github.event_name == 'pull_request' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: pr_number | |
path: pr_number.txt | |
analyze: | |
name: Analyze Code | |
runs-on: ubuntu-latest | |
needs: coverage | |
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.owner.login == 'dnsjava' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
# for Sonar | |
fetch-depth: 0 | |
- name: Get analysis data | |
uses: ./.github/actions/prepare-analysis | |
with: | |
cache: maven | |
- name: Run SonarQube | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |