Skip to content

Commit

Permalink
Enable CI for Gradle Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ihostage committed Jul 3, 2023
1 parent 0dcb2e8 commit 18ccb37
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ concurrency:
cancel-in-progress: true

jobs:
# Run Gradle Wrapper Validation to verify the wrapper's checksum
gradle-validation:
name: Gradle Wrapper
uses: playframework/.github/.github/workflows/gradle-wrapper-validation.yml@gradle # TODO: change version to v3

check-code-style:
name: Code Style
uses: playframework/.github/.github/workflows/cmd.yml@v3
needs:
- "gradle-validation"
uses: playframework/.github/.github/workflows/cmd.yml@gradle # TODO: change version to v3
with:
cmd: sbt validateCode
gradle-build-root: gradle-twirl
cmd: |
sbt validateCode
cd gradle-twirl && ./gradlew clean spotlessCheck --no-daemon
check-binary-compatibility:
name: Binary Compatibility
Expand All @@ -37,11 +47,12 @@ jobs:
- "check-code-style"
- "check-binary-compatibility"
- "check-docs"
uses: playframework/.github/.github/workflows/cmd.yml@v3
uses: playframework/.github/.github/workflows/cmd.yml@gradle # TODO: change version to v3
with:
java: 17, 11
scala: 2.12.x, 2.13.x, 3.x
cmd: scripts/test-code.sh
gradle-build-root: gradle-twirl

finish:
name: Finish
Expand Down
23 changes: 21 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@ on:
push:
branches: # Snapshots
- main
- gradle # TODO: remove this line
tags: ["**"] # Releases
release:
types: [published]

jobs:
publish-artifacts:
publish-snapshot-artifacts:
name: Publish / Artifacts
uses: playframework/.github/.github/workflows/publish.yml@v3
if: github.ref_type == 'branch' # Snapshots
uses: playframework/.github/.github/workflows/publish.yml@gradle # TODO: change version to v3
with:
gradle-build-root: gradle-twirl
cmd: |
cd gradle-twirl
./gradlew --no-daemon publishToSonatype -x test -PsonatypeUsername="$SONATYPE_USERNAME" -PsonatypePassword="$SONATYPE_PASSWORD"
secrets: inherit

publish-release-artifacts:
name: Publish / Artifacts
if: github.ref_type == 'tag' # Releases
uses: playframework/.github/.github/workflows/publish.yml@gradle # TODO: change version to v3
with:
gradle-build-root: gradle-twirl
cmd: |
sbt ci-release
cd gradle-twirl
./gradlew --no-daemon publishPlugins -x test -Pgradle.publish.key="$GRADLE_PUBLISH_KEY" -Pgradle.publish.secret="$GRADLE_PUBLISH_SECRET"
secrets: inherit
35 changes: 32 additions & 3 deletions gradle-twirl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
*/

import java.time.Duration
import java.util.Base64
import kotlin.text.Charsets.UTF_8

plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
`java-gradle-plugin`
id("com.gradle.plugin-publish") version "1.2.0"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("com.diffplug.spotless") version "6.19.0"
signing
}

// group = "com.playframework" // group and plugin id must use same top level namespace
group = "com.typesafe.play" // TODO: remove this line
version = "0.0.1-SNAPSHOT"

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
Expand Down Expand Up @@ -38,10 +47,30 @@ testing {
}
}

signing {
val signingKey = Base64.getDecoder().decode(System.getenv("PGP_SECRET").orEmpty()).toString(UTF_8)
val signingPassword = System.getenv("PGP_PASSPHRASE").orEmpty()
useInMemoryPgpKeys(signingKey, signingPassword)
}

nexusPublishing {
packageGroup.set(project.group.toString())
clientTimeout.set(Duration.ofMinutes(60))
this.repositories {
sonatype()
}
}

gradlePlugin {
website.set("https://www.playframework.com/documentation/latest/ScalaTemplates")
vcsUrl.set("https://github.com/playframework/twirl")
// Define the plugin
val greeting by plugins.creating {
id = "com.playframework.twirl"
// id = "com.playframework.twirl"
id = "com.typesafe.play.twirl" // TODO: remove this line
displayName = "Twirl Plugin"
description = "A Gradle plugin to compile Twirl templates"
tags.set(listOf("playframework", "web", "template", "java", "scala"))
implementationClass = "play.twirl.gradle.TwirlPlugin"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private File getSettingsFile() {
@Test
void canRunTask() throws IOException {
writeString(getSettingsFile(), "");
writeString(getBuildFile(), "plugins {" + " id('com.playframework.twirl')" + "}");
writeString(getBuildFile(), "plugins {" + " id('com.typesafe.play.twirl')" + "}");

// Run the build
GradleRunner runner = GradleRunner.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TwirlPluginTest {
void pluginRegistersATask() {
// Create a test project and apply the plugin
Project project = ProjectBuilder.builder().build();
project.getPlugins().apply("com.playframework.twirl");
project.getPlugins().apply("com.typesafe.play.twirl");

// Verify the result
assertNotNull(project.getTasks().findByName("greeting"));
Expand Down
1 change: 1 addition & 0 deletions scripts/test-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

sbt "++$MATRIX_SCALA test" || exit 1
sbt +publishLocal plugin/test plugin/scripted || exit 1
(cd gradle-twirl && ./gradlew clean check -x spotlessCheck --no-daemon) || exit 1

0 comments on commit 18ccb37

Please sign in to comment.