Skip to content

Commit

Permalink
Merge pull request #35 from ricoberger/add-preview-builds
Browse files Browse the repository at this point in the history
Add preview builds
  • Loading branch information
ricoberger authored Sep 14, 2021
2 parents c5b829f + 83df8d3 commit 5ea1547
Show file tree
Hide file tree
Showing 11 changed files with 681 additions and 584 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ jobs:
runs-on: ubuntu-20.04
name: Release
steps:
- name: Set up Go 1.16
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get dependencies
run: go mod download
Expand All @@ -30,6 +32,7 @@ jobs:
- name: Upload
run: |
./upload.sh ./bin/script_exporter-darwin-amd64 application/x-binary
./upload.sh ./bin/script_exporter-darwin-arm64 application/x-binary
./upload.sh ./bin/script_exporter-linux-amd64 application/x-binary
./upload.sh ./bin/script_exporter-linux-armv7 application/x-binary
./upload.sh ./bin/script_exporter-linux-arm64 application/x-binary
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Test

on:
pull_request:

jobs:
test:
runs-on: ubuntu-20.04
name: Test
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get dependencies
run: go mod download

- name: Test
run: go test ./...

- name: Build
run: make release

- name: Upload Artifacts (darwin-amd64)
uses: actions/upload-artifact@v2
with:
name: script_exporter-darwin-amd64
path: bin/script_exporter-darwin-amd64
if-no-files-found: error

- name: Upload Artifacts (darwin-arm64)
uses: actions/upload-artifact@v2
with:
name: script_exporter-darwin-arm64
path: bin/script_exporter-darwin-arm64
if-no-files-found: error

- name: Upload Artifacts (linux-amd64)
uses: actions/upload-artifact@v2
with:
name: script_exporter-linux-amd64
path: bin/script_exporter-linux-amd64
if-no-files-found: error

- name: Upload Artifacts (linux-armv7)
uses: actions/upload-artifact@v2
with:
name: script_exporter-linux-armv7
path: bin/script_exporter-linux-armv7
if-no-files-found: error

- name: Upload Artifacts (linux-arm64)
uses: actions/upload-artifact@v2
with:
name: script_exporter-linux-arm64
path: bin/script_exporter-linux-arm64
if-no-files-found: error

- name: Upload Artifacts (windows-amd64.exe)
uses: actions/upload-artifact@v2
with:
name: script_exporter-windows-amd64.exe
path: bin/script_exporter-windows-amd64.exe
if-no-files-found: error
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ build-darwin-amd64:
-o ./bin/$$target-darwin-amd64 ./cmd/$$target; \
done

build-darwin-arm64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
-X ${REPO}/pkg/version.Revision=${REVISION} \
-X ${REPO}/pkg/version.Branch=${BRANCH} \
-X ${REPO}/pkg/version.BuildUser=${BUILDUSER} \
-X ${REPO}/pkg/version.BuildDate=${BUILDTIME}" \
-o ./bin/$$target-darwin-arm64 ./cmd/$$target; \
done

build-linux-amd64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -installsuffix cgo -ldflags "-X ${REPO}/pkg/version.Version=${VERSION} \
Expand Down Expand Up @@ -71,11 +81,10 @@ build-windows-amd64:
-o ./bin/$$target-windows-amd64.exe ./cmd/$$target/${WHAT}_windows.go; \
done


clean:
rm -rf ./bin

release: clean build-darwin-amd64 build-linux-amd64 build-linux-armv7 build-linux-arm64 build-windows-amd64
release: clean build-darwin-amd64 build-darwin-arm64 build-linux-amd64 build-linux-armv7 build-linux-arm64 build-windows-amd64

release-major:
$(eval MAJORVERSION=$(shell git describe --tags --abbrev=0 | sed s/v// | awk -F. '{print "v"$$1+1".0.0"}'))
Expand Down
1 change: 0 additions & 1 deletion cmd/script_exporter/script_exporter_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// +build windows
// Script_exporter is a Prometheus exporter to execute programs and
// scripts and collect metrics from their output and their exit
// status.
Expand Down
90 changes: 46 additions & 44 deletions cmd/script_exporter/script_exporter_windows.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
// +build windows
// Script_exporter is a Prometheus exporter to execute programs and
// scripts and collect metrics from their output and their exit
// status.
package main

import (
"log"

"github.com/ricoberger/script_exporter/pkg/exporter"
win "github.com/ricoberger/script_exporter/pkg/windows"
"golang.org/x/sys/windows/svc"
)

func main() {
e := exporter.InitExporter()

isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
log.Fatal(err)
}

stopCh := make(chan bool)
if !isInteractive {
go func() {
err = svc.Run("Script Exporter", win.NewWindowsExporterService(stopCh))
if err != nil {
log.Fatalf("Failed to start service: %v", err)
}
}()
}

go func() {
e.Serve()
}()

for {
if <-stopCh {
log.Printf("Shutting down %s", "Script Exporter")
break
}
}

}
//go:build windows
// +build windows

// Script_exporter is a Prometheus exporter to execute programs and
// scripts and collect metrics from their output and their exit
// status.
package main

import (
"log"

"github.com/ricoberger/script_exporter/pkg/exporter"
win "github.com/ricoberger/script_exporter/pkg/windows"
"golang.org/x/sys/windows/svc"
)

func main() {
e := exporter.InitExporter()

isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
log.Fatal(err)
}

stopCh := make(chan bool)
if !isInteractive {
go func() {
err = svc.Run("Script Exporter", win.NewWindowsExporterService(stopCh))
if err != nil {
log.Fatalf("Failed to start service: %v", err)
}
}()
}

go func() {
e.Serve()
}()

for {
if <-stopCh {
log.Printf("Shutting down %s", "Script Exporter")
break
}
}

}
15 changes: 13 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
module github.com/ricoberger/script_exporter

go 1.17

require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/prometheus/client_golang v1.11.0
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0
gopkg.in/yaml.v2 v2.4.0
)

go 1.16
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
)
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3 h1:3Ad41xy2WCESpufXwgs7NpDSu+vjxqLt2UFqUV+20bI=
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 h1:xrCZDmdtoloIiooiA9q0OQb9r8HejIHYoHGhGCe1pGg=
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
Loading

0 comments on commit 5ea1547

Please sign in to comment.