From 85a23682e5b6063d6b5a8f450adc7c0c634cd0ca Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Fri, 9 Aug 2024 13:00:17 +0200 Subject: [PATCH] Modularize artifact build and rebuild artifacts before running the matrix test instead of re-using pre-build artifacts (which is error-prone). --- .github/workflows/build-artifacts.yml | 88 ++++++++++++++++++++++++++ .github/workflows/gradle-build.yml | 84 +++++++----------------- .github/workflows/test-java-os-mix.yml | 31 +++++++-- 3 files changed, 135 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/build-artifacts.yml diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml new file mode 100644 index 00000000..b4847eef --- /dev/null +++ b/.github/workflows/build-artifacts.yml @@ -0,0 +1,88 @@ +name: Build Artifacts +on: + workflow_call: + inputs: + java-version: + required: true + type: string + default: '17' + run-sonar: + required: false + type: boolean + default: false +env: + SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION || 'aim42' }} + SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY || 'aim42_htmlSanityCheck' }} +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: ${{ inputs.java-version }} + + - name: Cache Gradle Toolchain JDKs + uses: actions/cache@v4 + with: + path: ~/.gradle/jdks + key: "${{ runner.os }}-gradle-jdks" + restore-keys: ${{ runner.os }}-jdk + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} + + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: "${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}" + restore-keys: ${{ runner.os }}-gradle + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v4 + + - name: Execute Gradle build + run: ./gradlew clean check integrationTest --scan --stacktrace + + - name: Cache SonarCloud packages + uses: actions/cache@v4 + if: ${{ inputs.run-sonar }} + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Analyze with SonarCloud + if: ${{ inputs.run-sonar }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + BRANCH_NAME=${GITHUB_REF#refs/heads/} + ./gradlew sonar -Psonar.branch.name=${BRANCH_NAME} --info --scan + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: | + **/build + + - name: Collect state upon failure + if: failure() + run: | + echo "Git:" + git status + echo "Env:" + env + echo "PWD:" + pwd + echo "Files:" + find * -ls diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index e48007b1..fbf2cb4e 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -3,54 +3,26 @@ on: pull_request: push: workflow_dispatch: -env: - SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION || 'aim42' }} - SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY || 'aim42_htmlSanityCheck' }} jobs: - gradle: + build-artifacts: + uses: ./.github/workflows/build-artifacts.yml + with: + # SonarQube requires JDK 17 or higher + java-version: '17' + run-sonar: true + + post-build: + needs: build-artifacts runs-on: ubuntu-latest steps: - name: Check out uses: actions/checkout@v4 - - name: Setup Java - uses: actions/setup-java@v4 + - name: Download Artifacts + uses: actions/download-artifact@v4 with: - distribution: temurin - # SonarQube requires JDK 17 or higher - java-version: 17 - - - name: Cache Gradle Toolchain JDKs - uses: actions/cache@v4 - with: - path: ~/.gradle/jdks - key: "${{ runner.os }}-gradle-jdks" - restore-keys: ${{ runner.os }}-jdk - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - with: - cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} - - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: ~/.gradle/caches - key: "${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}" - restore-keys: ${{ runner.os }}-gradle - - - name: Validate Gradle Wrapper - uses: gradle/actions/wrapper-validation@v4 - - - name: Execute Gradle build - run: ./gradlew clean check integrationTest --scan --stacktrace - - - name: Dump current state when error - run: | - env - pwd - find build */build integration-test/*/build -ls - if: failure() + name: build-artifacts + path: . - name: 'Publish Test Results' uses: EnricoMi/publish-unit-test-result-action/linux@v2 @@ -67,29 +39,19 @@ jobs: coverage_report_title: JaCoCo github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: maven-repo - path: build/maven-repo - - name: Trigger Test Matrix Workflow uses: benc-uk/workflow-dispatch@v1 with: workflow: test-java-os-mix.yml - - name: Cache SonarCloud packages - uses: actions/cache@v4 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - - name: Analyze with SonarCloud - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + - name: Collect state upon failure + if: failure() run: | - BRANCH_NAME=${GITHUB_REF#refs/heads/} - ./gradlew sonar -Psonar.branch.name=${BRANCH_NAME} --info --scan - + echo "Git:" + git status + echo "Env:" + env + echo "PWD:" + pwd + echo "Files:" + find * -ls diff --git a/.github/workflows/test-java-os-mix.yml b/.github/workflows/test-java-os-mix.yml index dcf8424e..0cfc436d 100644 --- a/.github/workflows/test-java-os-mix.yml +++ b/.github/workflows/test-java-os-mix.yml @@ -6,7 +6,14 @@ on: workflow_dispatch: {} jobs: + build-artifacts: + uses: ./.github/workflows/build-artifacts.yml + with: + # SonarQube requires JDK 17 or higher + java-version: '17' + test-java-os-mix: + needs: build-artifacts strategy: matrix: os-version: [ ubuntu-latest, macos-14, windows-latest ] @@ -22,19 +29,18 @@ jobs: - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v4 - - name: Download Artifacts - uses: dawidd6/action-download-artifact@v3 - with: - workflow: gradle-build.yml - name: maven-repo - path: build/maven-repo - - name: Setup JDK uses: actions/setup-java@v4 with: distribution: temurin java-version: ${{ matrix.java-version }} + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: . + - name: Execute integration test (on Unixes) run: | cd integration-test/gradle-plugin @@ -42,3 +48,14 @@ jobs: ./gradlew --version ./gradlew htmlSanityCheck --scan + - name: Collect state upon failure + if: failure() + run: | + echo "Git:" + git status + echo "Env:" + env + echo "PWD:" + pwd + echo "Files:" + find * -ls