Skip to content

Commit

Permalink
ci: add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark committed Oct 30, 2024
1 parent 6251ff2 commit 938d084
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 8 # Same as v3 and before

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
Expand All @@ -27,7 +33,7 @@ jobs:
run: go get .
- name: Build
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o turbostat-exporter-${{ matrix.goos }}-${{ matrix.goarch }}
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-X 'main.Version=${{ env.GITHUB_REF_SLUG }}'" -o turbostat-exporter-${{ matrix.goos }}-${{ matrix.goarch }}
chmod +x turbostat-exporter-${{ matrix.goos }}-${{ matrix.goarch }}
# - name: Archive binaries
# uses: actions/upload-artifact@v4
Expand Down
17 changes: 15 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"crypto/sha256"
"crypto/subtle"
"encoding/csv"
"flag"
"fmt"
"io"
"maps"
"math"
"net/http"
"os"
"os/exec"
"slices"
"strconv"
"strings"
"time"

"net/http"

"github.com/joho/godotenv"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -481,6 +481,7 @@ func basicAuth(next http.HandlerFunc) http.HandlerFunc {
})
}

var Version = "development"
var listOfMetrics []metricMapping = nil
var defaultSleepTimer = 5
var isCommandCat = false
Expand Down Expand Up @@ -572,8 +573,20 @@ func parseConfiguration() {
}

func main() {
flagVersion := flag.Bool("version", false, "prints the version")

flag.Parse()

if *flagVersion {
fmt.Println(Version)
os.Exit(0)
}

zerolog.SetGlobalLevel(zerolog.InfoLevel)
startServer()
}

func startServer() {
fmt.Println("Prometheus turbostat exporter - created by BlackDark (https://github.com/BlackDark/prometheus_turbotstat_exporter)")
parseConfiguration()

Expand Down

0 comments on commit 938d084

Please sign in to comment.