Skip to content

Commit 5148952

Browse files
committed
Merge branch 'release/v1.7.0-beta1'
2 parents e54fbdd + 41c3133 commit 5148952

21 files changed

+1111
-500
lines changed

.github/workflows/release.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ jobs:
1414
- uses: actions/checkout@master
1515
- uses: actions/setup-go@v2
1616
with:
17-
go-version: '1.15'
17+
go-version: '1.16'
18+
19+
- name: Get the version
20+
id: get_version
21+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
1822

1923
- name: Build
20-
run: CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o github-actions-exporter
24+
run: CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-X 'main.version=${{ steps.get_version.outputs.VERSION }}'" -o github-actions-exporter
2125

2226
- name: Create Release
2327
id: create_release

Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
FROM golang:1.15 as builder
2-
1+
FROM golang:1.16 as builder
32

43
WORKDIR /app
54
COPY . .
6-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bin/app
5+
RUN bash ./build.sh
76

87
FROM alpine:latest as release
98
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

build.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
VERSION=`git branch | grep '*' | awk '{print $2}'`
6+
if [[ $VERSION == "master" ]];
7+
then
8+
VERSION=`git describe --tags --abbrev=0`
9+
fi
10+
11+
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-X 'main.version=$VERSION'" -o bin/app

config/config.go

-64
This file was deleted.

go.mod

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
module github-actions-exporter
22

3-
go 1.13
3+
go 1.16
44

55
require (
6-
github.com/prometheus/client_golang v1.4.0
7-
github.com/urfave/cli v1.22.2
6+
github.com/fasthttp/router v1.3.9 // indirect
7+
github.com/google/go-github/v33 v33.0.1-0.20210311004518-0540c33dca8b // indirect
8+
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
9+
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
10+
github.com/prometheus/client_golang v1.9.0 // indirect
11+
github.com/urfave/cli/v2 v2.3.0 // indirect
12+
github.com/valyala/fasthttp v1.22.0 // indirect
13+
golang.org/x/oauth2 v0.0.0-20210311163135-5366d9dc1934 // indirect
814
)

go.sum

+599-9
Large diffs are not rendered by default.

main.go

+12-43
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,28 @@
1-
/*
2-
Main application package
3-
*/
41
package main
52

63
import (
7-
"fmt"
84
"log"
9-
"net/http"
105
"os"
11-
"strconv"
126

13-
"github.com/prometheus/client_golang/prometheus"
7+
"github.com/urfave/cli/v2"
148

15-
"github.com/prometheus/client_golang/prometheus/promhttp"
16-
"github.com/urfave/cli"
17-
18-
"github-actions-exporter/config"
19-
"github-actions-exporter/metrics"
9+
"github-actions-exporter/pkg/config"
10+
"github-actions-exporter/pkg/server"
2011
)
2112

22-
var version = "v1.6.0"
13+
var (
14+
version = "development"
15+
)
2316

24-
// main init configuration
2517
func main() {
2618
app := cli.NewApp()
2719
app.Name = "github-actions-exporter"
28-
app.Flags = config.NewContext()
29-
app.Action = runWeb
20+
app.Flags = config.InitConfiguration()
3021
app.Version = version
22+
app.Action = server.RunServer
3123

32-
app.Run(os.Args)
33-
}
34-
35-
// runWeb start http server
36-
func runWeb(ctx *cli.Context) {
37-
go metrics.WorkflowsCache()
38-
go metrics.GetRunnersFromGithub()
39-
go metrics.GetRunnersOrganizationFromGithub()
40-
go metrics.GetWorkflowRunsFromGithub()
41-
go metrics.GetBillableFromGithub()
42-
43-
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
44-
fmt.Fprintf(w, "/metrics")
45-
})
46-
http.Handle("/metrics", promhttp.Handler())
47-
log.Printf("starting exporter with port %v", config.Port)
48-
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(config.Port), nil))
49-
}
50-
51-
// init prometheus metrics
52-
func init() {
53-
prometheus.MustRegister(metrics.RunnersGauge)
54-
prometheus.MustRegister(metrics.RunnersOrganizationGauge)
55-
prometheus.MustRegister(metrics.WorkflowRunStatusGauge)
56-
prometheus.MustRegister(metrics.WorkflowRunStatusDeprecatedGauge)
57-
prometheus.MustRegister(metrics.WorkflowRunDurationGauge)
58-
prometheus.MustRegister(metrics.WorkflowBillGauge)
24+
err := app.Run(os.Args)
25+
if err != nil {
26+
log.Fatal(err)
27+
}
5928
}

metrics/get_billable_from_github.go

-73
This file was deleted.

metrics/get_runners_from_github.go

-70
This file was deleted.

0 commit comments

Comments
 (0)