Skip to content

Commit

Permalink
ci: Re-arrange workflows to remove duplication (#410)
Browse files Browse the repository at this point in the history
* ci: split kotlin tests into a new job

It will then be easier to add new profiles
as more versions of kotlin are supported.

This also creates dependencies between
jobs to only execute codecoverage when
tests are successful.

* ci: split gradle plugin test to a new job

* ci: test-gradle-plugin after build

* ci: merge native tests into main workflow

* ci: clear names for the jobs

* ci: re-org job needs

* ci: create action to prepare local cache

* ci: names again

* ci: use new gradle wrapper validation action

* ci: remove duplication to set up gradle cache

* ci: only execute for pushes to the main branch

* ci: activate kotlin-1.9 profile for code coverage
  • Loading branch information
marcospereira authored Jan 3, 2025
1 parent 190ced3 commit 6f5434e
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 98 deletions.
21 changes: 21 additions & 0 deletions .github/gradle-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Gradle Cache Action"
description: "Sets up Gradle Cache"

inputs:
key:
required: true
description: "The cache key"

runs:
using: composite
steps:
# Adapted from https://github.com/actions/cache/blob/v3/examples.md#java---gradle
- name: Cache Gradle local repository
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-${{ inputs.key }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-${{ inputs.key }}-
17 changes: 17 additions & 0 deletions .github/prepare-cache-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Prepare Cache Action"
description: "Prevents local published artifacts from be added to GH Actions cache"

runs:
using: composite
steps:
- name: "Clean local artifacts"
if: contains(runner.os, 'win') == false
run: rm -rvf ~/.m2/repository/gg/jte
shell: bash

# `rm` syntax for Windows is different. Needs to use `-Force` since `-f`
# is ambiguous (possible matches include: -Filter -Force).
- name: "[Windows]: Clean local artifacts"
if: contains(runner.os, 'win')
run: rm -r -Force ~/.m2/repository/gg/jte
shell: pwsh
68 changes: 0 additions & 68 deletions .github/workflows/graalvm.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v3
- uses: gradle/actions/wrapper-validation@v4
130 changes: 103 additions & 27 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ on:
- main

jobs:
# From https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#example-returning-a-json-object
build-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
echo "matrix={ \"os\": [\"windows-2022\", \"macOS-latest\", \"ubuntu-latest\"], \"java_version\": [17] }" >> $GITHUB_OUTPUT
build:
name: Build / JDK ${{ matrix.java_version }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: build-matrix
strategy:
fail-fast: false
matrix:
java_version: [17]
os: [windows-2022, macOS-latest, ubuntu-latest]
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}

steps:
- uses: actions/checkout@v4
Expand All @@ -29,26 +39,37 @@ jobs:
java-version: ${{ matrix.java_version }}
distribution: 'temurin'
cache: 'maven'
- name: Make Maven Wrapper executable
if: contains(matrix.os, 'win') == false
run: chmod +x ./mvnw
- name: Build with Maven
run: ./mvnw verify --file pom.xml

# Adapted from https://github.com/actions/cache/blob/v3/examples.md#java---gradle
- name: Cache local Gradle
id: gradleCache
uses: actions/cache@v4
test-gradle-plugin:
name: Test / Gradle / JDK ${{ matrix.java_version }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs:
- build-matrix
- build
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
java-version: ${{ matrix.java_version }}
distribution: 'temurin'
cache: 'maven'
- uses: ./.github/gradle-cache
with:
key: "gradle"
- name: Make Maven Wrapper executable
if: contains(matrix.os, 'win') == false
run: chmod +x ./mvnw
- name: Build with Maven
run: ./mvnw install --file pom.xml
- name: Test Kotlin 2.0
run: ./mvnw test --file pom.xml --projects jte-kotlin --also-make --activate-profiles kotlin-2.0
run: ./mvnw install --file pom.xml -DskipTests=true
- name: Build Gradle Plugin
run: cd jte-gradle-plugin && ./gradlew publishToMavenLocal
- name: Run all the Gradle Plugin tests
Expand All @@ -63,25 +84,80 @@ jobs:
with:
name: failing-test-report
path: test/gradle-test-wrapper/build/reports/tests/test/**/*
- uses: ./.github/prepare-cache-action

# This prevents local published artifacts from be added to GH Actions cache
- name: Clean local artifacts
if: contains(matrix.os, 'win') == false
run: rm -rvf ~/.m2/repository/gg/jte
test-graal:
name: Test / Graal / JDK ${{ matrix.java_version }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs:
- build-matrix
- build
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}

# `rm` syntax for Windows is different. Needs to use `-Force` since `-f`
# is ambiguous (possible matches include: -Filter -Force).
- name: "[Windows]: Clean local artifacts"
if: contains(matrix.os, 'win')
run: rm -r -Force ~/.m2/repository/gg/jte
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
distribution: 'graalvm'
java-version: ${{ matrix.java_version }}
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'maven'
- uses: ./.github/gradle-cache
with:
key: "gradle-graalvm"
- name: Make Maven Wrapper executable
if: contains(matrix.os, 'win') == false
run: chmod +x ./mvnw
- name: Build with Maven
run: ./mvnw install --file pom.xml -DskipTests=true
- name: Build Gradle Plugin
run: cd jte-gradle-plugin && ./gradlew publishToMavenLocal
- name: Test Gradle Plugin Generate with conventions
run: cd test/jte-runtime-cp-test-gradle-convention && ./gradlew check nativeTest
- name: Stop Gradle Daemon
if: ${{ always() }}
run: cd test/jte-runtime-cp-test-gradle-convention && ./gradlew --stop
- uses: ./.github/prepare-cache-action

test-kotlin:
name: Test / Kotlin / ${{ matrix.kotlin-profile }}
runs-on: ubuntu-latest
needs:
- build
strategy:
fail-fast: false
matrix:
kotlin-profile: ["kotlin-1.9", "kotlin-2.0"]
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'maven'
- name: Make Maven Wrapper executable
run: chmod +x ./mvnw
- name: Build with Maven
run: ./mvnw install --file pom.xml -DskipTests=true
- name: Test Kotlin Profile ${{ matrix.kotlin-profile }}
run: ./mvnw test --file pom.xml --projects jte-kotlin --also-make --activate-profiles ${{ matrix.kotlin-profile }}
- uses: ./.github/prepare-cache-action

coverage:
name: Test / Coverage
# Do not run coverage for forks since they cannot upload
# the results to codecov. For reference, see:
# https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution#example-only-run-job-for-specific-repository
if: github.repository == 'casid/jte'
runs-on: ubuntu-latest
needs:
- test-gradle-plugin
- test-kotlin
- test-graal
steps:
- uses: actions/checkout@v4
- name: Set up JDK
Expand All @@ -94,7 +170,7 @@ jobs:
if: contains(matrix.os, 'win') == false
run: chmod +x ./mvnw
- name: Build with Maven
run: ./mvnw verify --file pom.xml -Pcoverage
run: ./mvnw verify --file pom.xml -Pcoverage,kotlin-1.9
- name: Upload coverage report
uses: codecov/codecov-action@v4
env:
Expand Down
10 changes: 9 additions & 1 deletion jte-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<properties>
<maven.deploy.skip>false</maven.deploy.skip>
<skipNexusStagingDeployMojo>false</skipNexusStagingDeployMojo>
<kotlin.version>1.9.10</kotlin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -50,6 +49,15 @@
</build>

<profiles>
<profile>
<id>kotlin-1.9</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<kotlin.version>1.9.10</kotlin.version>
</properties>
</profile>
<profile>
<id>kotlin-2.0</id>
<properties>
Expand Down
17 changes: 16 additions & 1 deletion test/jte-runtime-test-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<maven.deploy.skip>true</maven.deploy.skip>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
<jacoco.version>0.8.10</jacoco.version>
<kotlin.version>1.9.10</kotlin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -69,6 +68,22 @@
</plugins>
</build>
</profile>
<!-- Kotlin versions -->
<profile>
<id>kotlin-1.9</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<kotlin.version>1.9.10</kotlin.version>
</properties>
</profile>
<profile>
<id>kotlin-2.0</id>
<properties>
<kotlin.version>2.0.20</kotlin.version>
</properties>
</profile>
</profiles>

<build>
Expand Down

0 comments on commit 6f5434e

Please sign in to comment.