Skip to content

Commit 60e3e40

Browse files
Integrated example project for Mill into CI task (#22702)
* Integrated example project for Mill into CI task The example project uses Mills meta-build to resolve the snapshot version from a properties file. The properties-file is now integrated into `release_version_update.sh`. * Add coursier cache to actions-cache * Split Mill tests into separate steps * try to exclude problematic dependencies from maven-cache so they are downloaded by coursier * clear m2-cache prior to mill execution
1 parent 7f96a4a commit 60e3e40

File tree

13 files changed

+114
-34
lines changed

13 files changed

+114
-34
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Mill plugin tests
2+
3+
on:
4+
push:
5+
paths:
6+
- modules/openapi-generator-mill-plugin/**
7+
pull_request:
8+
paths:
9+
- modules/openapi-generator-mill-plugin/**
10+
11+
jobs:
12+
test:
13+
name: Mill plugin tests
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v5
17+
- name: Set up JDK 11
18+
uses: actions/setup-java@v5
19+
with:
20+
java-version: 11
21+
distribution: 'temurin'
22+
- name: Restore cache (read-only)
23+
# only use restore keys, no save key because we need to clear the cache before running the examples
24+
uses: actions/cache/restore@v4
25+
with:
26+
path: |
27+
~/.m2/repository
28+
~/.gradle
29+
~/.cache/coursier
30+
!~/.gradle/caches/*/plugin-resolution/
31+
!~/.m2/repository/org/openapitools/
32+
!~/.cache/coursier/v1/https/repo1.maven.org/maven2/org/openapitools/
33+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
34+
35+
- name: Maven Clean Install
36+
env:
37+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
38+
run: |
39+
./mvnw clean install -DskipTests -Dmaven.javadoc.skip=true
40+
41+
# This is needed because of differences in how Maven and Coursier download artifacts
42+
# Maven will only download the pom when the transitive dependency is not needed in the current projects compile classpath
43+
# whereas Coursier expects the artifact (jar) to be present in a Maven repository. When Coursier encounters a
44+
# artifact folder with a pom it considers the artifact to be available and will then crash when the jar is missing.
45+
- name: Clear m2 cache except openapitools (because otherwise coursier will fail to resolve artifacts where only poms are downloaded)
46+
run: |
47+
mv ~/.m2/repository/org/openapitools /tmp/openapitools-backup || true
48+
rm -rf ~/.m2/repository/*
49+
mkdir -p ~/.m2/repository/org
50+
mv /tmp/openapitools-backup ~/.m2/repository/org/openapitools || true
51+
52+
- name: Mill Example - Test Validation Command
53+
env:
54+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
55+
run: |
56+
(cd modules/openapi-generator-mill-plugin/example/ && ./mill validateOpenapiSpec $(pwd)/api/petstore-invalid.yaml)
57+
58+
- name: Mill Example - Test Validation Task
59+
env:
60+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
61+
run: |
62+
(cd modules/openapi-generator-mill-plugin/example/ && ./mill openapi.validate)
63+
64+
- name: Mill Example - Test Compile Task
65+
env:
66+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
67+
run: |
68+
(cd modules/openapi-generator-mill-plugin/example/ && ./mill __.compile)
69+

bin/utils/release/release_version_update.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ declare -a xml_files=(
9393
declare -a properties_files=(
9494
"${root}/modules/openapi-generator-gradle-plugin/gradle.properties"
9595
"${root}/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties"
96+
"${root}/modules/openapi-generator-mill-plugin/example/mill-build/version.properties"
9697
)
9798

9899
${cwd}/bump.sh -f ${version} -i ${inc} ${xml_files[@]}

modules/openapi-generator-mill-plugin/mill-test/api/petstore-v3.0-invalid.yaml renamed to modules/openapi-generator-mill-plugin/example/api/petstore-invalid.yaml

File renamed without changes.

modules/openapi-generator-mill-plugin/mill-test/api/petstore.yaml renamed to modules/openapi-generator-mill-plugin/example/api/petstore.yaml

File renamed without changes.

modules/openapi-generator-mill-plugin/mill-test/build.mill renamed to modules/openapi-generator-mill-plugin/example/build.mill

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//| mill-version: 1.0.6
2-
//| mvnDeps:
3-
//| - com.lihaoyi::mill-contrib-versionfile:$MILL_VERSION
4-
//| - org.openapitools:openapi-generator-mill-plugin:$MILL_OPENAPITOOLS_PLUGIN_VERSION
2+
//| # usually you would add the plugin dependency like the following,
3+
//| # but for testing with SNAPSHOT versions, the plugin dependency is added in the meta-build
4+
//| # mvnDeps:
5+
//| # - org.openapitools:openapi-generator-mill-plugin:$MILL_OPENAPITOOLS_PLUGIN_VERSION
56
//|
67
package build
78

@@ -12,15 +13,12 @@ import mill.scalalib.publish.PomSettings
1213
import mill.util.BuildInfo.{millBinPlatform, millVersion}
1314
import javalib.*
1415

15-
import mill.contrib.versionfile.VersionFileModule
1616
import org.openapitools.generator.mill.OpenApiModule
1717

1818
object `package` extends JavaModule with MavenModule with OpenApiModule {
1919

20-
// dependency on openapi-generator is set in Mills meta-build
21-
// this is needed to point to a local maven repo
2220
override def mvnDeps = Seq(
23-
mvn"jakarta.platform:jakarta.jakartaee-api:11.0.0",
21+
mvn"jakarta.platform:jakarta.jakartaee-api:10.0.0",
2422
mvn"com.fasterxml.jackson.core:jackson-databind:2.20.0",
2523
mvn"org.openapitools:jackson-databind-nullable:0.2.8"
2624
)
File renamed without changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
import coursier.LocalRepositories.Dangerous
3+
import coursier.Repositories
4+
import mill.scalalib.DepSyntax
5+
import mill.*
6+
import mill.api.Task
7+
import mill.meta.MillBuildRootModule
8+
import java.util.Properties
9+
import java.io.FileInputStream
10+
import scala.util.Using
11+
12+
object `package` extends MillBuildRootModule {
13+
14+
override def repositories = Task {
15+
Seq(
16+
// central needed for default deps
17+
Repositories.central.root,
18+
// the previously installed snapshot is in local maven
19+
// see docs on Coursier, why m2 is considered dangerous
20+
Dangerous.maven2Local.root)
21+
}
22+
23+
def propsFile = Task.Source("version.properties")
24+
25+
def readOpenapiSnapshotVersion: Task[String] = Task {
26+
val props = new Properties()
27+
Using(new FileInputStream(propsFile().path.toIO)) { fis =>
28+
props.load(fis)
29+
props.getProperty("openApiGeneratorVersion")
30+
}.get
31+
}
32+
33+
override def mvnDeps = Seq(
34+
mvn"org.openapitools:openapi-generator-mill-plugin:${readOpenapiSnapshotVersion()}"
35+
)
36+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# RELEASE_VERSION
2+
openApiGeneratorVersion=7.19.0-SNAPSHOT
3+
# /RELEASE_VERSION

modules/openapi-generator-mill-plugin/mill-test/mill.bat renamed to modules/openapi-generator-mill-plugin/example/mill.bat

File renamed without changes.

modules/openapi-generator-mill-plugin/mill-test/src/main/java/com/acme/foo/boundary/web/TestController.java renamed to modules/openapi-generator-mill-plugin/example/src/main/java/com/acme/foo/boundary/web/TestController.java

File renamed without changes.

0 commit comments

Comments
 (0)