diff --git a/Makefile b/Makefile index 582a6fa19..bdf15ab33 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/graphql/documents/queries/misc.graphql b/graphql/documents/queries/misc.graphql index d7990159a..3c1de2639 100644 --- a/graphql/documents/queries/misc.graphql +++ b/graphql/documents/queries/misc.graphql @@ -52,4 +52,11 @@ query Stats { studio_count, tag_count } -} \ No newline at end of file +} + +query Version { + version { + hash, + build_time + } +} diff --git a/graphql/schema/schema.graphql b/graphql/schema/schema.graphql index 466c406e3..b90b4bc75 100644 --- a/graphql/schema/schema.graphql +++ b/graphql/schema/schema.graphql @@ -68,6 +68,9 @@ type Query { allPerformers: [Performer!]! allStudios: [Studio!]! allTags: [Tag!]! + + # Version + version: Version! } type Mutation { diff --git a/graphql/schema/types/version.graphql b/graphql/schema/types/version.graphql new file mode 100644 index 000000000..79f9e4dab --- /dev/null +++ b/graphql/schema/types/version.graphql @@ -0,0 +1,4 @@ +type Version { + hash: String! + build_time: String! +} \ No newline at end of file diff --git a/pkg/api/resolver.go b/pkg/api/resolver.go index 451df1eef..2744cb322 100644 --- a/pkg/api/resolver.go +++ b/pkg/api/resolver.go @@ -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) diff --git a/pkg/api/server.go b/pkg/api/server.go index 1e2c12410..560f46e32 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -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 { diff --git a/scripts/cross-compile.sh b/scripts/cross-compile.sh index 2a1c8d863..6a1d6d45a 100755 --- a/scripts/cross-compile.sh +++ b/scripts/cross-compile.sh @@ -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" diff --git a/scripts/getDate.go b/scripts/getDate.go new file mode 100644 index 000000000..6afa863c2 --- /dev/null +++ b/scripts/getDate.go @@ -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) +} diff --git a/ui/v2/src/components/Settings/SettingsAboutPanel.tsx b/ui/v2/src/components/Settings/SettingsAboutPanel.tsx index d2d93ba60..f943ef345 100644 --- a/ui/v2/src/components/Settings/SettingsAboutPanel.tsx +++ b/ui/v2/src/components/Settings/SettingsAboutPanel.tsx @@ -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 = (props: IProps) => { + const { data, error, loading } = StashService.useVersion(); + + function renderVersion() { + if (!data || !data.version) { return; } + return ( + <> + + + + Build hash: + {data.version.hash} + + + Build time: + {data.version.build_time} + + + + + ); + } return ( <> - About +

About

+ {!data || loading ? : undefined} + {!!error ? error.message : undefined} + {renderVersion()} ); }; diff --git a/ui/v2/src/core/StashService.ts b/ui/v2/src/core/StashService.ts index 7943a96e3..110623ea7 100644 --- a/ui/v2/src/core/StashService.ts +++ b/ui/v2/src/core/StashService.ts @@ -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 }}); }