Skip to content

Commit

Permalink
Modularize artifact build
Browse files Browse the repository at this point in the history
and rebuild artifacts before running the matrix test
instead of re-using pre-build artifacts (which is error-prone).
  • Loading branch information
ascheman committed Aug 13, 2024
1 parent 28bc8a9 commit 85a2368
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 68 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
@@ -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
84 changes: 23 additions & 61 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
31 changes: 24 additions & 7 deletions .github/workflows/test-java-os-mix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand All @@ -22,23 +29,33 @@ 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
uname -a
./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

0 comments on commit 85a2368

Please sign in to comment.