Integrate build version in UI (#629)

This commit is contained in:
WithoutPants
2020-06-23 09:51:57 +10:00
committed by GitHub
parent aa57b75243
commit 534d47500b
3 changed files with 45 additions and 22 deletions

View File

@@ -1,14 +1,27 @@
ifeq ($(OS),Windows_NT) IS_WIN =
ifeq (${SHELL}, sh.exe)
IS_WIN = true
endif
ifeq (${SHELL}, cmd)
IS_WIN = true
endif
ifdef IS_WIN
SEPARATOR := && SEPARATOR := &&
SET := set SET := set
else
SEPARATOR := ;
SET := export
endif endif
release: generate ui build release: generate ui build
build: pre-build:
$(eval DATE := $(shell go run scripts/getDate.go)) $(eval DATE := $(shell go run scripts/getDate.go))
$(eval GITHASH := $(shell git rev-parse --short HEAD)) $(eval GITHASH := $(shell git rev-parse --short HEAD))
$(eval STASH_VERSION := $(shell git describe --tags --exclude latest_develop)) $(eval STASH_VERSION := $(shell git describe --tags --exclude latest_develop))
build: pre-build
$(SET) CGO_ENABLED=1 $(SEPARATOR) go build -mod=vendor -v -ldflags "-X 'github.com/stashapp/stash/pkg/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$(DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)'" $(SET) CGO_ENABLED=1 $(SEPARATOR) go build -mod=vendor -v -ldflags "-X 'github.com/stashapp/stash/pkg/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$(DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)'"
install: install:
@@ -59,10 +72,19 @@ pre-ui:
cd ui/v2.5 && yarn install --frozen-lockfile cd ui/v2.5 && yarn install --frozen-lockfile
.PHONY: ui .PHONY: ui
ui: ui: pre-build
$(SET) REACT_APP_DATE="$(DATE)" $(SEPARATOR) \
$(SET) REACT_APP_GITHASH=$(GITHASH) $(SEPARATOR) \
$(SET) REACT_APP_STASH_VERSION=$(STASH_VERSION) $(SEPARATOR) \
cd ui/v2.5 && yarn build cd ui/v2.5 && yarn build
packr2 packr2
ui-start: pre-build
$(SET) REACT_APP_DATE="$(DATE)" $(SEPARATOR) \
$(SET) REACT_APP_GITHASH=$(GITHASH) $(SEPARATOR) \
$(SET) REACT_APP_STASH_VERSION=$(STASH_VERSION) $(SEPARATOR) \
cd ui/v2.5 && yarn start
fmt-ui: fmt-ui:
cd ui/v2.5 && yarn format cd ui/v2.5 && yarn format

View File

@@ -6,6 +6,14 @@ import { V010, V011, V020, V021, V030 } from "./versions";
const Changelog: React.FC = () => { const Changelog: React.FC = () => {
const [{ data, loading }, setOpenState] = useChangelogStorage(); const [{ data, loading }, setOpenState] = useChangelogStorage();
const stashVersion = process.env.REACT_APP_STASH_VERSION;
const buildTime = process.env.REACT_APP_DATE;
let buildDate;
if (buildTime) {
buildDate = buildTime.substring(0, buildTime.indexOf(" "));
}
if (loading) return <></>; if (loading) return <></>;
const openState = data?.versions ?? {}; const openState = data?.versions ?? {};
@@ -22,7 +30,8 @@ const Changelog: React.FC = () => {
<> <>
<h1 className="mb-4">Changelog:</h1> <h1 className="mb-4">Changelog:</h1>
<Version <Version
version="v0.3.0" version={stashVersion || "v0.3.0"}
date={buildDate}
openState={openState} openState={openState}
setOpenState={setVersionOpenState} setOpenState={setVersionOpenState}
defaultOpen defaultOpen

View File

@@ -1,10 +1,13 @@
import React from "react"; import React from "react";
import { Button, Table } from "react-bootstrap"; import { Button, Table } from "react-bootstrap";
import { LoadingIndicator } from "src/components/Shared"; import { LoadingIndicator } from "src/components/Shared";
import { useVersion, useLatestVersion } from "src/core/StashService"; import { useLatestVersion } from "src/core/StashService";
export const SettingsAboutPanel: React.FC = () => { export const SettingsAboutPanel: React.FC = () => {
const { data, error, loading } = useVersion(); const gitHash = process.env.REACT_APP_GITHASH;
const stashVersion = process.env.REACT_APP_STASH_VERSION;
const buildTime = process.env.REACT_APP_DATE;
const { const {
data: dataLatest, data: dataLatest,
error: errorLatest, error: errorLatest,
@@ -14,13 +17,13 @@ export const SettingsAboutPanel: React.FC = () => {
} = useLatestVersion(); } = useLatestVersion();
function maybeRenderTag() { function maybeRenderTag() {
if (!data || !data.version || !data.version.version) { if (!stashVersion) {
return; return;
} }
return ( return (
<tr> <tr>
<td>Version:</td> <td>Version:</td>
<td>{data.version.version}</td> <td>{stashVersion}</td>
</tr> </tr>
); );
} }
@@ -32,11 +35,8 @@ export const SettingsAboutPanel: React.FC = () => {
) { ) {
return; return;
} }
if (!data || !data.version || !data.version.hash) {
return <>{dataLatest.latestversion.shorthash}</>;
}
if (data.version.hash !== dataLatest.latestversion.shorthash) { if (gitHash !== dataLatest.latestversion.shorthash) {
return ( return (
<> <>
<strong>{dataLatest.latestversion.shorthash} [NEW] </strong> <strong>{dataLatest.latestversion.shorthash} [NEW] </strong>
@@ -49,9 +49,6 @@ export const SettingsAboutPanel: React.FC = () => {
} }
function renderLatestVersion() { function renderLatestVersion() {
if (!data || !data.version || !data.version.version) {
return;
} // if there is no "version" latest version check is obviously not supported
return ( return (
<Table> <Table>
<tbody> <tbody>
@@ -70,9 +67,6 @@ export const SettingsAboutPanel: React.FC = () => {
} }
function renderVersion() { function renderVersion() {
if (!data || !data.version) {
return;
}
return ( return (
<> <>
<Table> <Table>
@@ -80,11 +74,11 @@ export const SettingsAboutPanel: React.FC = () => {
{maybeRenderTag()} {maybeRenderTag()}
<tr> <tr>
<td>Build hash:</td> <td>Build hash:</td>
<td>{data.version.hash}</td> <td>{gitHash}</td>
</tr> </tr>
<tr> <tr>
<td>Build time:</td> <td>Build time:</td>
<td>{data.version.build_time}</td> <td>{buildTime}</td>
</tr> </tr>
</tbody> </tbody>
</Table> </Table>
@@ -148,8 +142,6 @@ export const SettingsAboutPanel: React.FC = () => {
</tr> </tr>
</tbody> </tbody>
</Table> </Table>
{!data || loading ? <LoadingIndicator inline /> : ""}
{error && <span>{error.message}</span>}
{errorLatest && <span>{errorLatest.message}</span>} {errorLatest && <span>{errorLatest.message}</span>}
{renderVersion()} {renderVersion()}
{!dataLatest || loadingLatest || networkStatus === 4 ? ( {!dataLatest || loadingLatest || networkStatus === 4 ? (