完善功能
Some checks failed
Gitea Actions Build / ${{gitea.event.head_commit.message}} ${{gitea.event.head_commit.url}} (push) Failing after 42s
Some checks failed
Gitea Actions Build / ${{gitea.event.head_commit.message}} ${{gitea.event.head_commit.url}} (push) Failing after 42s
This commit is contained in:
parent
71e554a16b
commit
75d1432907
@ -1,5 +1,5 @@
|
|||||||
name: Gitea Actions Build
|
name: Gitea Actions Build
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: ${{gitea.repository}} ${{gitea.event.head_commit.sha}} ${{gitea.event.head_commit.message}} is build and releases out Gitea Actions 🚀
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@ -7,20 +7,27 @@ on:
|
|||||||
- master
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Info:
|
Task:
|
||||||
|
name: ${{gitea.event.head_commit.message}} ${{gitea.event.head_commit.url}}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- logInfoMessage: Check out repository code
|
- name: Check out repository code
|
||||||
|
uses: https://git.mingliqiye.com/Actions/checkout@v4
|
||||||
|
|
||||||
|
- name: setup java
|
||||||
|
uses: https://git.mingliqiye.com/Actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'oracle'
|
||||||
|
java-version: '17'
|
||||||
|
|
||||||
|
- name: build
|
||||||
run: |
|
run: |
|
||||||
echo "${{gitea.server_url}}"
|
git update-index --chmod=+x ./gradlew
|
||||||
echo "${{gitea.api_url}}"
|
./gradlew
|
||||||
echo "${{gitea.repository_owner}}"
|
./gradlew build-jar
|
||||||
echo "${{gitea.repository}}"
|
- name: releases
|
||||||
echo "${{gitea.event.repository.name}}"
|
run: |
|
||||||
echo "${{gitea.token}}"
|
java -jar build/libs/com.mingliqiye.gitea.releases-1.0.jar -s ${{gitea.server_url}} -o ${{gitea.repository_owner}} -t "Auto Releases" -r ${{gitea.event.repository.name}} -t ${{gitea.token}} -ti "Auto releases ${{gitea.event.head_commit.sha}}" -b "# Auto releases wtih ${{gitea.event.head_commit.message}} -[${{gitea.event.head_commit.sha}}](${{gitea.event.head_commit.url}})" -a "./build/libs"
|
||||||
echo "${{gitea.event.head_commit.sha}}"
|
|
||||||
echo "${{gitea.event.head_commit.url}}"
|
|
||||||
echo "${{gitea.event.head_commit.message}}"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1 +1,3 @@
|
|||||||
# com.mingliqiye.gitea.releases
|
# com.mingliqiye.gitea.releases
|
||||||
|
|
||||||
|
- [a](666)
|
139
build.gradle
139
build.gradle
@ -1,19 +1,154 @@
|
|||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id 'idea'
|
||||||
|
id 'com.github.johnrengelman.shadow' version '8.1.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.mingliqiye.gitea.releases'
|
String jarNameStr = "${groups}-${versions}"
|
||||||
version = '1.0-SNAPSHOT'
|
String jarName = "${jarNameStr}.jar"
|
||||||
|
|
||||||
|
group = groups
|
||||||
|
version = versions
|
||||||
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
maven { url 'https://maven.aliyun.com/repository/google' }
|
||||||
|
maven { url 'https://maven.aliyun.com/repository/central' }
|
||||||
|
maven { url 'https://maven.aliyun.com/repository/public' }
|
||||||
|
maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
|
||||||
|
maven { url "https://maven.aliyun.com/repository/spring-plugin" }
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.36'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok:1.18.36'
|
||||||
|
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.16'
|
||||||
|
implementation 'ch.qos.logback:logback-classic:1.5.16'
|
||||||
|
implementation 'org.slf4j:slf4j-api:2.0.16'
|
||||||
|
implementation 'args4j:args4j:2.37'
|
||||||
|
implementation 'com.alibaba.fastjson2:fastjson2:2.0.57'
|
||||||
|
implementation 'commons-cli:commons-cli:1.9.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.generateHash = { file, ads ->
|
||||||
|
MessageDigest md = MessageDigest.getInstance(ads)
|
||||||
|
file.eachByte(4096) { bytes, size ->
|
||||||
|
md.update(bytes, 0x00, size)
|
||||||
|
}
|
||||||
|
return md.digest().encodeHex().toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.getHash = {
|
||||||
|
File file ->
|
||||||
|
{
|
||||||
|
def path = rootDir.toPath().resolve("build").resolve("libs").toString()
|
||||||
|
String md5 = generateHash(file, "MD5")
|
||||||
|
String sha1 = generateHash(file, "SHA-1")
|
||||||
|
String sha256 = generateHash(file, "SHA-256")
|
||||||
|
File md5f = new File(path, file.getName() + ".MD5.txt")
|
||||||
|
File sha1f = new File(path, file.getName() + ".SHA1.txt")
|
||||||
|
File sha256f = new File(path, file.getName() + ".SHA256.txt")
|
||||||
|
md5f.text = md5
|
||||||
|
sha1f.text = sha1
|
||||||
|
sha256f.text = sha256
|
||||||
|
println ">>> 构建成功!"
|
||||||
|
println ">>> MD5: ${md5}"
|
||||||
|
println ">>> SHA1: ${sha1}"
|
||||||
|
println ">>> SHA256: ${sha256}"
|
||||||
|
println ">>> 输出文件: ${file.absolutePath}"
|
||||||
|
println ">>> 输出文件: ${md5f.absolutePath}"
|
||||||
|
println ">>> 输出文件: ${sha1f.absolutePath}"
|
||||||
|
println ">>> 输出文件: ${sha256f.absolutePath}"
|
||||||
|
println ">>> 文件大小: ${file.length() / 1024 / 1024} MB"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tasks.register("addfile", Copy) {
|
||||||
|
def path = rootDir.toPath().resolve("build").resolve("assets").toString()
|
||||||
|
from zipTree(tasks.shadowJar.archiveFile.get())
|
||||||
|
into path
|
||||||
|
dependsOn tasks.shadowJar
|
||||||
|
doFirst {
|
||||||
|
mkdir path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("zipsrc", Zip) {
|
||||||
|
def path = rootDir.toPath().resolve("build").resolve("libs").resolve(jarNameStr).toString()
|
||||||
|
def pathsource = rootDir.toPath().resolve("src").resolve("main").resolve('java').toString()
|
||||||
|
def pathresources = rootDir.toPath().resolve("src").resolve("main").resolve('resources').toString()
|
||||||
|
archiveFileName = path + ".source.jar"
|
||||||
|
entryCompression = ZipEntryCompression.DEFLATED
|
||||||
|
from 'LICENSE' into '.'
|
||||||
|
from 'README.md' into '.'
|
||||||
|
from fileTree(pathresources) into '.'
|
||||||
|
from fileTree(pathsource) into '.'
|
||||||
|
doLast {
|
||||||
|
getHash(new File(path + ".source.jar"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("zipJar", Zip) {
|
||||||
|
def path = rootDir.toPath().resolve("build").resolve("libs").toString()
|
||||||
|
def jarpath = rootDir.toPath().resolve("build").resolve("libs").resolve(jarName).toString()
|
||||||
|
def assetspath = rootDir.toPath().resolve("build").resolve("assets").toString()
|
||||||
|
delete fileTree(path)
|
||||||
|
archiveFileName = jarpath
|
||||||
|
entryCompression = ZipEntryCompression.DEFLATED
|
||||||
|
from fileTree(assetspath) into '.'
|
||||||
|
from 'LICENSE' into '.'
|
||||||
|
from 'README.md' into '.'
|
||||||
|
dependsOn tasks.addfile
|
||||||
|
dependsOn tasks.zipsrc
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("build-jar") {
|
||||||
|
def path = rootDir.toPath().resolve("build").resolve("libs")
|
||||||
|
def pathassets = rootDir.toPath().resolve("build").resolve("assets").toString()
|
||||||
|
|
||||||
|
delete fileTree(path.toString())
|
||||||
|
dependsOn tasks.zipJar
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
getHash(path.resolve(jarName).toFile())
|
||||||
|
delete pathassets
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shadowJar {
|
||||||
|
archiveFileName = jarName
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||||
|
minimize()
|
||||||
|
manifest {
|
||||||
|
attributes 'Main-Class': maimClassStr
|
||||||
|
attributes 'Implementation-Title': groups
|
||||||
|
attributes 'Implementation-Version': versions
|
||||||
|
attributes 'Email': 'minglipro@163.com'
|
||||||
|
attributes 'Implementation-Vendor': 'minglipro|Armamem0t'
|
||||||
|
attributes 'Copyright': copyright
|
||||||
|
attributes 'Env': 'prod'
|
||||||
|
attributes 'LICENSE': 'Apache License 2.0'
|
||||||
|
attributes 'Created': createdTime
|
||||||
|
attributes 'Updated': new Date().format('yyyy-MM-dd HH:mm:ss')
|
||||||
|
}
|
||||||
|
from {
|
||||||
|
project.configurations.runtimeClasspath.collect {
|
||||||
|
it.isDirectory() ? it : zipTree(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exclude '**/LICENSE'
|
||||||
|
exclude '**/LICENSE.*'
|
||||||
|
exclude '**/NOTICE.*'
|
||||||
}
|
}
|
6
gradle.properties
Normal file
6
gradle.properties
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
groups=com.mingliqiye.gitea.releases
|
||||||
|
versions=1.0
|
||||||
|
maimClassStr=com.mingliqiye.gitea.releases.Main
|
||||||
|
copyright=Copyright 2026 @minglipro|Armamem0t All rights reserved.
|
||||||
|
createdTime=2025-06-18 13:05:06
|
||||||
|
systemProp.file.encoding=UTF-8
|
@ -1,17 +1,135 @@
|
|||||||
package com.mingliqiye.gitea.releases;
|
package com.mingliqiye.gitea.releases;
|
||||||
|
|
||||||
// TIP 要<b>运行</b>代码,请按 <shortcut actionId="Run"/> 或
|
import com.mingliqiye.gitea.releases.entitys.Attachment;
|
||||||
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
|
import com.mingliqiye.gitea.releases.entitys.CreateReleaseOption;
|
||||||
public class Main {
|
import com.mingliqiye.gitea.releases.entitys.Release;
|
||||||
public static void main(String[] args) {
|
import com.mingliqiye.gitea.releases.entitys.StringKeyValue;
|
||||||
// TIP 当文本光标位于高亮显示的文本处时按 <shortcut actionId="ShowIntentionActions"/>
|
import com.mingliqiye.gitea.releases.http.HttpRelease;
|
||||||
// 查看 IntelliJ IDEA 建议如何修正。
|
import com.mingliqiye.libs.meta.ManifestReader;
|
||||||
System.out.printf("Hello and welcome!");
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.cli.*;
|
||||||
|
|
||||||
for (int i = 1; i <= 5; i++) {
|
import java.io.File;
|
||||||
// TIP 按 <shortcut actionId="Debug"/> 开始调试代码。我们已经设置了一个 <icon src="AllIcons.Debugger.Db_set_breakpoint"/> 断点
|
import java.util.ArrayList;
|
||||||
// 但您始终可以通过按 <shortcut actionId="ToggleLineBreakpoint"/> 添加更多断点。
|
import java.util.Arrays;
|
||||||
System.out.println("i = " + i);
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Main {
|
||||||
|
public static CommandLine cmd;
|
||||||
|
public static List<File> files = new ArrayList<>();
|
||||||
|
|
||||||
|
public static void getFiles(File file) {
|
||||||
|
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
log.info("search directory {}", file.getAbsolutePath());
|
||||||
|
Arrays.stream(file.listFiles()).forEach(Main::getFiles);
|
||||||
|
} else {
|
||||||
|
if (file.exists()) {
|
||||||
|
files.add(file);
|
||||||
|
} else {
|
||||||
|
log.warn("file not found {}", file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
log.info("search file {} add.", file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
init(args);
|
||||||
|
Arrays.stream(cmd.getOptionValues("add-path")).forEach(s -> getFiles(new File(s)));
|
||||||
|
String token = cmd.getOptionValue("token", () -> null);
|
||||||
|
String serverUrl = cmd.getOptionValue("server-url", () -> null);
|
||||||
|
String repositoryOwner = cmd.getOptionValue("repository-owner", () -> null);
|
||||||
|
String repositoryName = cmd.getOptionValue("repository-name", () -> null);
|
||||||
|
String title = cmd.getOptionValue("title", () -> null);
|
||||||
|
String body = cmd.getOptionValue("body", () -> null);
|
||||||
|
String tagName = cmd.getOptionValue("tag-name", () -> null);
|
||||||
|
String targetCommitish = cmd.getOptionValue("target-commitish", () -> null);
|
||||||
|
Boolean preRelease = Boolean.getBoolean(cmd.getOptionValue("pre-release", "false"));
|
||||||
|
Boolean draft = Boolean.getBoolean(cmd.getOptionValue("draft", "false"));
|
||||||
|
CreateReleaseOption createReleaseOption = new CreateReleaseOption();
|
||||||
|
createReleaseOption.setName(title);
|
||||||
|
createReleaseOption.setBody(body);
|
||||||
|
createReleaseOption.setTag_name(tagName);
|
||||||
|
createReleaseOption.setTarget_commitish(targetCommitish);
|
||||||
|
createReleaseOption.setPrerelease(preRelease);
|
||||||
|
createReleaseOption.setDraft(draft);
|
||||||
|
StringKeyValue authorization = new StringKeyValue("Authorization", "token " + token);
|
||||||
|
Release release = HttpRelease.createARelease(
|
||||||
|
serverUrl, repositoryOwner, repositoryName, createReleaseOption, authorization);
|
||||||
|
if (release == null) {
|
||||||
|
log.error("release is null");
|
||||||
|
exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("release is {}", release);
|
||||||
|
for (int i = 1; i <= files.size(); i++) {
|
||||||
|
File file = files.get(i - 1);
|
||||||
|
log.info("{}/{} -> uploading file {}", i, files.size(), file.getAbsolutePath());
|
||||||
|
Attachment attachment = HttpRelease.createAReleaseAttachment(
|
||||||
|
serverUrl, repositoryOwner, repositoryName, release.getId(), file.getName(), file, authorization);
|
||||||
|
if (attachment == null) {
|
||||||
|
log.error("attachment is null : file {}", file.getAbsolutePath());
|
||||||
|
exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void exit(Integer code) {
|
||||||
|
if (code == null) {
|
||||||
|
code = 1;
|
||||||
|
}
|
||||||
|
log.info("System exit by code: {}", code);
|
||||||
|
System.exit(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(String[] args) {
|
||||||
|
|
||||||
|
Options options = new Options();
|
||||||
|
Option help = new Option("h", "help", false, "显示帮助信息");
|
||||||
|
Option info = new Option("i", "info", false, "显示帮助信息");
|
||||||
|
Option token = new Option("t", "token", true, "token 不 包含 前缀的token");
|
||||||
|
Option repositoryOwner = new Option("o", "repository-owner", true, "团队名");
|
||||||
|
Option repositoryName = new Option("r", "repository-name", true, "仓库名");
|
||||||
|
Option title = new Option("ti", "title", true, "releases的标题");
|
||||||
|
Option body = new Option("b", "body", true, "releases的描述");
|
||||||
|
Option serverUrl = new Option("s", "server-url", true, "服务器url");
|
||||||
|
Option tagName = new Option("tn", "tag-name", true, "标签名");
|
||||||
|
Option targetCommitish = new Option("tc", "target-commitish", true, "提交版本");
|
||||||
|
Option preRelease = new Option("p", "pre-release", true, "是否为预发布");
|
||||||
|
Option draft = new Option("d", "draft", true, "是否为草稿");
|
||||||
|
Option addPath = new Option("a", "add-path", true, "添加文件和目录 目录下的所有文件都会加入到 releases 包括递归子目录");
|
||||||
|
options.addOption(help);
|
||||||
|
options.addOption(info);
|
||||||
|
options.addOption(token);
|
||||||
|
options.addOption(repositoryOwner);
|
||||||
|
options.addOption(repositoryName);
|
||||||
|
options.addOption(title);
|
||||||
|
options.addOption(body);
|
||||||
|
options.addOption(serverUrl);
|
||||||
|
options.addOption(tagName);
|
||||||
|
options.addOption(targetCommitish);
|
||||||
|
options.addOption(preRelease);
|
||||||
|
options.addOption(draft);
|
||||||
|
options.addOption(addPath);
|
||||||
|
CommandLineParser parser = new DefaultParser();
|
||||||
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
|
try {
|
||||||
|
cmd = parser.parse(options, args);
|
||||||
|
if (cmd.hasOption("h")) {
|
||||||
|
formatter.printHelp(" ", options);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (cmd.hasOption("i")) {
|
||||||
|
ManifestReader.getManifestData().properties().forEach(i -> {
|
||||||
|
System.out.println(i.getKey() + " : " + i.getValue());
|
||||||
|
});
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.entitys;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Attachment {
|
||||||
|
private String browser_download_url;
|
||||||
|
private String created_at;
|
||||||
|
private String download_count;
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String size;
|
||||||
|
private String uuid;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.entitys;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class CreateReleaseOption {
|
||||||
|
private String body;
|
||||||
|
private boolean draft = false;
|
||||||
|
private String name;
|
||||||
|
private boolean prerelease = false;
|
||||||
|
private String tag_name;
|
||||||
|
private String target_commitish;
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.entitys;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@Data
|
||||||
|
public class KeyValue<T> {
|
||||||
|
private String key;
|
||||||
|
private T value;
|
||||||
|
|
||||||
|
public static <K> KeyValue<K> of(String key, K value) {
|
||||||
|
return new KeyValue<>(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <K> KeyValue<K> of() {
|
||||||
|
return new KeyValue<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyValue() {}
|
||||||
|
|
||||||
|
public KeyValue(String key, T value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.entitys;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Release {
|
||||||
|
private Attachment[] assets;
|
||||||
|
private User author;
|
||||||
|
private String body;
|
||||||
|
private String created_at;
|
||||||
|
private Boolean draft;
|
||||||
|
private String html_url;
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Boolean prerelease;
|
||||||
|
private String published_at;
|
||||||
|
private String tag_name;
|
||||||
|
private String tarball_url;
|
||||||
|
private String target_commitish;
|
||||||
|
private String upload_url;
|
||||||
|
private String url;
|
||||||
|
private String zipball_url;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.entitys;
|
||||||
|
|
||||||
|
public class StringKeyValue extends KeyValue<String> {
|
||||||
|
|
||||||
|
public StringKeyValue(String key, String value) {
|
||||||
|
super(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringKeyValue() {}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.entitys;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class User {
|
||||||
|
private Boolean active;
|
||||||
|
private String avatar_url;
|
||||||
|
private String created;
|
||||||
|
private String description;
|
||||||
|
private String email;
|
||||||
|
private Long followers_count;
|
||||||
|
private Long following_count;
|
||||||
|
private String full_name;
|
||||||
|
private String html_url;
|
||||||
|
private Long id;
|
||||||
|
private Boolean is_admin;
|
||||||
|
private String language;
|
||||||
|
private String last_login;
|
||||||
|
private String location;
|
||||||
|
private String login;
|
||||||
|
private String login_name;
|
||||||
|
private Boolean prohibit_login;
|
||||||
|
private Boolean restricted;
|
||||||
|
private Long source_id;
|
||||||
|
private Long starred_repos_count;
|
||||||
|
private String visibility;
|
||||||
|
private String website;
|
||||||
|
}
|
@ -0,0 +1,122 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.http;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.mingliqiye.gitea.releases.entitys.Attachment;
|
||||||
|
import com.mingliqiye.gitea.releases.entitys.CreateReleaseOption;
|
||||||
|
import com.mingliqiye.gitea.releases.entitys.Release;
|
||||||
|
import com.mingliqiye.gitea.releases.entitys.StringKeyValue;
|
||||||
|
import com.mingliqiye.gitea.releases.utils.StringUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class HttpRelease {
|
||||||
|
public static OkHttpClient client = new OkHttpClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建releasesApi<p>
|
||||||
|
* create release api<p>
|
||||||
|
* {baseurl}/{owner}/{repo}<p>
|
||||||
|
* https://git.mingliqiye.com/Actions/com.mingliqiye.gitea.releases/<p>
|
||||||
|
* 注意: 创建release 不包含附件<p>
|
||||||
|
* Note: Creating a release does not include attachments.<p>
|
||||||
|
* api 地址 https://docs.gitea.com/zh-cn/api/#tag/repository/operation/repoCreateRelease<p>
|
||||||
|
* api url https://docs.gitea.com/api/#tag/repository/operation/repoCreateRelease
|
||||||
|
* @param baseurl http://your.gitea.url 你的gitea地址 your gitea url
|
||||||
|
* @param owner 所属组织 organization
|
||||||
|
* @param repo 仓库名 repertoty
|
||||||
|
* @param createReleaseOption 创建发布选项 create release option
|
||||||
|
* @see Release
|
||||||
|
* @see CreateReleaseOption
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static Release createARelease(
|
||||||
|
String baseurl,
|
||||||
|
String owner,
|
||||||
|
String repo,
|
||||||
|
CreateReleaseOption createReleaseOption,
|
||||||
|
StringKeyValue authorization) {
|
||||||
|
String url = StringUtils.format("{}/api/v1/repos/{}/{}/releases", baseurl, owner, repo);
|
||||||
|
MediaType json = MediaType.parse("application/json; charset=utf-8");
|
||||||
|
log.info("{}", createReleaseOption);
|
||||||
|
String jsondata = JSON.toJSONString(createReleaseOption);
|
||||||
|
RequestBody body = RequestBody.create(jsondata, json);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader(authorization.getKey(), authorization.getValue())
|
||||||
|
.post(body)
|
||||||
|
.build();
|
||||||
|
try {
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
log.info("CreateReleaseOK");
|
||||||
|
return JSON.parseObject(response.body().string(), Release.class);
|
||||||
|
} else {
|
||||||
|
log.error("CreateReleaseFailed");
|
||||||
|
log.error("Response.body:{}", response.body().string());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Attachment createAReleaseAttachment(
|
||||||
|
String baseurl,
|
||||||
|
String owner,
|
||||||
|
String repo,
|
||||||
|
Long id,
|
||||||
|
String name,
|
||||||
|
File attachment,
|
||||||
|
StringKeyValue authorization) {
|
||||||
|
String url = StringUtils.format("{}/api/v1/repos/{}/{}/releases/{}/assets", baseurl, owner, repo, id);
|
||||||
|
|
||||||
|
if (attachment == null) {
|
||||||
|
log.error("{}:{}", "attachment", "is a NullPointer");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
log.info("ReleaseAttachment start {}", attachment.getAbsolutePath());
|
||||||
|
if (!attachment.exists()) {
|
||||||
|
log.error("{}:{}", attachment.getAbsolutePath(), "is not exist");
|
||||||
|
return null;
|
||||||
|
} else if (!attachment.isFile()) {
|
||||||
|
log.error("{}:{}", attachment.getAbsolutePath(), "is not a file");
|
||||||
|
return null;
|
||||||
|
} else if (!attachment.canRead()) {
|
||||||
|
log.error("{}:{}", attachment.getAbsolutePath(), "permission denied can't read");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RequestBody formBody = new MultipartBody.Builder()
|
||||||
|
.setType(MultipartBody.FORM)
|
||||||
|
.addFormDataPart("name", name)
|
||||||
|
.addFormDataPart(
|
||||||
|
"attachment",
|
||||||
|
attachment.getName(),
|
||||||
|
RequestBody.create(attachment, MediaType.parse("multipart/form-data")))
|
||||||
|
.build();
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader(authorization.getKey(), authorization.getValue())
|
||||||
|
.post(formBody)
|
||||||
|
.build();
|
||||||
|
try {
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
log.info("ReleaseAttachment {} OK", attachment.getAbsolutePath());
|
||||||
|
return JSON.parseObject(response.body().string(), Attachment.class);
|
||||||
|
} else {
|
||||||
|
log.error("ReleaseAttachment {} Failed", attachment.getAbsolutePath());
|
||||||
|
log.error("Response.body:{}", response.body().string());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.mingliqiye.gitea.releases.utils;
|
||||||
|
|
||||||
|
import org.slf4j.helpers.MessageFormatter;
|
||||||
|
|
||||||
|
public class StringUtils {
|
||||||
|
public static String format(String str, Object... args) {
|
||||||
|
return MessageFormatter.arrayFormat(str, args).getMessage();
|
||||||
|
}
|
||||||
|
}
|
97
src/main/java/com/mingliqiye/libs/meta/ManifestReader.java
Normal file
97
src/main/java/com/mingliqiye/libs/meta/ManifestReader.java
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
package com.mingliqiye.libs.meta;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.jar.Manifest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取本 jar 的 Manifest 文件
|
||||||
|
* @see com.mingliqiye.libs.meta.ManifestReader
|
||||||
|
* com.mingliqiye.libs.Main
|
||||||
|
* @author MingLiPro|Armamem0t
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public final class ManifestReader {
|
||||||
|
|
||||||
|
private static final Manifest manifest = readManifest();
|
||||||
|
private static final ManifestData manifestData = new ManifestData(manifest);
|
||||||
|
|
||||||
|
public static ManifestData getManifestData() {
|
||||||
|
return ManifestReader.manifestData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class ManifestData {
|
||||||
|
|
||||||
|
private final Manifest manifest;
|
||||||
|
|
||||||
|
public ManifestData(Manifest manifest) {
|
||||||
|
this.manifest = manifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
if (manifest == null) return null;
|
||||||
|
return manifest.getMainAttributes().getValue("Implementation-Version");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCopyright() {
|
||||||
|
if (manifest == null) return null;
|
||||||
|
return manifest.getMainAttributes().getValue("Copyright");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVendor() {
|
||||||
|
if (manifest == null) return null;
|
||||||
|
return manifest.getMainAttributes().getValue("Implementation-Vendor");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
if (manifest == null) return null;
|
||||||
|
return manifest.getMainAttributes().getValue("Email");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
if (manifest == null) return null;
|
||||||
|
return manifest.getMainAttributes().getValue("Implementation-Title");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnv() {
|
||||||
|
if (manifest == null) return null;
|
||||||
|
return manifest.getMainAttributes().getValue("Env");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMainClass() {
|
||||||
|
if (manifest == null) return null;
|
||||||
|
return manifest.getMainAttributes().getValue("Main-Class");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDevelopment() {
|
||||||
|
String env = null;
|
||||||
|
if (manifest == null && (env = manifest.getMainAttributes().getValue("Env")) == null) return true;
|
||||||
|
|
||||||
|
if (env == null) return true;
|
||||||
|
return !env.equals("prod");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Map.Entry<Object, Object>> properties() {
|
||||||
|
if (manifest == null) return new HashSet<>();
|
||||||
|
return manifest.getMainAttributes().entrySet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Manifest readManifest() {
|
||||||
|
try {
|
||||||
|
URL jarUrl = ManifestReader.class.getResource("/META-INF/MANIFEST.MF");
|
||||||
|
if (jarUrl != null) {
|
||||||
|
return new Manifest(jarUrl.openStream());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
src/main/resources/logback.xml
Normal file
29
src/main/resources/logback.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%boldYellow(%d{yyyy-MM-dd HH:mm:ss.SSS}) %highlight([%level]) %boldMagenta([%thread/%logger{0}]) %highlight(%msg%n)</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<!--
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -> %msg%n</pattern>
|
||||||
|
<charset>utf-8</charset>
|
||||||
|
</encoder>
|
||||||
|
<file>log/output.log</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||||
|
<fileNamePattern>log/output.log.%i</fileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
|
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||||
|
<MaxFileSize>1MB</MaxFileSize>
|
||||||
|
</triggeringPolicy>
|
||||||
|
</appender>
|
||||||
|
-->
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<!--
|
||||||
|
<appender-ref ref="FILE" />
|
||||||
|
-->
|
||||||
|
</root>
|
||||||
|
</configuration>
|
Loading…
x
Reference in New Issue
Block a user