Skip to content

Commit

Permalink
Prepare for the 1.4.4-RC1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Aug 4, 2021
1 parent 5a62936 commit dee758a
Show file tree
Hide file tree
Showing 43 changed files with 266 additions and 3,610 deletions.
62 changes: 0 additions & 62 deletions .github/relay_release.py

This file was deleted.

105 changes: 105 additions & 0 deletions .github/release.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
@file:DependsOn("io.github.rybalkinsd:kohttp:0.12.0")
@file:DependsOn("com.google.code.gson:gson:2.8.6")

import com.google.gson.GsonBuilder
import io.github.rybalkinsd.kohttp.dsl.httpGet
import io.github.rybalkinsd.kohttp.dsl.httpPost
import io.github.rybalkinsd.kohttp.ext.url
import kotlin.system.exitProcess

val gson = GsonBuilder()

val webhookUrl: String = System.getenv("WEBHOOK_URL")

var githubTag: String = System.getenv("GITHUB_REF")
val repo: String = System.getenv("GITHUB_REPOSITORY")

if (githubTag.contains("/")) {
githubTag = githubTag.split("/").last()
}

println("Current tag: $githubTag")

val apiUrl = "https://api.github.com/repos/$repo/releases/tags/$githubTag"

if (githubTag.contains("v")) {
githubTag = githubTag.split("v", limit = 2).last()
}

val response = httpGet { url(apiUrl) }
val responseCode = response.code()

if (responseCode >= 400) {
println("API error: HTTP $responseCode")
println(response.body()?.string())

exitProcess(1)
}

val data = gson.create().fromJson<Map<String, *>>(response.body()!!.string(), Map::class.java)

val author = data["author"] as Map<*, *>

val authorAvatar = author["avatar_url"] as String
val authorName = author["login"] as String
val authorUrl = author["html_url"] as String

var releaseBody = (data["body"] as String).replace("\n* ", "\n**»** ").trim()
val releaseName = data["name"] as String
val releaseTime = data["published_at"] as String
val releaseUrl = data["html_url"] as String

if (releaseBody.startsWith("#")) {
val lines = releaseBody.split("\n").toMutableList()

lines[0] = lines[0].replaceFirst("#", "**") + "**"
releaseBody = lines.joinToString("\n")
}

if (releaseBody.contains("---")) {
releaseBody = releaseBody.split("---", limit = 2).first()
}

val webhook = mapOf(
"embeds" to listOf(
mapOf(
"color" to 7506394,
"description" to releaseBody,
"timestamp" to releaseTime.replace("Z", ".000Z"),
"title" to releaseName,
"url" to releaseUrl,

"author" to mapOf(
"icon_url" to authorAvatar,
"name" to authorName,
"url" to authorUrl,
)
)
)
)

val jsonBody = gson.create().toJson(webhook)

val webhookResponse = httpPost {
url(webhookUrl)

header {
"User-Agent" to "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) " +
"Chrome/35.0.1916.47 Safari/537.36"
}

body {
json(jsonBody)
}
}

val webhookCode = webhookResponse.code()

if (webhookCode >= 400) {
println("Webhook error: HTTP $webhookCode")
println(webhookResponse.body()?.string())

exitProcess(1)
}

exitProcess(0)
77 changes: 77 additions & 0 deletions .github/tag.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@file:DependsOn("com.lordcodes.turtle:turtle:0.5.0")

import com.lordcodes.turtle.shellRun
import java.io.File
import kotlin.system.exitProcess

//val webhookUrl = System.getenv("WEBHOOK_URL")
val repo = System.getenv("GITHUB_REPOSITORY")

var githubTag: String = System.getenv("GITHUB_REF") ?: error("No tag found in GITHUB_REF env var")

if (githubTag.contains("/")) {
githubTag = githubTag.split("/").last()
}

println("Current tag: $githubTag")

if (githubTag.contains("v")) {
githubTag = githubTag.split("v", limit = 2).last()
}

val tags = shellRun("git", listOf("tag")).trim().split("\n")

val commits = if (tags.size < 2) {
println("No previous tags, using all branch commits.")

shellRun("git", listOf("log", "--format=oneline", "--no-color"))
} else {
val previousTag = tags.takeLast(2).first()

println("Previous tag: $previousTag")

shellRun("git", listOf("log", "--format=oneline", "--no-color", "$previousTag..HEAD"))
}.split("\n").map {
val split = it.split(" ", limit = 2)
val commit = split.first()
val message = split.last()

Pair(commit, message)
}

println("Commits: ${commits.size}")

val commitList = if (commits.size > 10) {
commits.take(10).joinToString("\n") {
val (commit, message) = it

"* [${commit.take(6)}](https://github.com/$repo/commit/$commit): $message"
} + "\n\n...and ${commits.size - 10} more."
} else {
commits.joinToString("\n") {
val (commit, message) = it

"* [${commit.take(6)}](https://github.com/$repo/commit/$commit): $message"
}
}

val descFile = File("changes/$githubTag.md")

val description = if (descFile.exists()) {
descFile.readText(Charsets.UTF_8).trim()
} else {
"Description file `changes/$githubTag.md` not found - this release will need to be updated later!"
}

val file = File("release.md")

file.writeText(
"$description\n\n" +
"---\n\n" +
"# Commits (${commits.size}) \n\n" +
commitList
)

print("File written: release.md")

exitProcess(0)
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: CI (PRs/root)
name: CI (PRs/branches)

on:
push:
branches-ignore:
- "develop"
- "gh-pages"

pull_request:
Expand Down
51 changes: 0 additions & 51 deletions .github/workflows/docs-develop.yml

This file was deleted.

25 changes: 0 additions & 25 deletions .github/workflows/release.yml

This file was deleted.

Loading

0 comments on commit dee758a

Please sign in to comment.