From 9251f164f1078fb255d0b6a843dbe3e3816c3ecc Mon Sep 17 00:00:00 2001 From: kaack Date: Fri, 21 Jul 2023 17:30:29 -0700 Subject: [PATCH] Use git information for AppInfo --- .github/workflows/windows-amd64.yaml | 2 +- pkg/proto/generated/pb/server.pb.go | 218 ++++++++---------- pkg/proto/server.proto | 8 +- pkg/server/generated/.gitignore | 1 + pkg/server/generated/version.json | 5 + pkg/server/server_grpc.go | 28 +-- pkg/server/version.go | 38 +++ .../build-release-zip}/build-release-zip.go | 7 +- .../generate-version-file.go | 185 +++++++++++++++ webapp/src/components/pages/AboutPage.jsx | 2 +- webapp/src/generated/server_pb.js | 96 ++------ 11 files changed, 364 insertions(+), 226 deletions(-) create mode 100644 pkg/server/generated/.gitignore create mode 100644 pkg/server/generated/version.json rename scripts/{ => cmd/build-release-zip}/build-release-zip.go (96%) create mode 100644 scripts/cmd/generate-version-file/generate-version-file.go diff --git a/.github/workflows/windows-amd64.yaml b/.github/workflows/windows-amd64.yaml index 9ee22cf..14ffb90 100644 --- a/.github/workflows/windows-amd64.yaml +++ b/.github/workflows/windows-amd64.yaml @@ -20,7 +20,7 @@ jobs: dir /a && go generate ./... && go build -trimpath -tags static -o elrs-joystick-control.exe .\cmd\elrs-joystick-control\. && - go run scripts\build-release-zip.go --location C:\app --prefix elrs-joystick-control --files *.exe,LICENSE* " + go run scripts\cmd\build-release-zip\build-release-zip.go --location C:\app --prefix elrs-joystick-control --files *.exe,LICENSE* " - name: Upload binary uses: actions/upload-artifact@v3 with: diff --git a/pkg/proto/generated/pb/server.pb.go b/pkg/proto/generated/pb/server.pb.go index 3b7e79c..271274e 100644 --- a/pkg/proto/generated/pb/server.pb.go +++ b/pkg/proto/generated/pb/server.pb.go @@ -2157,11 +2157,9 @@ type GetAppInfoRes struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` - Sum string `protobuf:"bytes,3,opt,name=sum,proto3" json:"sum,omitempty"` - Vcs string `protobuf:"bytes,4,opt,name=vcs,proto3" json:"vcs,omitempty"` - VcsRevision string `protobuf:"bytes,5,opt,name=vcs_revision,json=vcsRevision,proto3" json:"vcs_revision,omitempty"` + ReleaseTag string `protobuf:"bytes,1,opt,name=release_tag,json=releaseTag,proto3" json:"release_tag,omitempty"` + CommitHash string `protobuf:"bytes,2,opt,name=commit_hash,json=commitHash,proto3" json:"commit_hash,omitempty"` + BranchName string `protobuf:"bytes,3,opt,name=branch_name,json=branchName,proto3" json:"branch_name,omitempty"` } func (x *GetAppInfoRes) Reset() { @@ -2196,37 +2194,23 @@ func (*GetAppInfoRes) Descriptor() ([]byte, []int) { return file_server_proto_rawDescGZIP(), []int{32} } -func (x *GetAppInfoRes) GetPath() string { +func (x *GetAppInfoRes) GetReleaseTag() string { if x != nil { - return x.Path + return x.ReleaseTag } return "" } -func (x *GetAppInfoRes) GetVersion() string { +func (x *GetAppInfoRes) GetCommitHash() string { if x != nil { - return x.Version + return x.CommitHash } return "" } -func (x *GetAppInfoRes) GetSum() string { +func (x *GetAppInfoRes) GetBranchName() string { if x != nil { - return x.Sum - } - return "" -} - -func (x *GetAppInfoRes) GetVcs() string { - if x != nil { - return x.Vcs - } - return "" -} - -func (x *GetAppInfoRes) GetVcsRevision() string { - if x != nil { - return x.VcsRevision + return x.BranchName } return "" } @@ -2481,105 +2465,103 @@ var file_server_proto_rawDesc = []byte{ 0x02, 0x52, 0x07, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x75, 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x04, 0x66, 0x75, 0x65, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x02, 0x52, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x22, 0x84, 0x01, 0x0a, - 0x0d, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x12, 0x12, - 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, - 0x74, 0x68, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, - 0x73, 0x75, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x12, 0x10, - 0x0a, 0x03, 0x76, 0x63, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x76, 0x63, 0x73, - 0x12, 0x21, 0x0a, 0x0c, 0x76, 0x63, 0x73, 0x5f, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x76, 0x63, 0x73, 0x52, 0x65, 0x76, 0x69, 0x73, - 0x69, 0x6f, 0x6e, 0x2a, 0x28, 0x0a, 0x10, 0x47, 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, 0x49, 0x6e, - 0x70, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x58, 0x49, 0x53, 0x10, - 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x42, 0x55, 0x54, 0x54, 0x4f, 0x4e, 0x10, 0x01, 0x2a, 0x45, 0x0a, - 0x09, 0x50, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x6f, - 0x72, 0x74, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x50, - 0x6f, 0x72, 0x74, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x10, - 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x50, 0x6f, 0x72, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, - 0x65, 0x64, 0x10, 0x02, 0x2a, 0x56, 0x0a, 0x0f, 0x53, 0x75, 0x70, 0x65, 0x72, 0x76, 0x69, 0x73, - 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x15, 0x0a, 0x11, 0x53, 0x75, 0x70, 0x65, 0x72, - 0x76, 0x69, 0x73, 0x6f, 0x72, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x16, - 0x0a, 0x12, 0x53, 0x75, 0x70, 0x65, 0x72, 0x76, 0x69, 0x73, 0x6f, 0x72, 0x49, 0x6e, 0x61, 0x63, - 0x74, 0x69, 0x76, 0x65, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x53, 0x75, 0x70, 0x65, 0x72, 0x76, - 0x69, 0x73, 0x6f, 0x72, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x10, 0x02, 0x32, 0x82, 0x09, 0x0a, - 0x0f, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x12, 0x48, 0x0a, 0x0b, 0x67, 0x65, 0x74, 0x47, 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, 0x73, 0x12, - 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1f, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, - 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x61, 0x6d, - 0x65, 0x70, 0x61, 0x64, 0x73, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0f, 0x67, 0x65, - 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x73, 0x12, 0x16, 0x2e, + 0x02, 0x52, 0x09, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x22, 0x72, 0x0a, 0x0d, + 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x12, 0x1f, 0x0a, + 0x0b, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x74, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x54, 0x61, 0x67, 0x12, 0x1f, + 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, + 0x1f, 0x0a, 0x0b, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4e, 0x61, 0x6d, 0x65, + 0x2a, 0x28, 0x0a, 0x10, 0x47, 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, 0x49, 0x6e, 0x70, 0x75, 0x74, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x58, 0x49, 0x53, 0x10, 0x00, 0x12, 0x0a, + 0x0a, 0x06, 0x42, 0x55, 0x54, 0x54, 0x4f, 0x4e, 0x10, 0x01, 0x2a, 0x45, 0x0a, 0x09, 0x50, 0x6f, + 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x6f, 0x72, 0x74, 0x55, + 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x6f, 0x72, 0x74, + 0x44, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x10, 0x01, 0x12, 0x11, + 0x0a, 0x0d, 0x50, 0x6f, 0x72, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x10, + 0x02, 0x2a, 0x56, 0x0a, 0x0f, 0x53, 0x75, 0x70, 0x65, 0x72, 0x76, 0x69, 0x73, 0x6f, 0x72, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x12, 0x15, 0x0a, 0x11, 0x53, 0x75, 0x70, 0x65, 0x72, 0x76, 0x69, 0x73, + 0x6f, 0x72, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x16, 0x0a, 0x12, 0x53, + 0x75, 0x70, 0x65, 0x72, 0x76, 0x69, 0x73, 0x6f, 0x72, 0x49, 0x6e, 0x61, 0x63, 0x74, 0x69, 0x76, + 0x65, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x53, 0x75, 0x70, 0x65, 0x72, 0x76, 0x69, 0x73, 0x6f, + 0x72, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x10, 0x02, 0x32, 0x82, 0x09, 0x0a, 0x0f, 0x4a, 0x6f, + 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x12, 0x48, 0x0a, + 0x0b, 0x67, 0x65, 0x74, 0x47, 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, 0x73, 0x12, 0x16, 0x2e, 0x4a, + 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1f, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x61, 0x6d, 0x65, 0x70, 0x61, + 0x64, 0x73, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0f, 0x67, 0x65, 0x74, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x73, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, + 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x1a, 0x22, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74, + 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x09, 0x67, 0x65, 0x74, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, + 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1d, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x22, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, - 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, - 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x09, 0x67, - 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, - 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, - 0x1a, 0x1d, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x22, - 0x00, 0x12, 0x44, 0x0a, 0x09, 0x73, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1d, + 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x44, + 0x0a, 0x09, 0x73, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1d, 0x2e, 0x4a, 0x6f, + 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x65, + 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x4a, 0x6f, 0x79, + 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x22, 0x00, 0x12, 0x4e, 0x0a, 0x0e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, + 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x22, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, - 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x4e, 0x0a, 0x0e, 0x76, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, - 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x1a, 0x22, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, - 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x1d, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x4c, 0x69, 0x6e, 0x6b, - 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x3c, 0x0a, - 0x08, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, - 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x1a, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x09, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x48, 0x54, 0x54, 0x50, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, - 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, + 0x65, 0x73, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4c, 0x69, 0x6e, + 0x6b, 0x12, 0x1d, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, + 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x4c, 0x69, 0x6e, 0x6b, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x3c, 0x0a, 0x08, 0x73, 0x74, - 0x6f, 0x70, 0x48, 0x54, 0x54, 0x50, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, + 0x6f, 0x70, 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x47, 0x0a, 0x0d, 0x67, 0x65, 0x74, 0x4c, - 0x69, 0x6e, 0x6b, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, - 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x1a, 0x1a, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x6e, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0x00, 0x30, - 0x01, 0x12, 0x4c, 0x0a, 0x12, 0x67, 0x65, 0x74, 0x54, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, - 0x79, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, - 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, - 0x1a, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x54, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x22, 0x00, 0x30, 0x01, 0x12, - 0x48, 0x0a, 0x0d, 0x67, 0x65, 0x74, 0x45, 0x76, 0x61, 0x6c, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, - 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, - 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x76, 0x61, 0x6c, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x73, 0x22, 0x00, 0x30, 0x01, 0x12, 0x6a, 0x0a, 0x14, 0x67, 0x65, 0x74, - 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, - 0x6d, 0x12, 0x28, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74, 0x74, - 0x65, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x1a, 0x24, 0x2e, 0x4a, 0x6f, - 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x54, 0x72, - 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x73, 0x22, 0x00, 0x30, 0x01, 0x12, 0x62, 0x0a, 0x10, 0x67, 0x65, 0x74, 0x47, 0x61, 0x6d, 0x65, - 0x70, 0x61, 0x64, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x24, 0x2e, 0x4a, 0x6f, 0x79, 0x73, - 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x47, - 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x1a, - 0x24, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x47, 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x73, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x73, 0x22, 0x00, 0x30, 0x01, 0x12, 0x46, 0x0a, 0x0a, 0x67, 0x65, 0x74, - 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, - 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, - 0x1e, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x22, - 0x00, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x6b, 0x61, 0x61, 0x63, 0x6b, 0x2f, 0x65, 0x6c, 0x72, 0x73, 0x2d, 0x6a, 0x6f, 0x79, 0x73, 0x74, - 0x69, 0x63, 0x6b, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, + 0x74, 0x48, 0x54, 0x54, 0x50, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, + 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, + 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x3c, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x48, + 0x54, 0x54, 0x50, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x4a, 0x6f, + 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, + 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x47, 0x0a, 0x0d, 0x67, 0x65, 0x74, 0x4c, 0x69, 0x6e, 0x6b, + 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, + 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1a, + 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x4c, 0x69, 0x6e, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x4c, + 0x0a, 0x12, 0x67, 0x65, 0x74, 0x54, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x53, 0x74, + 0x72, 0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1a, 0x2e, 0x4a, + 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x54, + 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x22, 0x00, 0x30, 0x01, 0x12, 0x48, 0x0a, 0x0d, + 0x67, 0x65, 0x74, 0x45, 0x76, 0x61, 0x6c, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x16, 0x2e, + 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, + 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x76, 0x61, 0x6c, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x73, 0x22, 0x00, 0x30, 0x01, 0x12, 0x6a, 0x0a, 0x14, 0x67, 0x65, 0x74, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x28, + 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x53, + 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x1a, 0x24, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, + 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, + 0x6d, 0x69, 0x74, 0x74, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x73, 0x22, 0x00, + 0x30, 0x01, 0x12, 0x62, 0x0a, 0x10, 0x67, 0x65, 0x74, 0x47, 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, + 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x24, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, + 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x47, 0x61, 0x6d, 0x65, + 0x70, 0x61, 0x64, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x1a, 0x24, 0x2e, 0x4a, + 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, + 0x61, 0x6d, 0x65, 0x70, 0x61, 0x64, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x73, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x73, 0x22, 0x00, 0x30, 0x01, 0x12, 0x46, 0x0a, 0x0a, 0x67, 0x65, 0x74, 0x41, 0x70, 0x70, + 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x2e, 0x4a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1e, 0x2e, 0x4a, + 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, + 0x65, 0x74, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x22, 0x00, 0x42, 0x36, + 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6b, 0x61, 0x61, + 0x63, 0x6b, 0x2f, 0x65, 0x6c, 0x72, 0x73, 0x2d, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, + 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, + 0x76, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pkg/proto/server.proto b/pkg/proto/server.proto index 0e2d737..466d2c3 100644 --- a/pkg/proto/server.proto +++ b/pkg/proto/server.proto @@ -211,11 +211,9 @@ message BatteryData { message GetAppInfoRes { - string path = 1; - string version = 2; - string sum = 3; - string vcs = 4; - string vcs_revision = 5; + string release_tag = 1; + string commit_hash = 2; + string branch_name = 3; } service JoystickControl { diff --git a/pkg/server/generated/.gitignore b/pkg/server/generated/.gitignore new file mode 100644 index 0000000..6a2257e --- /dev/null +++ b/pkg/server/generated/.gitignore @@ -0,0 +1 @@ +version.json \ No newline at end of file diff --git a/pkg/server/generated/version.json b/pkg/server/generated/version.json new file mode 100644 index 0000000..0af9b77 --- /dev/null +++ b/pkg/server/generated/version.json @@ -0,0 +1,5 @@ +{ + "release_tag": "(generated)", + "commit_hash": "(generated)", + "branch_name": "(generated)" +} \ No newline at end of file diff --git a/pkg/server/server_grpc.go b/pkg/server/server_grpc.go index 0c608d0..9d854e2 100644 --- a/pkg/server/server_grpc.go +++ b/pkg/server/server_grpc.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc/status" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/types/known/structpb" - "runtime/debug" "time" ) @@ -298,29 +297,16 @@ func (s *GRPCServer) GetTelemetryStream(_ *pb.Empty, server pb.JoystickControl_G func (s *GRPCServer) GetAppInfo(_ context.Context, _ *pb.Empty) (*pb.GetAppInfoRes, error) { - var info *debug.BuildInfo - var ok bool - - if info, ok = debug.ReadBuildInfo(); !ok { - return nil, status.Error(codes.Internal, "could not read application information") - } - - var vcs string - var vcsRevision string + var info *VersionInfo + var err error - for _, setting := range info.Settings { - if setting.Key == "vcs" { - vcs = setting.Value - } else if setting.Key == "vcs.revision" { - vcsRevision = setting.Value - } + if info, err = GetVersionInfo(); err != nil { + return nil, status.Error(codes.Internal, fmt.Sprintf("could not unmarshal version file. %s", err.Error())) } return &pb.GetAppInfoRes{ - Path: info.Main.Path, - Version: info.Main.Version, - Sum: info.Main.Sum, - Vcs: vcs, - VcsRevision: vcsRevision, + ReleaseTag: info.ReleaseTag, + CommitHash: info.CommitHash, + BranchName: info.BranchName, }, nil } diff --git a/pkg/server/version.go b/pkg/server/version.go index e69de29..7ed496b 100644 --- a/pkg/server/version.go +++ b/pkg/server/version.go @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: © 2023 OneEyeFPV oneeyefpv@gmail.com +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: FS-0.9-or-later + +package server + +import ( + _ "embed" + "encoding/json" + "sync" +) + +//go:generate go run ..\..\scripts\cmd\generate-version-file\generate-version-file.go --repo ..\.. --location ./generated +//go:embed generated/version.json +var versionJson []byte + +type VersionInfo struct { + ReleaseTag string `json:"release_tag"` + CommitHash string `json:"commit_hash"` + BranchName string `json:"branch_name"` +} + +var _version *VersionInfo +var _lock = &sync.Mutex{} + +func GetVersionInfo() (*VersionInfo, error) { + if _version == nil { + _lock.Lock() + defer _lock.Unlock() + if _version == nil { + _version = &VersionInfo{} + if err := json.Unmarshal(versionJson, _version); err != nil { + return nil, err + } + } + } + return _version, nil +} diff --git a/scripts/build-release-zip.go b/scripts/cmd/build-release-zip/build-release-zip.go similarity index 96% rename from scripts/build-release-zip.go rename to scripts/cmd/build-release-zip/build-release-zip.go index 27d40ad..6a3cacf 100644 --- a/scripts/build-release-zip.go +++ b/scripts/cmd/build-release-zip/build-release-zip.go @@ -116,6 +116,7 @@ func createZip(outputDir string, fileName string, filesList []string) error { return err } + //goland:noinspection ALL defer archive.Close() zipWriter := zip.NewWriter(archive) @@ -157,7 +158,7 @@ func createZip(outputDir string, fileName string, filesList []string) error { } } - zipWriter.Close() + _ = zipWriter.Close() return nil } @@ -197,7 +198,9 @@ func main() { fmt.Printf("release file name: %s\n", zipOutputFile) fmt.Printf("release file contents: %v", filesList) - createZip(outputZipDir, zipOutputFile, filesList) + if err = createZip(outputZipDir, zipOutputFile, filesList); err != nil { + panic(err) + } return } diff --git a/scripts/cmd/generate-version-file/generate-version-file.go b/scripts/cmd/generate-version-file/generate-version-file.go new file mode 100644 index 0000000..c3e87b8 --- /dev/null +++ b/scripts/cmd/generate-version-file/generate-version-file.go @@ -0,0 +1,185 @@ +// SPDX-FileCopyrightText: © 2023 OneEyeFPV oneeyefpv@gmail.com +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: FS-0.9-or-later + +package main + +import ( + "bufio" + "encoding/json" + "errors" + "flag" + "fmt" + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/storer" + "io" + "os" + "path/filepath" + "regexp" +) + +type VersionInfo struct { + ReleaseTag string `json:"release_tag"` + CommitHash string `json:"commit_hash"` + BranchName string `json:"branch_name"` +} + +func getCommitTags(r *git.Repository, hash plumbing.Hash) ([]string, error) { + var iter storer.ReferenceIter + var err error + + if iter, err = r.Tags(); err != nil { + return nil, err + } + + var ref *plumbing.Reference + var tags []string + for { + if ref, err = iter.Next(); errors.Is(err, io.EOF) { + break + } else if err != nil { + return nil, err + } + + if ref.Hash() != hash { + continue + } + + tags = append(tags, ref.Name().Short()) + + } + return tags, nil +} + +func getHeadTags(repoPath string) ([]string, error) { + var repo *git.Repository + var err error + if repo, err = git.PlainOpen(repoPath); err != nil { + return nil, err + } + + var hashCommit *plumbing.Reference + if hashCommit, err = repo.Head(); err != nil { + return nil, err + } + + return getCommitTags(repo, hashCommit.Hash()) +} + +func getReleaseTag(repoPath string, defaultTag string) (string, error) { + var tags []string + var err error + + if tags, err = getHeadTags(repoPath); err != nil { + return "", err + } + + var ok bool + for _, tag := range tags { + if ok, err = regexp.MatchString(`^v\d+\.\d+\.\d+`, tag); err != nil { + return "", err + } else if ok { + return tag, nil + } + } + + return defaultTag, nil +} + +func getCommitHash(repoPath string) (string, error) { + var repo *git.Repository + var err error + if repo, err = git.PlainOpen(repoPath); err != nil { + return "", err + } + + var hashCommit *plumbing.Reference + if hashCommit, err = repo.Head(); err != nil { + return "", err + } + + return hashCommit.Hash().String(), nil +} + +func getBranchName(repoPath string) (string, error) { + var repo *git.Repository + var err error + if repo, err = git.PlainOpen(repoPath); err != nil { + return "", err + } + + var head *plumbing.Reference + if head, err = repo.Head(); err != nil { + return "", err + } + + return head.Name().Short(), nil + +} + +//goland:noinspection GoUnhandledErrorResult +func createVersionFile(location string, versionInfo VersionInfo) error { + var err error + var file *os.File + + if file, err = os.Create(filepath.Join(location, "version.json")); err != nil { + return err + } + defer file.Close() + + writer := bufio.NewWriter(file) + + var jsonData []byte + if jsonData, err = json.MarshalIndent(versionInfo, "", " "); err != nil { + panic(err) + } + + writer.Write(jsonData) + writer.Flush() + + return nil +} + +func main() { + var outputDir string + var repoPath string + + flag.StringVar(&repoPath, "repo", ".", "Path containing .git") + flag.StringVar(&outputDir, "location", ".", "Output file directory") + + flag.Parse() + + var err error + var info os.FileInfo + + if info, err = os.Stat(outputDir); err != nil || !info.IsDir() { + panic(errors.New(fmt.Sprintf("output directory %s does not exist\n", outputDir))) + } + + var releaseTag string + var commitHash string + var branchName string + + if releaseTag, err = getReleaseTag(repoPath, "(devel)"); err != nil { + panic(err) + } + if commitHash, err = getCommitHash(repoPath); err != nil { + panic(err) + } + if branchName, err = getBranchName(repoPath); err != nil { + panic(err) + } + + version := VersionInfo{ + ReleaseTag: releaseTag, + CommitHash: commitHash, + BranchName: branchName, + } + + if err = createVersionFile(outputDir, version); err != nil { + panic(err) + } + + return +} diff --git a/webapp/src/components/pages/AboutPage.jsx b/webapp/src/components/pages/AboutPage.jsx index 56856a2..1331c9c 100644 --- a/webapp/src/components/pages/AboutPage.jsx +++ b/webapp/src/components/pages/AboutPage.jsx @@ -35,7 +35,7 @@ export default function AboutPage({}) { const getBackendVersionString = function (appInfo) { - return `${appInfo.getVersion()} ${appInfo.getVcs()}-${appInfo.getVcsRevision().substring(0, 7)}`; + return `${appInfo.getReleaseTag()}-${appInfo.getCommitHash().substring(0, 7)}`; } const openInNewTab = (url) => { diff --git a/webapp/src/generated/server_pb.js b/webapp/src/generated/server_pb.js index ef15bbf..256da2c 100644 --- a/webapp/src/generated/server_pb.js +++ b/webapp/src/generated/server_pb.js @@ -7025,11 +7025,9 @@ proto.JoystickControl.GetAppInfoRes.prototype.toObject = function(opt_includeIns */ proto.JoystickControl.GetAppInfoRes.toObject = function(includeInstance, msg) { var f, obj = { - path: jspb.Message.getFieldWithDefault(msg, 1, ""), - version: jspb.Message.getFieldWithDefault(msg, 2, ""), - sum: jspb.Message.getFieldWithDefault(msg, 3, ""), - vcs: jspb.Message.getFieldWithDefault(msg, 4, ""), - vcsRevision: jspb.Message.getFieldWithDefault(msg, 5, "") + releaseTag: jspb.Message.getFieldWithDefault(msg, 1, ""), + commitHash: jspb.Message.getFieldWithDefault(msg, 2, ""), + branchName: jspb.Message.getFieldWithDefault(msg, 3, "") }; if (includeInstance) { @@ -7068,23 +7066,15 @@ proto.JoystickControl.GetAppInfoRes.deserializeBinaryFromReader = function(msg, switch (field) { case 1: var value = /** @type {string} */ (reader.readString()); - msg.setPath(value); + msg.setReleaseTag(value); break; case 2: var value = /** @type {string} */ (reader.readString()); - msg.setVersion(value); + msg.setCommitHash(value); break; case 3: var value = /** @type {string} */ (reader.readString()); - msg.setSum(value); - break; - case 4: - var value = /** @type {string} */ (reader.readString()); - msg.setVcs(value); - break; - case 5: - var value = /** @type {string} */ (reader.readString()); - msg.setVcsRevision(value); + msg.setBranchName(value); break; default: reader.skipField(); @@ -7115,49 +7105,35 @@ proto.JoystickControl.GetAppInfoRes.prototype.serializeBinary = function() { */ proto.JoystickControl.GetAppInfoRes.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = message.getPath(); + f = message.getReleaseTag(); if (f.length > 0) { writer.writeString( 1, f ); } - f = message.getVersion(); + f = message.getCommitHash(); if (f.length > 0) { writer.writeString( 2, f ); } - f = message.getSum(); + f = message.getBranchName(); if (f.length > 0) { writer.writeString( 3, f ); } - f = message.getVcs(); - if (f.length > 0) { - writer.writeString( - 4, - f - ); - } - f = message.getVcsRevision(); - if (f.length > 0) { - writer.writeString( - 5, - f - ); - } }; /** - * optional string path = 1; + * optional string release_tag = 1; * @return {string} */ -proto.JoystickControl.GetAppInfoRes.prototype.getPath = function() { +proto.JoystickControl.GetAppInfoRes.prototype.getReleaseTag = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; @@ -7166,16 +7142,16 @@ proto.JoystickControl.GetAppInfoRes.prototype.getPath = function() { * @param {string} value * @return {!proto.JoystickControl.GetAppInfoRes} returns this */ -proto.JoystickControl.GetAppInfoRes.prototype.setPath = function(value) { +proto.JoystickControl.GetAppInfoRes.prototype.setReleaseTag = function(value) { return jspb.Message.setProto3StringField(this, 1, value); }; /** - * optional string version = 2; + * optional string commit_hash = 2; * @return {string} */ -proto.JoystickControl.GetAppInfoRes.prototype.getVersion = function() { +proto.JoystickControl.GetAppInfoRes.prototype.getCommitHash = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); }; @@ -7184,16 +7160,16 @@ proto.JoystickControl.GetAppInfoRes.prototype.getVersion = function() { * @param {string} value * @return {!proto.JoystickControl.GetAppInfoRes} returns this */ -proto.JoystickControl.GetAppInfoRes.prototype.setVersion = function(value) { +proto.JoystickControl.GetAppInfoRes.prototype.setCommitHash = function(value) { return jspb.Message.setProto3StringField(this, 2, value); }; /** - * optional string sum = 3; + * optional string branch_name = 3; * @return {string} */ -proto.JoystickControl.GetAppInfoRes.prototype.getSum = function() { +proto.JoystickControl.GetAppInfoRes.prototype.getBranchName = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); }; @@ -7202,47 +7178,11 @@ proto.JoystickControl.GetAppInfoRes.prototype.getSum = function() { * @param {string} value * @return {!proto.JoystickControl.GetAppInfoRes} returns this */ -proto.JoystickControl.GetAppInfoRes.prototype.setSum = function(value) { +proto.JoystickControl.GetAppInfoRes.prototype.setBranchName = function(value) { return jspb.Message.setProto3StringField(this, 3, value); }; -/** - * optional string vcs = 4; - * @return {string} - */ -proto.JoystickControl.GetAppInfoRes.prototype.getVcs = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, "")); -}; - - -/** - * @param {string} value - * @return {!proto.JoystickControl.GetAppInfoRes} returns this - */ -proto.JoystickControl.GetAppInfoRes.prototype.setVcs = function(value) { - return jspb.Message.setProto3StringField(this, 4, value); -}; - - -/** - * optional string vcs_revision = 5; - * @return {string} - */ -proto.JoystickControl.GetAppInfoRes.prototype.getVcsRevision = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 5, "")); -}; - - -/** - * @param {string} value - * @return {!proto.JoystickControl.GetAppInfoRes} returns this - */ -proto.JoystickControl.GetAppInfoRes.prototype.setVcsRevision = function(value) { - return jspb.Message.setProto3StringField(this, 5, value); -}; - - /** * @enum {number} */