feat: add version page

This commit is contained in:
MiniDigger | Martin 2022-11-05 12:22:53 +01:00
parent 3bc9df8afe
commit 8919c48f31
10 changed files with 96 additions and 75 deletions

View File

@ -319,7 +319,7 @@
<verbose>false</verbose>
<dateFormat>yyyy-MM-dd-HH:mm:ss</dateFormat>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>false</generateGitPropertiesFile>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
</configuration>
</plugin>
</plugins>

View File

@ -17,7 +17,6 @@ import java.util.List;
public class HangarConfig {
private String logo = "https://docs.papermc.io/img/paper.png";
private String service = "Hangar";
private List<Sponsor> sponsors;
private boolean dev = true;
@ -119,14 +118,6 @@ public class HangarConfig {
this.logo = logo;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
public List<Sponsor> getSponsors() {
return sponsors;
}

View File

@ -1,33 +1,18 @@
package io.papermc.hangar.controller;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.papermc.hangar.HangarComponent;
import io.papermc.hangar.controller.extras.RobotsBuilder;
import io.papermc.hangar.controller.extras.StatusZ;
import io.papermc.hangar.security.annotations.Anyone;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import io.papermc.hangar.HangarComponent;
import io.papermc.hangar.controller.extras.RobotsBuilder;
import io.papermc.hangar.security.annotations.Anyone;
@Anyone
@Controller
public class ApplicationController extends HangarComponent {
private final StatusZ statusZ;
@Autowired
public ApplicationController(StatusZ statusZ) {
this.statusZ = statusZ;
}
@ResponseBody
@GetMapping("/statusz")
public ObjectNode showStatusZ() {
return statusZ.getStatus();
}
@GetMapping(path = "/robots.txt", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String robots() {
@ -45,7 +30,7 @@ public class ApplicationController extends HangarComponent {
.disallow("/admin")
.disallow("/actuator")
.disallow("/error")
.disallow("/statusz")
.disallow("/version-info")
.disallow("/api")
.allow("/api$")
.disallow("/notifications")

View File

@ -1,42 +0,0 @@
package io.papermc.hangar.controller.extras;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.papermc.hangar.config.hangar.HangarConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class StatusZ {
private final ObjectNode status;
private final String BUILD_NUM = "BUILD_NUMBER";
private final String GIT_BRANCH = "GIT_BRANCH";
private final String GIT_COMMIT = "GIT_COMMIT";
private final String JOB_NAME = "JOB_NAME";
private final String BUILD_TAG = "BUILD_TAG";
private final String HANGAR_ENV = "HANGAR_ENV";
private final String SERVICE = "SERVICE";
@Autowired
public StatusZ(HangarConfig hangarConfig, ObjectMapper mapper) {
status = mapper.createObjectNode();
status.set(BUILD_NUM, mapper.valueToTree(getEnv(BUILD_NUM)));
status.set(GIT_BRANCH, mapper.valueToTree(getEnv(GIT_BRANCH)));
status.set(GIT_COMMIT, mapper.valueToTree(getEnv(GIT_COMMIT)));
status.set(JOB_NAME, mapper.valueToTree(getEnv(JOB_NAME)));
status.set(BUILD_TAG, mapper.valueToTree(getEnv(BUILD_TAG)));
status.set(HANGAR_ENV, mapper.valueToTree(getEnv(HANGAR_ENV)));
status.set(SERVICE, mapper.valueToTree(hangarConfig.getService()));
}
public ObjectNode getStatus() {
return status;
}
private String getEnv(String key) {
return System.getenv().getOrDefault(key, "unknown");
}
}

View File

@ -25,6 +25,7 @@ import io.papermc.hangar.security.annotations.Anyone;
import io.papermc.hangar.security.annotations.ratelimit.RateLimit;
import io.papermc.hangar.service.internal.PlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.GitProperties;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@ -38,6 +39,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
@Controller
@ -49,12 +52,14 @@ public class BackendDataController {
private final ObjectMapper noJsonValueMapper;
private final HangarConfig config;
private final PlatformService platformService;
private final GitProperties gitProperties;
@Autowired
public BackendDataController(ObjectMapper mapper, HangarConfig config, PlatformService platformService) {
public BackendDataController(ObjectMapper mapper, HangarConfig config, PlatformService platformService, GitProperties gitProperties) {
this.config = config;
this.noJsonValueMapper = mapper.copy();
this.platformService = platformService;
this.gitProperties = gitProperties;
this.noJsonValueMapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
@Override
protected <A extends Annotation> A _findAnnotation(Annotated annotated, Class<A> annoClass) {
@ -182,6 +187,21 @@ public class BackendDataController {
return Prompt.getValues();
}
@ResponseBody
@GetMapping("/version-info")
public Map<String, String> info() {
return Map.of(
"version", gitProperties.get("build.version"),
"committer", gitProperties.get("commit.user.name"),
"time", gitProperties.get("commit.time"),
"commit", gitProperties.getCommitId(),
"commitShort", gitProperties.getShortCommitId(),
"message", gitProperties.get("commit.message.short"),
"tag", Optional.of(gitProperties.get("tags")).orElse(gitProperties.get("closest.tag.name")),
"behind", gitProperties.get("closest.tag.commit.count")
);
}
@GetMapping("/validations")
@Cacheable("validations")
public ResponseEntity<ObjectNode> getValidations() {

View File

@ -14,4 +14,4 @@
Hangar version @project.version@, running commit @git.commit.id.abbrev@, committed on @git.commit.time@
@git.commit.user.name@ <@git.commit.user.email@>: @git.commit.message.short@
Running Spring Boot @spring-boot.version@
Running Spring Boot ${spring-boot.version}

@ -1 +1 @@
Subproject commit ec51c259360015f4d905bbcb2b97c9a1ed55e7a4
Subproject commit 32e402d11c4eb6d9ca4077d2a9eba5d0c30471ac

View File

@ -1,5 +1,6 @@
<script lang="ts" setup>
import PageTitle from "~/lib/components/design/PageTitle.vue";
// TODO TOS
</script>
<template>

View File

@ -0,0 +1,52 @@
<script lang="ts" setup>
import PageTitle from "~/lib/components/design/PageTitle.vue";
import { useBackendDataStore } from "~/store/backendData";
import Link from "~/lib/components/design/Link.vue";
import Alert from "~/lib/components/design/Alert.vue";
import { useHead } from "@vueuse/head";
import { useSeo } from "~/composables/useSeo";
import { useRoute } from "vue-router";
const version = useBackendDataStore().versionInfo;
const route = useRoute();
useHead(useSeo("Hangar Version", null, route, null));
</script>
<template>
<PageTitle>Hangar Version</PageTitle>
<p mb="2">This instance is running <Link href="https://github.com/HangarMC/Hangar">Hangar</Link> {{ version.version }}</p>
<p mb="2">
The last commit was <Link :href="'https://github.com/HangarMC/Hangar/commit/' + version.commit">{{ version.commitShort }}</Link> by
<Link :href="'https://github.com/' + version.committer">{{ version.committer }}</Link> at {{ version.time }} with message: <br />
{{ version.message }}
</p>
<p mb="4">Last Tag: {{ version.tag }} ({{ version.behind || 0 }} commits since tag)</p>
<h2 class="text-xl mb-4 font-bold">Milestones</h2>
<p mb="2">The next development steps of Hangar have been set to the following milestones</p>
<ul class="list-disc list-inside">
<li mb="2">
<Link href="https://github.com/orgs/HangarMC/projects/1/views/10">Before Alpha</Link>: <br />
Once this is done, we will look for Alpha Testers on our Staging Instance on <Link href="https://hangar.papermc.dev">hangar.papermc.dev</Link>.<br />
At this point, DB resets are unlikely, but not impossible.
</li>
<li mb="2">
<Link href="https://github.com/orgs/HangarMC/projects/1/views/12">Before Beta</Link>: <br />
Once this is done, we will look for Beta Testers on our Prod Instance on <Link href="https://hangar.papermc.io">hangar.papermc.io</Link>.<br />
At this point we promise to no longer reset the DB, so you can upload all your plugins! Stuff might still be rough around the edges, so expect breakage,
please report any findings to our <Link href="https://github.com/HangarMC/Hangar/issues/new/choose">issue tracker</Link>!
</li>
<li mb="2">
<Link href="https://github.com/orgs/HangarMC/projects/1/views/14">During Beta</Link> we aim to fix all bugs and introduce a few new exiting features.
Hangar might be in this period for a while.
</li>
<li mb="2">
The <Link href="https://github.com/orgs/HangarMC/projects/1/views/16">Future</Link> is looking bright for Hangar, so this milestone captures all tasks
that we are interested in, but might be out of reach for a while for various reasons. But that should not stop you from suggesting new stuff!
</li>
</ul>
<p mt="2">You can see a graphical display of those milestones <Link href="https://github.com/orgs/HangarMC/projects/1/insights/2">here</Link>.</p>
<Alert mt="4">
Please remember, these are estimates, not promises, they can change at any time as the team shifts focus. Altho you can always speed up a particular task by
contributing!
</Alert>
</template>

View File

@ -15,6 +15,17 @@ interface Validation {
min?: number;
}
interface VersionInfo {
time: string;
commit: string;
commitShort: string;
version: string;
committer: string;
message: string;
tag: string;
behind: string;
}
interface Validations {
project: {
name: Validation;
@ -47,6 +58,7 @@ export const useBackendDataStore = defineStore("backendData", () => {
const globalRoles = ref<Role[]>([]);
const channelColors = ref<Color[]>([]);
const flagReasons = ref<FlagReason[]>([]);
const versionInfo = ref<VersionInfo>();
async function initBackendData() {
try {
@ -89,6 +101,7 @@ export const useBackendDataStore = defineStore("backendData", () => {
fetchIfNeeded(async () => useInternalApi("data/projectRoles", false), projectRoles),
fetchIfNeeded(async () => useInternalApi("data/globalRoles", false), globalRoles),
fetchIfNeeded(async () => useInternalApi("data/flagReasons", false), flagReasons),
fetchIfNeeded(async () => useInternalApi("data/version-info", false), versionInfo),
]);
} catch (e) {
console.error("ERROR FETCHING BACKEND DATA");
@ -123,6 +136,7 @@ export const useBackendDataStore = defineStore("backendData", () => {
visiblePlatforms,
licenseOptions,
categoryOptions,
versionInfo,
};
});