From 2b9fbee775300877c64e52f4f27ec5825d3cb79f Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Sat, 7 Dec 2024 11:51:48 -0300 Subject: [PATCH] Fix ci.yml for Gradle projects - Should use gradle/actions/setup-gradle action instead too --- .../base/.github/workflows/ci.tpl.qute.yml | 17 ++++++------ .../QuarkusCodestartGenerationTest.java | 27 ++++++++++++++----- .../.github_workflows_ci.yml | 11 +++++--- .../.github_workflows_ci.yml | 9 +++++-- .../.github_workflows_ci.yml | 25 +++++++++++++++++ 5 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenGithubAction/.github_workflows_ci.yml diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/github-action/base/.github/workflows/ci.tpl.qute.yml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/github-action/base/.github/workflows/ci.tpl.qute.yml index 7dece3c9e74cd9..9e6edad446fe2f 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/github-action/base/.github/workflows/ci.tpl.qute.yml +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/github-action/base/.github/workflows/ci.tpl.qute.yml @@ -12,22 +12,23 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Set up JDK {java.version} uses: actions/setup-java@v4 with: java-version: {java.version} distribution: temurin - {#if buildtool.cli == 'gradle'} + {#if buildtool.cli.contains('gradle')} cache: gradle {#else} cache: maven {/if} + + {#if buildtool.cli.contains('gradle')} + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + {/if} - name: Build - {#if buildtool.cli == 'gradle'} - uses: eskatos/gradle-command-action@v1 - with: - arguments: {buildtool.cmd.build-ci} - {#else} run: {buildtool.cli} {buildtool.cmd.build-ci} - {/if} diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java index 4723c18d9d0186..25863e9bfb7f23 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java @@ -1,8 +1,6 @@ package io.quarkus.devtools.codestarts.quarkus; -import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.PROJECT_PACKAGE_NAME; -import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.RESTEASY_CODESTART_RESOURCE_CLASS_NAME; -import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.RESTEASY_CODESTART_RESOURCE_PATH; +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.*; import static io.quarkus.devtools.testing.FakeExtensionCatalog.FAKE_QUARKUS_CODESTART_CATALOG; import static io.quarkus.devtools.testing.SnapshotTesting.assertThatMatchSnapshot; import static io.quarkus.devtools.testing.SnapshotTesting.checkContains; @@ -262,7 +260,23 @@ public void generateGradleWrapperGithubAction(TestInfo testInfo) throws Throwabl checkGradle(projectDir); assertThatMatchSnapshot(testInfo, projectDir, ".github/workflows/ci.yml") - .satisfies(checkContains("run: ./gradlew build")); + .satisfies( + checkContains("cache: gradle"), + checkContains("run: ./gradlew build")); + } + + @Test + public void generateMavenGithubAction(TestInfo testInfo) throws Throwable { + final QuarkusCodestartProjectInput input = newInputBuilder() + .buildTool(BuildTool.MAVEN) + .addData(getGenerationTestInputData()) + .addCodestarts(Collections.singletonList("tooling-github-action")) + .build(); + Path projectDir = testDirPath.resolve("maven-github"); + getCatalog().createProject(input).generate(projectDir); + + assertThatMatchSnapshot(testInfo, projectDir, ".github/workflows/ci.yml") + .satisfies(checkContains("cache: maven")); } @Test @@ -279,8 +293,9 @@ public void generateGradleNoWrapperGithubAction(TestInfo testInfo) throws Throwa checkGradle(projectDir); assertThatMatchSnapshot(testInfo, projectDir, ".github/workflows/ci.yml") - .satisfies(checkContains("uses: eskatos/gradle-command-action@v1")) - .satisfies(checkContains("arguments: build")); + .satisfies( + checkContains("uses: gradle/actions/setup-gradle"), + checkContains("cache: gradle")); } private void checkDockerfiles(Path projectDir, BuildTool buildTool) { diff --git a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleNoWrapperGithubAction/.github_workflows_ci.yml b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleNoWrapperGithubAction/.github_workflows_ci.yml index 92af3184ba7382..49fc6c79c53da4 100644 --- a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleNoWrapperGithubAction/.github_workflows_ci.yml +++ b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleNoWrapperGithubAction/.github_workflows_ci.yml @@ -12,14 +12,17 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: java-version: 17 distribution: temurin cache: gradle + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Build - uses: eskatos/gradle-command-action@v1 - with: - arguments: build + run: gradle build diff --git a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleWrapperGithubAction/.github_workflows_ci.yml b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleWrapperGithubAction/.github_workflows_ci.yml index eb4e47391ac892..76078bfd44367c 100644 --- a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleWrapperGithubAction/.github_workflows_ci.yml +++ b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateGradleWrapperGithubAction/.github_workflows_ci.yml @@ -12,12 +12,17 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: java-version: 17 distribution: temurin - cache: maven + cache: gradle + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Build run: ./gradlew build diff --git a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenGithubAction/.github_workflows_ci.yml b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenGithubAction/.github_workflows_ci.yml new file mode 100644 index 00000000000000..593d3aeb9b2bf5 --- /dev/null +++ b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenGithubAction/.github_workflows_ci.yml @@ -0,0 +1,25 @@ +## A basic GitHub Actions workflow for your Quarkus application. + +name: CI build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + cache: maven + + - name: Build + run: ./mvnw verify -B