mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
release uploading
This commit is contained in:
parent
e578d9fe51
commit
243a776d8f
@ -11,6 +11,11 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
import de.bixilon.kutil.array.ByteArrayUtil.toHex
|
||||
import de.bixilon.kutil.base64.Base64Util.fromBase64
|
||||
import de.bixilon.kutil.base64.Base64Util.toBase64
|
||||
import de.bixilon.kutil.buffer.BufferDefinition
|
||||
import de.bixilon.kutil.hash.HashUtil
|
||||
import de.bixilon.kutil.os.Architectures
|
||||
import de.bixilon.kutil.os.OSTypes
|
||||
import de.bixilon.kutil.os.PlatformInfo
|
||||
@ -24,7 +29,20 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import org.gradle.configurationcache.extensions.capitalized
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
import java.net.URI
|
||||
import java.net.URLEncoder
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpRequest.BodyPublishers
|
||||
import java.net.http.HttpResponse
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.KeyFactory
|
||||
import java.security.MessageDigest
|
||||
import java.security.Signature
|
||||
import java.security.spec.PKCS8EncodedKeySpec
|
||||
import java.util.stream.Collectors
|
||||
|
||||
|
||||
plugins {
|
||||
@ -429,7 +447,7 @@ fun loadGit() {
|
||||
stable = true
|
||||
tag.name
|
||||
} else {
|
||||
commit.abbreviatedId
|
||||
commit.id.substring(0, 9)
|
||||
}
|
||||
if (!git.status().isClean) {
|
||||
nextVersion += "-dirty"
|
||||
@ -526,3 +544,49 @@ task("assetsProperties", type = JavaExec::class) {
|
||||
standardOutput = System.out
|
||||
mainClass.set("de.bixilon.minosoft.assets.properties.version.generator.AssetsPropertiesGenerator")
|
||||
}
|
||||
|
||||
task("upload") {
|
||||
dependsOn("fatJar")
|
||||
doLast {
|
||||
val path = "${project.name}-fat-${os.name.lowercase()}-${architecture.name.lowercase()}-${project.version}.jar"
|
||||
val file = File("build/libs/$path")
|
||||
val key = KeyFactory.getInstance("RSA").generatePrivate(PKCS8EncodedKeySpec(System.getenv("RELEASE_KEY").fromBase64()))
|
||||
|
||||
val digest = MessageDigest.getInstance(HashUtil.SHA_512)
|
||||
val sign = Signature.getInstance("SHA512withRSA")
|
||||
sign.initSign(key)
|
||||
val stream = FileInputStream(file)
|
||||
|
||||
val buffer = ByteArray(BufferDefinition.DEFAULT_BUFFER_SIZE)
|
||||
var length: Int
|
||||
while (true) {
|
||||
length = stream.read(buffer, 0, buffer.size)
|
||||
if (length < 0) {
|
||||
break
|
||||
}
|
||||
digest.update(buffer, 0, length)
|
||||
sign.update(buffer, 0, length)
|
||||
}
|
||||
val sha512 = digest.digest().toHex()
|
||||
val signature = sign.sign().toBase64()
|
||||
|
||||
stream.close()
|
||||
|
||||
val data = mapOf(
|
||||
"size" to file.length(),
|
||||
"sha512" to sha512,
|
||||
"signature" to signature,
|
||||
"os" to os.name.lowercase(),
|
||||
"architecture" to architecture.name.lowercase(),
|
||||
)
|
||||
val url = System.getenv("MINOSOFT_API") + "/api/v1/releases/upload/${project.version}?"
|
||||
val client = HttpClient.newHttpClient()
|
||||
val request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(data.entries.stream().map { it.key + "=" + URLEncoder.encode(it.value.toString(), StandardCharsets.UTF_8) }.collect(Collectors.joining("&", url, ""))))
|
||||
.header("Authorization", "Bearer " + System.getenv("MINOSOFT_TOKEN"))
|
||||
.PUT(BodyPublishers.ofFile(file.toPath()))
|
||||
|
||||
val response = client.send(request.build(), HttpResponse.BodyHandlers.ofString())
|
||||
if (response.statusCode() != 200) throw IOException("Could not upload: $response")
|
||||
}
|
||||
}
|
||||
|
13
release/create.sh
Normal file → Executable file
13
release/create.sh
Normal file → Executable file
@ -12,11 +12,12 @@
|
||||
# This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
#
|
||||
|
||||
VERSION=$(git rev-parse --short HEAD)
|
||||
|
||||
curl \
|
||||
--form-string "stable=false" \
|
||||
-F "page=" \
|
||||
-F "release_notes=abc" \
|
||||
-F "channel=test" \
|
||||
-H "Authorization: Bearer ..Hs6dpK_aHBWeuasq2MA2c_zBw1JCJsgk4Lcw2fm1PoI" \
|
||||
localhost:8080/api/v1/releases/create/test
|
||||
# https://minosoft.bixilon.de/api/v1/releases/create/test
|
||||
--form-string "page=" \
|
||||
--form-string "release_notes=$(git log -1 --pretty=%B)" \
|
||||
--form-string "channel=master" \
|
||||
-H "Authorization: Bearer $MINOSOFT_TOKEN" \
|
||||
"$MINOSOFT_API/api/v1/releases/create/$VERSION"
|
||||
|
20
release/release.sh
Executable file
20
release/release.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/ash
|
||||
#
|
||||
# Minosoft
|
||||
# Copyright (C) 2020-2024 Moritz Zwerger
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
# This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
#
|
||||
|
||||
VERSION=$(git rev-parse --short HEAD)
|
||||
|
||||
curl \
|
||||
-X POST \
|
||||
-H "Authorization: Bearer $MINOSOFT_TOKEN" \
|
||||
"$MINOSOFT_API/api/v1/releases/release/$VERSION"
|
Loading…
x
Reference in New Issue
Block a user