Skip to content

Commit

Permalink
feat(plugin): add first try of task
Browse files Browse the repository at this point in the history
  • Loading branch information
manuandru committed Mar 14, 2024
1 parent 78b9fcb commit 32b23d6
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 218 deletions.
42 changes: 23 additions & 19 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@ jobs:
- name: Checkout
uses: DanySK/[email protected]
- uses: DanySK/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
# Dry-deployment
check-command: ./gradlew build --parallel
deploy-command: >-
./gradlew
uploadKotlinOSSRHToMavenCentralNexus
uploadPluginMavenToMavenCentralNexus
uploadPluginMarkerMavenToMavenCentralNexus
close
drop
--parallel
# deploy-command: >-
# ./gradlew
# uploadKotlinOSSRHToMavenCentralNexus
# uploadPluginMavenToMavenCentralNexus
# uploadPluginMarkerMavenToMavenCentralNexus
# close
# drop
# --parallel
should-run-codecov: ${{ runner.os == 'Linux' }}
should-deploy: >-
${{
runner.os == 'Linux'
&& !github.event.repository.fork
&& github.event_name != 'pull_request'
}}
maven-central-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
should-deploy: false
# should-deploy: >-
# ${{
# runner.os == 'Linux'
# && !github.event.repository.fork
# && github.event_name != 'pull_request'
# }}
# maven-central-username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
# maven-central-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
signing-key: ${{ secrets.SIGNING_KEY }}
signing-password: ${{ secrets.SIGNING_PASSWORD }}
release:
Expand All @@ -54,8 +58,8 @@ jobs:
steps:
- name: Checkout
uses: actions/[email protected]
with:
token: ${{ secrets.DEPLOYMENT_TOKEN }}
# with:
# token: ${{ secrets.DEPLOYMENT_TOKEN }}
- name: Find the version of Node from package.json
id: node-version
run: echo "version=$(jq -r .engines.node package.json)" >> $GITHUB_OUTPUT
Expand All @@ -75,8 +79,8 @@ jobs:
github-token: ${{ github.token }}
gradle-publish-secret: ${{ secrets.GRADLE_PUBLISH_SECRET }}
gradle-publish-key: ${{ secrets.GRADLE_PUBLISH_KEY }}
maven-central-username: 'zucchero-sintattico'
maven-central-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
# maven-central-username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
# maven-central-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
signing-key: ${{ secrets.SIGNING_KEY }}
signing-password: ${{ secrets.SIGNING_PASSWORD }}
success:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
build/
.idea/
node_modules/

.DS_Store
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inner class ProjectInfo {
val vcsUrl = "$website.git"
val scm = "scm:git:$website.git"
val pluginImplementationClass = "$group.gradle.Typescript"
val tags = listOf("typescript", "plugin", "gradle")
val tags = listOf("typescript", "compilation")
}
val info = ProjectInfo()

Expand Down Expand Up @@ -110,10 +110,13 @@ signing {
* Publication on Maven Central and the Plugin portal
*/
publishOnCentral {
configureMavenCentral.set(false) // Waiting for support for new central portal

projectLongName.set(info.longName)
projectDescription.set(description ?: TODO("Missing description"))
projectUrl.set(info.website)
scmConnection.set(info.scm)
group = "io.github.zucchero-sintattico"
repository("https://maven.pkg.github.com/zucchero-sintattico/${rootProject.name}".lowercase(), name = "github") {
user.set(System.getenv("GITHUB_ACTOR"))
password.set(System.getenv("GITHUB_TOKEN"))
Expand Down
4 changes: 2 additions & 2 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var publishCmd = `
./gradlew uploadKotlinOSSRHToMavenCentralNexus uploadPluginMavenToMavenCentralNexus uploadPluginMarkerMavenToMavenCentralNexus release || exit 1
// ./gradlew uploadKotlinOSSRHToMavenCentralNexus uploadPluginMavenToMavenCentralNexus uploadPluginMarkerMavenToMavenCentralNexus release || exit 1
let publishCmd = `
./gradlew publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET || exit 2
./gradlew publishKotlinOSSRHPublicationToGithubRepository publishPluginMavenPublicationToGithubRepository || true
`
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gradleEnterprise {

gitHooks {
preCommit {
tasks("ktlintCheck")
tasks("ktlintCheck", "detekt", "--parallel")
}
commitMsg { conventionalCommits() }
createHooks(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.zuccherosintattico.gradle

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

/**
* A task to check if Node is installed.
*/
open class CheckNodeTask : DefaultTask() {
init {
group = "Node"
description = "Check if Node is installed"
}

/**
* The task action to check if Node is installed.
*/
@TaskAction
fun checkNode() {
val res = Runtime.getRuntime().runCatching { exec("node --version").waitFor() }
if (res.isSuccess) {
logger.quiet("Node is installed")
} else {
logger.error("Node is not installed")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import java.io.Serializable
open class Typescript : Plugin<Project> {
override fun apply(project: Project) {
val extension = project.extensions.create<TypescriptExtension>("typescript")
project.tasks.register<TypescriptTask>("hello") {
author.set(extension.author)

val checkNodeTask = project.tasks.register<CheckNodeTask>("checkNode")

project.tasks.register<TypescriptTask>("compileTypescript") {
dependsOn(checkNodeTask)
sourceSet.set(extension.sourceSet)
}
}
}
Expand All @@ -35,13 +39,13 @@ open class TypescriptTask : DefaultTask() {
* Just a template.
*/
@Input
val author: Property<String> = project.objects.property()
val sourceSet: Property<String> = project.objects.property()

/**
* Read-only property calculated from the greeting.
*/
@Internal
val message: Provider<String> = author.map { "Hello from $it" }
val message: Provider<String> = sourceSet.map { "Hello from $it" }

/**
* Just a template.
Expand All @@ -60,7 +64,7 @@ open class TypescriptExtension(objects: ObjectFactory) : Serializable {
/**
* Just a template.
*/
val author: Property<String> = objects.property()
val sourceSet: Property<String> = objects.property<String>().convention("src/main/typescript")

companion object {
private const val serialVersionUID = 1L
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.github.zuccherosintattico.gradle

import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.matchers.paths.shouldExist
import org.gradle.testkit.runner.GradleRunner
import java.io.File
import java.nio.file.Files
import kotlin.io.path.createTempDirectory

class TypescriptPluginTest : AnnotationSpec() {

@BeforeAll
fun setup() {
val testkitProperties = javaClass.classLoader.getResource("testkit-gradle.properties")?.readText()
checkNotNull(testkitProperties) {
"No file testkit-gradle.properties was generated"
}
}

@Test
fun `test the plugin`() {
val folder = createTempDirectory("test")
folder.shouldExist()

val testResources = File("src/test/resources/plugin-base-env").toPath()
Files.walk(testResources)
.filter { it != testResources }
.map { testResources.relativize(it) }
.map { testResources.resolve(it) to folder.resolve(it) }
.forEach { (source, destination) ->
Files.createDirectories(destination.parent)
Files.copy(source, destination)
}

println(folder.toFile())

val result = with(GradleRunner.create()) {
withProjectDir(folder.toFile())
withArguments("compileTypescript", "--stacktrace")
withPluginClasspath()
build()
}

result.output.lines().forEach { println(it) }

// ProcessBuilder("npx", "tsc", "--outDir", "./build/bin", "src/main/typescript/*.ts")
// .directory(folder.toFile())
// .inheritIO()
// .start()
// .waitFor()
}
}
75 changes: 0 additions & 75 deletions src/test/kotlin/org/danilopianini/gradle/test/TestingDSL.kt

This file was deleted.

Loading

0 comments on commit 32b23d6

Please sign in to comment.