Skip to content

Commit

Permalink
1.0.0: The initial version!
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Sep 21, 2024
0 parents commit 0a09263
Show file tree
Hide file tree
Showing 38 changed files with 2,522 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
insert_final_newline = true
indent_style = tab
trim_trailing_whitespace = true
max_line_length = 120

[{*.yml,*.yaml}]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .github/boring-cyborg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Boring Cyborg: https://probot.github.io/apps/boring-cyborg/
_extends: ".github"
2 changes: 2 additions & 0 deletions .github/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# to-do: https://probot.github.io/apps/todo/
_extends: ".github"
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
enable-beta-ecosystems: true

updates:
- package-ecosystem: "gradle"
directory: "/"

schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"

schedule:
interval: "weekly"
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)
2 changes: 2 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Settings: https://probot.github.io/apps/settings/
_extends: ".github"
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)
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI (PRs/branches)

on:
push:
branches-ignore:
- "root"

pull_request:
merge_group:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4

with:
java-version: 17
distribution: temurin

- name: Set up Gradle properties
run: |
mkdir -p ~/.gradle
echo "org.gradle.jvmargs=-XX:MaxMetaspaceSize=5G" >> ~/.gradle/gradle.properties
- name: Gradle (Setup)
uses: gradle/actions/setup-gradle@v4

- name: Gradle (Build)
run: "./gradlew checkLicenses build"

env:
NO_SIGNING: "true"

- name: Upload JARs
uses: actions/upload-artifact@v4

with:
name: JARs
path: "*/build/libs/*.jar"
53 changes: 53 additions & 0 deletions .github/workflows/root.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI (root)

on:
push:
branches:
- "root"

permissions:
contents: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4

with:
java-version: 17
distribution: temurin

- name: Set up Kotlin
uses: fwilhe2/setup-kotlin@main

- name: Set up Gradle properties

run: |
mkdir -p ~/.gradle
echo "githubToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.gradle/gradle.properties
echo -e "\norg.gradle.jvmargs=-XX:MaxMetaspaceSize=5G" >> ~/.gradle/gradle.properties
- name: Gradle (Setup)
uses: gradle/actions/setup-gradle@v4

with:
dependency-graph: generate-and-submit

- name: Gradle (Build)
run: "./gradlew checkLicenses build"

env:
NO_SIGNING: "true"

- name: Upload JARs
uses: actions/upload-artifact@v4

with:
name: JARs
path: "*/build/libs/*.jar"
Loading

0 comments on commit 0a09263

Please sign in to comment.