Merge pull request #110 from WithoutPants/version

Display hash and build time at startup and in about page
This commit is contained in:
Leopere 2019-10-23 23:49:27 -04:00 committed by GitHub
commit 1a28917870
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 92 additions and 8 deletions

View file

@ -4,7 +4,9 @@ ifeq ($(OS),Windows_NT)
endif
build:
$(SET) CGO_ENABLED=1 $(SEPARATOR) packr2 build -mod=vendor -v
$(eval DATE := $(shell go run scripts/getDate.go))
$(eval GITHASH := $(shell git rev-parse --short HEAD))
$(SET) CGO_ENABLED=1 $(SEPARATOR) go build -mod=vendor -v -ldflags "-X 'github.com/stashapp/stash/pkg/api.buildstamp=$(DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)'"
install:
packr2 install
@ -35,3 +37,4 @@ lint:
.PHONY: ui
ui:
cd ui/v2 && yarn build
packr2

View file

@ -52,4 +52,11 @@ query Stats {
studio_count,
tag_count
}
}
}
query Version {
version {
hash,
build_time
}
}

View file

@ -68,6 +68,9 @@ type Query {
allPerformers: [Performer!]!
allStudios: [Studio!]!
allTags: [Tag!]!
# Version
version: Version!
}
type Mutation {

View file

@ -0,0 +1,4 @@
type Version {
hash: String!
build_time: String!
}

View file

@ -2,10 +2,11 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scraper"
"sort"
"strconv"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scraper"
)
type Resolver struct{}
@ -104,6 +105,15 @@ func (r *queryResolver) Stats(ctx context.Context) (*models.StatsResultType, err
}, nil
}
func (r *queryResolver) Version(ctx context.Context) (*models.Version, error) {
hash, buildtime := GetVersion()
return &models.Version{
Hash: hash,
BuildTime: buildtime,
}, nil
}
// Get scene marker tags which show up under the video.
func (r *queryResolver) SceneMarkerTags(ctx context.Context, scene_id string) ([]*models.SceneMarkerTag, error) {
sceneID, _ := strconv.Atoi(scene_id)

View file

@ -27,6 +27,9 @@ import (
"github.com/stashapp/stash/pkg/utils"
)
var buildstamp string = ""
var githash string = ""
var uiBox *packr.Box
//var legacyUiBox *packr.Box
@ -197,6 +200,7 @@ func Start() {
}
go func() {
printVersion()
logger.Infof("stash is running on HTTPS at https://" + address + "/")
logger.Fatal(httpsServer.ListenAndServeTLS("", ""))
}()
@ -207,12 +211,21 @@ func Start() {
}
go func() {
printVersion()
logger.Infof("stash is running on HTTP at http://" + address + "/")
logger.Fatal(server.ListenAndServe())
}()
}
}
func printVersion() {
fmt.Printf("stash version: %s (%s)\n", githash, buildstamp)
}
func GetVersion() (string, string) {
return githash, buildstamp
}
func makeTLSConfig() *tls.Config {
cert, err := ioutil.ReadFile(paths.GetSSLCert())
if err != nil {

View file

@ -1,9 +1,13 @@
#!/bin/sh
DATE=`go run scripts/getDate.go`
GITHASH=`git rev-parse --short HEAD`
VERSION_FLAGS="-X 'github.com/stashapp/stash/pkg/api.buildstamp=$DATE' -X 'github.com/stashapp/stash/pkg/api.githash=$GITHASH'"
SETUP="export GO111MODULE=on; export CGO_ENABLED=1;"
WINDOWS="GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ packr2 build -o dist/stash-win.exe -ldflags \"-extldflags '-static'\" -tags extended -v -mod=vendor;"
DARWIN="GOOS=darwin GOARCH=amd64 CC=o64-clang CXX=o64-clang++ packr2 build -o dist/stash-osx -tags extended -v -mod=vendor;"
LINUX="packr2 build -o dist/stash-linux -v -mod=vendor;"
WINDOWS="GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ packr2 build -o dist/stash-win.exe -ldflags \"-extldflags '-static' $VERSION_FLAGS\" -tags extended -v -mod=vendor;"
DARWIN="GOOS=darwin GOARCH=amd64 CC=o64-clang CXX=o64-clang++ packr2 build -o dist/stash-osx -ldflags \"$VERSION_FLAGS\" -tags extended -v -mod=vendor;"
LINUX="packr2 build -o dist/stash-linux -ldflags \"$VERSION_FLAGS\" -v -mod=vendor;"
COMMAND="$SETUP $WINDOWS $DARWIN $LINUX"

12
scripts/getDate.go Normal file
View file

@ -0,0 +1,12 @@
// +build ignore
package main
import "fmt"
import "time"
func main() {
now := time.Now().Format("2006-01-02 15:04:05")
fmt.Printf("%s", now)
}

View file

@ -2,18 +2,45 @@ import {
H1,
H4,
H6,
HTMLTable,
Spinner,
Tag,
} from "@blueprintjs/core";
import React, { FunctionComponent } from "react";
import * as GQL from "../../core/generated-graphql";
import { TextUtils } from "../../utils/text";
import { StashService } from "../../core/StashService";
interface IProps {}
export const SettingsAboutPanel: FunctionComponent<IProps> = (props: IProps) => {
const { data, error, loading } = StashService.useVersion();
function renderVersion() {
if (!data || !data.version) { return; }
return (
<>
<HTMLTable>
<tbody>
<tr>
<td>Build hash:</td>
<td>{data.version.hash}</td>
</tr>
<tr>
<td>Build time:</td>
<td>{data.version.build_time}</td>
</tr>
</tbody>
</HTMLTable>
</>
);
}
return (
<>
About
<H4>About</H4>
{!data || loading ? <Spinner size={Spinner.SIZE_LARGE} /> : undefined}
{!!error ? <span>error.message</span> : undefined}
{renderVersion()}
</>
);
};

View file

@ -123,6 +123,7 @@ export class StashService {
return GQL.useValidGalleriesForScene({variables: {scene_id: sceneId}});
}
public static useStats() { return GQL.useStats(); }
public static useVersion() { return GQL.useVersion(); }
public static useConfiguration() { return GQL.useConfiguration(); }
public static useDirectories(path?: string) { return GQL.useDirectories({ variables: { path }}); }