Skip to content

Commit

Permalink
Added version info to build
Browse files Browse the repository at this point in the history
  • Loading branch information
robrotheram committed Feb 28, 2024
1 parent 59de6d6 commit 6562794
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ __debug_bin*
*.db
notes
.kube

w2g
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FROM golang:1.21.4 as GO_BUILDER
ARG VER
WORKDIR /server
ADD . .
RUN go generate pkg/utils/version.go
RUN CGO_ENABLED=0 GOOS=linux go build

FROM alpine
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func main() {
log.Fatalf("Database Error: %v", err)
}

log.Infof("Version: %s", utils.Version)

hub := controllers.NewHub(db)

bot, _ := discord.NewDiscordBot(utils.Configuration, hub)
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewController(id string, db *bolt.DB) *Controller {
contoller.load(id)
contoller.AddListner(uuid.NewString(), &Auditing{})
if utils.Configuration.BetterStackToken != "" {
log.Info("enabling better stack logging")
contoller.AddListner(uuid.NewString(), &BetterStack{Token: utils.Configuration.BetterStackToken})
}

Expand Down
22 changes: 16 additions & 6 deletions pkg/discord/commands/infoCmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package commands

import (
"time"
"w2g/pkg/discord/components"
"w2g/pkg/utils"

"github.com/bwmarrin/discordgo"
)
Expand All @@ -12,7 +14,6 @@ func init() {
Name: "player",
ApplicationCommand: []discordgo.ApplicationCommand{
{

Type: discordgo.UserApplicationCommand,
},
{
Expand All @@ -31,18 +32,27 @@ func init() {
},
},
Function: listcmd,
},
Command{
Name: "version",
ApplicationCommand: []discordgo.ApplicationCommand{
{
Description: "return the version of this bot",
Type: discordgo.ChatApplicationCommand,
},
},
Function: versioncmd,
})
}

func nowplayingCmd(ctx CommandCtx) *discordgo.InteractionResponse {
current := ctx.Controller.State().Current
return ctx.CmdReplyEmbed(components.MediaEmbed(current, "Now Playing"))
}

func listcmd(ctx CommandCtx) *discordgo.InteractionResponse {
return ctx.CmdReplyData(components.QueueCompontent(ctx.Controller.State().Queue, 0))
}

func controlscmd(ctx CommandCtx) *discordgo.InteractionResponse {
return ctx.CmdReplyData(components.ControlCompontent(ctx.Controller.State()))
}

func versioncmd(ctx CommandCtx) *discordgo.InteractionResponse {
return ctx.Replyf("Version: %s, \n commit: %s \n time: %s", utils.Version, utils.Revision, utils.LastCommit.Format(time.RFC822))
}
31 changes: 31 additions & 0 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package utils

import (
_ "embed"
"runtime/debug"
"time"
)

//go:generate sh -c "git describe --tags --abbrev=0 > version.txt"
//go:embed version.txt
var Version string
var LastCommit time.Time
var Revision string

func init() {
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
for _, kv := range info.Settings {
if kv.Value == "" {
continue
}
switch kv.Key {
case "vcs.revision":
Revision = kv.Value
case "vcs.time":
LastCommit, _ = time.Parse(time.RFC3339, kv.Value)
}
}
}
Empty file added pkg/utils/version.txt
Empty file.
8 changes: 6 additions & 2 deletions ui/src/pages/app/components/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const Nav = ({user, bot}) => {
<button onClick={() => setModalOpen(!isModalOpen)} type="button" className="float-right flex mr-4 text-sm rounded-full md:mr-0 focus:ring-4 focus:ring-gray-300 dark:focus:ring-gray-600" id="user-menu-button" aria-expanded="false" data-dropdown-toggle="user-dropdown" data-dropdown-placement="bottom">
<img className="w-8 h-8 rounded-full" src={user.avatar_icon} alt="user photo" />
</button>
{isModalOpen && <div className="z-50 fixed top-10 right-2 my-4 text-base list-none divide-y divide-gray-100 rounded-lg shadow bg-zinc-800" id="user-dropdown">
<ul className="" aria-labelledby="user-menu-button">
{!isModalOpen && <div className="z-50 fixed top-10 right-2 my-4 text-base list-none divide-y divide-gray-100 rounded-lg shadow bg-zinc-800" id="user-dropdown">
<ul className="px-4 py-1" aria-labelledby="user-menu-button">
<li>
<a href={`https://discord.com/oauth2/authorize?client_id=${bot}&scope=bot`} className="block text-center px-8 py-3 text-md hover:rounded-lg text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">
invite bot
Expand All @@ -53,6 +53,10 @@ export const Nav = ({user, bot}) => {
Sign out
</a>
</li>
<hr style={{margin:"0.5rem 0"}}/>
<li className="text-center py-2">
<span>Release: {import.meta.env.VITE_APP_VERSION}</span>
</li>
</ul>
</div>}
</div>
Expand Down
9 changes: 9 additions & 0 deletions ui/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import * as child from "child_process";
import { VitePWA } from "vite-plugin-pwa";

const manifestForPlugin = {
Expand Down Expand Up @@ -47,7 +48,15 @@ const manifestForPlugin = {
},
};



const commitHash = child.execSync("git rev-parse --short HEAD").toString()
const gitTag = child.execSync("git describe --tags --abbrev=0").toString()
// https://vitejs.dev/config/
export default defineConfig({
define: {
'import.meta.env.VITE_APP_VERSION': JSON.stringify(gitTag),
'import.meta.env.VITE_APP_COMMIT': JSON.stringify(commitHash)
},
plugins: [react()],
})

0 comments on commit 6562794

Please sign in to comment.