From 2b4b86b147cfe7b9d5234cdb40bbf86c1faaa02d Mon Sep 17 00:00:00 2001
From: AH-dark <ahdark@outlook.com>
Date: Thu, 7 Dec 2023 23:45:37 +0800
Subject: [PATCH] ci: releaser

---
 .github/workflows/release.yml | 37 ++++++++++++++
 build.gradle.kts              | 93 ++++++++++++++++++++++++++++++++++-
 2 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 .github/workflows/release.yml

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..b0b18fb
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,37 @@
+name: release
+
+on:
+  push:
+    branches:
+      - main
+    tags:
+      - *
+  workflow_dispatch:
+
+jobs:
+  release:
+    name: Release
+
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+
+      # Configure build steps as you'd normally do
+
+      - name: Setup Java
+        uses: actions/setup-java@v3
+        with:
+          java-version: 21
+          distribution: 'oracle'
+          cache: gradle
+
+      # Create a release
+
+      - name: Run JReleaser
+        uses: jreleaser/release-action@v2
+        env:
+          JRELEASER_GITHUB_TOKEN: ${{ github.token }}
+          JRELEASER_DOCKER_GHCR_USERNAME: ${{ github.actor }}
+          JRELEASER_DOCKER_GHCR_PASSWORD: ${{ github.token }}
diff --git a/build.gradle.kts b/build.gradle.kts
index fd93242..f5048ee 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,3 +1,7 @@
+import org.jreleaser.model.Active
+import org.jreleaser.model.Distribution.DistributionType
+import org.jreleaser.model.Stereotype
+
 val ktor_version: String by project
 val kotlin_version: String by project
 val logback_version: String by project
@@ -10,10 +14,11 @@ plugins {
     kotlin("jvm") version "1.9.21"
     id("io.ktor.plugin") version "2.3.6"
     id("org.jetbrains.kotlin.plugin.serialization") version "1.9.21"
+    id("org.jreleaser") version "1.9.0"
 }
 
 group = "com.ahdark.code"
-version = "0.0.1"
+version = "1.0.0"
 
 application {
     mainClass.set("com.ahdark.code.ApplicationKt")
@@ -22,6 +27,92 @@ application {
     applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
 }
 
+jreleaser {
+    project {
+        name = "ahdark-blog-releaser"
+        stereotype = Stereotype.WEB
+        description = "AHdark Blog Release Notification Service"
+        longDescription = """
+        This project is a Kotlin-based HTTP server designed to handle GitHub Webhooks. It automatically forwards push notifications from the main branch of a GitHub repository to a specified Telegram chat, facilitating real-time updates.
+        """.trimIndent()
+        license = "MIT"
+        authors = listOf("AHdark")
+        maintainers = listOf("AH-dark")
+        inceptionYear = "2023"
+        website = "https://github.com/aH-dark/ahdark-blog-releaser"
+        docsUrl = "https://github.com/AH-dark/ahdark-blog-releaser/wiki"
+
+        java {
+            version = "21"
+        }
+    }
+
+    release {
+        github {
+            repoOwner = "ahdark"
+            overwrite = true
+        }
+    }
+
+    checksum {
+        name = "{{projectName}}-{{projectVersion}}_checksums.txt"
+
+        algorithm("MD5")
+        algorithm("SHA-256")
+
+        individual = true
+        artifacts = true
+        files = true
+    }
+
+    distributions {
+        create("app") {
+            active = Active.RELEASE
+            distributionType = DistributionType.JAVA_BINARY
+
+            platform {
+                replacements.put("osx-x86_64", "mac")
+                replacements.put("aarch_64", "aarch64")
+                replacements.put("x86_64", "amd64")
+                replacements.put("linux_musl", "alpine")
+            }
+
+            artifacts {
+                artifact {
+                    path = File("build/{{distributionName}}-{{projectVersion}}.zip")
+                }
+                artifact {
+                    path = File("build/{{distributionName}}-{{projectVersion}}-mac.zip")
+                    platform = "osx"
+                }
+                artifact {
+                    path = File("build/{{distributionName}}-{{projectVersion}}-windows.zip")
+                    platform = "windows"
+                }
+            }
+        }
+    }
+
+    packagers {
+        docker {
+            active = Active.RELEASE
+
+            buildx {
+                enabled = true
+
+                platform("linux/amd64")
+                platform("linux/arm64")
+            }
+
+            registries {
+                create("ghcr") {
+                    server = "https://ghcr.io"
+                }
+            }
+        }
+    }
+}
+
 repositories {
     mavenCentral()
     maven("https://jitpack.io")