From b2a1e5a5471fd045b5b754f0adcb344239686179 Mon Sep 17 00:00:00 2001 From: Fabian Vowie Date: Sun, 23 Jan 2022 17:43:56 +0100 Subject: [PATCH] Add commit hash to index metadata --- build.sh | 3 +++ main.go | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..77f3431 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +GIT_COMMIT=$(git rev-parse --short HEAD); go build -ldflags "-X main.GitCommit=$GIT_COMMIT" diff --git a/main.go b/main.go index 0191c1b..030aa5b 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,12 @@ import ( const Name string = "Lithium" const Version string = "0.1.0" +var GitCommit string + type Metadata struct { - Name string `json:"name"` - Version string `json:"version"` + Name string `json:"name"` + Version string `json:"version"` + CommitHash string `json:"commit_hash"` } func PipelineHandler(pipeline pipelines.IPipeline, storageProvider storage.IStorageProvider, w http.ResponseWriter, r *http.Request) { @@ -30,7 +33,7 @@ func PipelineHandler(pipeline pipelines.IPipeline, storageProvider storage.IStor func IndexHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(Metadata{Name, Version}) + err := json.NewEncoder(w).Encode(Metadata{Name, Version, GitCommit}) if err != nil { w.WriteHeader(http.StatusInternalServerError) }