Skip to content

Commit

Permalink
πŸ”¨ Split modules
Browse files Browse the repository at this point in the history
Movin `main` method to a separate module simplifies testing
  • Loading branch information
vlsi committed Aug 9, 2020
1 parent 594213e commit ec0c31a
Show file tree
Hide file tree
Showing 48 changed files with 88 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
run: |
git fetch origin refs/heads/release:release
git checkout release
cp build/distributions/gradle-cache-action.js* dist/
cp cache-action-entrypoint/build/distributions/cache-action-entrypoint.js* dist/
rm dist/gradle-cache-action.js*
git checkout main action.yml
git add dist/ action.yml
if git diff --staged --quiet; then
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ inputs:
required: false
runs:
using: node12
main: dist/gradle-cache-action.js
post: dist/gradle-cache-action.js
main: dist/cache-action-entrypoint.js
post: dist/cache-action-entrypoint.js
branding:
icon: archive
color: gray-dark
40 changes: 9 additions & 31 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,44 +1,22 @@
plugins {
kotlin("js")
kotlin("plugin.serialization")
kotlin("js") apply false
}

allprojects {
repositories {
jcenter()
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile>().configureEach {
kotlinOptions {
moduleKind = "commonjs"
}
}
}

kotlin {
js {
browser {
testTask {
useMocha()
testLogging {
showStandardStreams = true
}
plugins.withId("org.jetbrains.kotlin.js") {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile>().configureEach {
kotlinOptions {
moduleKind = "commonjs"
}
}
binaries.executable()
}
}

configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
nodeVersion = "12.18.3"
}

val String.v: String get() = rootProject.extra["$this.version"] as String

dependencies {
implementation(project(":lib"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${"kotlinx-coroutines".v}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${"kotlinx-serialization".v}")
implementation("org.jetbrains:kotlin-extensions:${"kotlin-wrappers".v}-kotlin-${"kotlin".v}")

testImplementation(kotlin("test-js"))
plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
nodeVersion = "12.18.3"
}
}
14 changes: 14 additions & 0 deletions cache-action-entrypoint/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
kotlin("js")
}

kotlin {
js {
browser()
binaries.executable()
}
}

dependencies {
implementation(project(":layered-cache"))
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
/*
* Copyright 2020 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.github.burrunan.gradle

import com.github.burrunan.gradle.GradleCacheAction
import com.github.burrunan.gradle.Parameters
import com.github.burrunan.gradle.github.env.ActionsEnvironment
import com.github.burrunan.gradle.github.event.currentTrigger
import github.actions.core.info
import kotlinext.js.jsObject
import process

internal fun getInput(name: String, required: Boolean = false): String =
github.actions.core.getInput(name, jsObject { this.required = required })

suspend fun main() {
if (process.env["GITHUB_ACTIONS"].isNullOrBlank()) {
Expand All @@ -42,7 +20,9 @@ suspend fun main() {
concurrent = getInput("concurrent").ifBlank { "false" }.toBoolean(),
)

if (!params.generatedGradleJars && !params.localBuildCache) {
if (!params.generatedGradleJars && !params.localBuildCache &&
!params.gradleDependenciesCache && !params.mavenDependenciesCache
) {
info("All the caches are disabled, skipping the action")
return
}
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions layered-cache/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
kotlin("js")
kotlin("plugin.serialization")
}

kotlin {
js {
nodejs {
testTask {
useMocha()
testLogging {
showStandardStreams = true
}
}
}
}
}

val String.v: String get() = rootProject.extra["$this.version"] as String

dependencies {
api(project(":lib"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${"kotlinx-coroutines".v}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${"kotlinx-serialization".v}")
api("org.jetbrains:kotlin-extensions:${"kotlin-wrappers".v}-kotlin-${"kotlin".v}")

testImplementation(kotlin("test-js"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.github.burrunan.gradle.github.stateVariable
import com.github.burrunan.gradle.github.suspendingStateVariable
import com.github.burrunan.gradle.github.toBoolean
import fs2.promises.readFile
import github.actions.core.ext.getInput
import github.actions.exec.exec
import kotlinx.coroutines.await

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package github.actions.core.ext

import kotlinext.js.jsObject

fun getInput(name: String, required: Boolean = false): String =
github.actions.core.getInput(name, jsObject { this.required = required })
Empty file.
6 changes: 5 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ pluginManagement {

rootProject.name = "gradle-cache-action"

include("lib")
include(
"lib",
"layered-cache",
"cache-action-entrypoint"
)

0 comments on commit ec0c31a

Please sign in to comment.