Browse Source

Add version to UA string

Matty Jorgensen 1 year ago
parent
commit
92b5e78ea7
6 changed files with 51 additions and 6 deletions
  1. 1 1
      .github/workflows/go.yml
  2. 2 0
      .github/workflows/release.yml
  3. 16 0
      .idea/inspectionProfiles/Project_Default.xml
  4. 15 0
      Makefile
  5. 15 5
      config.go
  6. 2 0
      gof.go

+ 1 - 1
.github/workflows/go.yml

@@ -28,7 +28,7 @@ jobs:
           ${{ runner.os }}-go-
 
     - name: Build
-      run: go build -v ./...
+      run: make build
 
     #- name: Test
     #  run: go test -v ./...

+ 2 - 0
.github/workflows/release.yml

@@ -23,4 +23,6 @@ jobs:
         github_token: ${{ secrets.GITHUB_TOKEN }}
         goos: ${{ matrix.goos }}
         goarch: ${{ matrix.goarch }}
+        build_command: "make"
+        build_flags: "build"
         extra_files: LICENSE README.md gof.example.yaml

+ 16 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,16 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
+    <inspection_tool class="PyPackageRequirementsInspection" enabled="false" level="WARNING" enabled_by_default="false">
+      <option name="ignoredPackages">
+        <value>
+          <list size="1">
+            <item index="0" class="java.lang.String" itemvalue="django" />
+          </list>
+        </value>
+      </option>
+    </inspection_tool>
+    <inspection_tool class="Stylelint" enabled="true" level="ERROR" enabled_by_default="true" />
+  </profile>
+</component>

+ 15 - 0
Makefile

@@ -0,0 +1,15 @@
+VERSION := $(shell git describe --tags --abbrev=0)
+BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
+
+GOLDFLAGS += -X main.Version=$(VERSION)
+GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
+GOFLAGS = -ldflags "$(GOLDFLAGS)"
+
+run: build
+	./gof
+
+dry-run: build
+	./gof -dry-run
+
+build:
+	go build -o gof $(GOFLAGS) .

+ 15 - 5
config.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"fmt"
 	"log"
 	"os"
 	"time"
@@ -8,11 +9,9 @@ import (
 	"gopkg.in/yaml.v2"
 )
 
-const (
-	HttpUserAgent = "gof"
-)
-
 var (
+	Version    string
+	Buildtime  string
 	configFile string
 )
 
@@ -28,6 +27,13 @@ type config struct {
 	Accounts    []account
 	LastUpdated time.Time
 	HttpConfig  httpConfig
+	Meta        meta
+}
+
+type meta struct {
+	Name      string
+	Version   string
+	Buildtime string
 }
 
 type account struct {
@@ -56,7 +62,11 @@ func readConfig(fileName string) *config {
 	if debug {
 		log.Printf("Config:\n\n%v", config)
 	}
-	config.HttpConfig.UserAgent = HttpUserAgent
+	config.Meta.Name = "gof"
+	config.Meta.Version = Version
+	config.Meta.Buildtime = Buildtime
+	config.HttpConfig.UserAgent = fmt.Sprintf("%s/%s",
+		config.Meta.Name, config.Meta.Version)
 	return config
 }
 

+ 2 - 0
gof.go

@@ -36,6 +36,8 @@ func main() {
 
 	log.Println("gof starting up...")
 	conf = readConfig(configFile)
+	log.Printf("Version: %s\n", conf.Meta.Version)
+	log.Printf("Build time: %s\n", conf.Meta.Buildtime)
 
 	var tpls = make(map[string]*template.Template)
 	var formats = make(map[string]string)