-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define protocol update as a Gradle task instead of script
This avoids having to setup kotlin in Github Actions (which currently has this problem: fwilhe2/setup-kotlin#85).
- Loading branch information
1 parent
2d7a488
commit 53e044e
Showing
4 changed files
with
66 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,21 +18,6 @@ jobs: | |
with: | ||
java-version: 11 | ||
|
||
- name: Set up Kotlin | ||
uses: fwilhe2/[email protected] | ||
with: | ||
version: 1.4.20 | ||
|
||
- name: Update protocol | ||
run: kotlinc -script update-protocol.kts | ||
|
||
- name: Read protocol version | ||
uses: pCYSl5EDgo/cat@master | ||
id: version | ||
with: | ||
path: protocol/version.txt | ||
trim: true | ||
|
||
- name: Gradle build cache | ||
uses: actions/[email protected] | ||
with: | ||
|
@@ -46,6 +31,16 @@ jobs: | |
path: ~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }} | ||
|
||
- name: Update protocol | ||
run: ./gradlew updateProtocolDefinitions | ||
|
||
- name: Read protocol version | ||
uses: pCYSl5EDgo/cat@master | ||
id: version | ||
with: | ||
path: protocol/version.txt | ||
trim: true | ||
|
||
- name: Update public ABI descriptors | ||
run: ./gradlew apiDump | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.hildan.chrome.devtools.build | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
import java.net.URL | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
private const val baseUrl = "https://raw.githubusercontent.com/ChromeDevTools/devtools-protocol" | ||
private const val branch = "master" | ||
private const val browserProtocolUrl = "$baseUrl/$branch/json/browser_protocol.json" | ||
private const val jsProtocolUrl = "$baseUrl/$branch/json/js_protocol.json" | ||
private const val packageJsonUrl = "$baseUrl/$branch/package.json" | ||
|
||
private val protocolDescriptorUrls = listOf(browserProtocolUrl, jsProtocolUrl) | ||
|
||
open class UpdateProtocolDefinitionsTask : DefaultTask() { | ||
|
||
init { | ||
// never consider this task up-to-date, the point is to check for updates | ||
outputs.upToDateWhen { false } | ||
} | ||
|
||
@OutputDirectory | ||
val outputDir: Path = project.rootDir.resolve("protocol").toPath() | ||
|
||
@TaskAction | ||
fun generate() { | ||
Files.createDirectories(outputDir) | ||
|
||
protocolDescriptorUrls.forEach { url -> | ||
print("Downloading protocol JSON spec from $url ... ") | ||
downloadTextFile(url, outputDir) | ||
println("Done.") | ||
} | ||
|
||
val newVersion = fetchProtocolNpmVersion() | ||
outputDir.resolve("version.txt").toFile().writeText(newVersion) | ||
println("Chrome Devtools Protocol definition updated to $newVersion") | ||
} | ||
} | ||
|
||
private fun fetchProtocolNpmVersion(): String { | ||
val packageJson = URL(packageJsonUrl).readText() | ||
return Regex(""""version"\s*:\s*"([^"]+)"""").find(packageJson)?.groupValues?.get(1) ?: "not-found" | ||
} | ||
|
||
private fun downloadTextFile(fileUrl: String, targetDir: Path) { | ||
val url = URL(fileUrl) | ||
val text = url.readText() | ||
val outputFilePath = targetDir.resolve(url.path.substringAfterLast('/')) | ||
outputFilePath.toFile().writeText(text) | ||
} |
This file was deleted.
Oops, something went wrong.