Skip to content

Commit

Permalink
Merge pull request #152 from Lixuhuilll/version-show-commit
Browse files Browse the repository at this point in the history
/version 接口返回值返回编译时对应的 commit 的 abbreviatedId 以及 dateTime
  • Loading branch information
dragove authored Dec 13, 2023
2 parents 6919a6d + 9a96506 commit 72aa329
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
Expand All @@ -6,6 +8,7 @@ plugins {
id 'org.springdoc.openapi-gradle-plugin' version '1.8.0'
id 'org.hidetake.swagger.generator' version '2.19.2'
// id 'org.graalvm.buildtools.native' version '0.9.28'
id 'org.ajoberstar.grgit' version '5.2.1'
}

group 'plus.maa'
Expand Down Expand Up @@ -126,4 +129,20 @@ rootProject.afterEvaluate(){
forkedSpringBootRun.configure {
doNotTrackState("See https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/102")
}
}
}

// 配置资源文件拷贝任务
processResources {
// 获取当前 commit
def commit = grgit?.head()
// 替换配置文件中的占位符
filesMatching(['**/*.properties', '**/*.yml', '**/*.yaml']) { file ->
{
file.filter(ReplaceTokens, tokens: [
// commit 不存在时,填充空字符串
'commitAbbreviatedId': commit?.abbreviatedId ?: '',
'commitDateTime' : commit?.dateTime?.toString() ?: ''
])
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/plus/maa/backend/config/external/Commit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package plus.maa.backend.config.external;

import lombok.Data;

import java.time.ZonedDateTime;

@Data
public class Commit {
private String abbreviatedId;
private ZonedDateTime dateTime;
}
4 changes: 4 additions & 0 deletions src/main/java/plus/maa/backend/config/external/Info.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package plus.maa.backend.config.external;

import org.springframework.boot.context.properties.NestedConfigurationProperty;

@lombok.Data
public class Info {
private String title;
private String description;
private String version;
private String domain;
private String frontendDomain;
@NestedConfigurationProperty
private Commit commit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public MaaResult<MaaSystemInfo> getSystemVersion() {
systemInfo.setTitle(info.getTitle());
systemInfo.setDescription(info.getDescription());
systemInfo.setVersion(info.getVersion());
systemInfo.setCommit(info.getCommit());
return MaaResult.success(systemInfo);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package plus.maa.backend.controller.response;

import lombok.Data;
import plus.maa.backend.config.external.Commit;

/**
* @author AnselYuki
Expand All @@ -10,4 +11,5 @@ public class MaaSystemInfo {
private String title;
private String description;
private String version;
private Commit commit;
}
9 changes: 8 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ logging:
logback:
rollingpolicy:
max-history: 14
clean-history-on-start: true
clean-history-on-start: true

maa-copilot:
info:
# 这几个参数应在编译时生成,不宜修改
commit:
abbreviated-id: @commitAbbreviatedId@
date-time: @commitDateTime@

0 comments on commit 72aa329

Please sign in to comment.