Skip to content

Commit

Permalink
Merge pull request #19 from opsdis/setup_workflow
Browse files Browse the repository at this point in the history
Setup workflow
  • Loading branch information
thenodon authored Apr 28, 2023
2 parents 7be2266 + 8f3772f commit 5f73bf2
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 4 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Go

on:
push:
branches:
- '**'
- '!master'
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ^1.20
id: go

- name: Get dependencies
run: make get-dependencies

- name: Ensure that all files are properly formatted
run: |
FILES=$(go run golang.org/x/tools/cmd/goimports@latest -w -l .)
if [ -n "${FILES}" ]; then
printf "Following files are not formatted: \n%s" "$FILES"
exit 1
fi
- name: GO vet
run: make vet

- name: Test
run: make test

- name: Test building
run: make build
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
release:
types: [created]

jobs:
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux, darwin, windows]
goarch: [ "arm64", "amd64" ]
exclude:
- goarch: arm64
goos: windows
- goarch: arm64
goos: darwin

steps:
- uses: actions/checkout@v3
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GH_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: 1.20
binary_name: aci-exporter-${{ env.RELEASE_VERSION }}.${{ matrix.goos }}.${{ matrix.goarch }}
extra_files: COPYING README.md
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
build/
.vscode/
.idea/
./config.yaml
target/
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
VERSION := $(shell git describe --tags)
GIT_HASH := $(shell git rev-parse --short HEAD )

GO_VERSION ?= $(shell go version)
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
LDFLAGS = -ldflags "-X main.Version=${VERSION} -X main.GitHash=${GIT_HASH} -X main.GoVersion=${GO_VERSION_NUMBER}"

.PHONY: build
build:
CGO_ENABLED=0 go build ${LDFLAGS} -v -o target/aci-exporter .

.PHONY: build-release
build-release: build-release-amd64 build-release-arm64

.PHONY: build-release-amd64
build-release-amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o=aci-exporter.linux.amd64 . && \
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o=aci-exporter.windows.amd64.exe . && \
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o=aci-exporter.darwin.amd64 .

.PHONY: build-release-arm64
build-release-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o=aci-exporter.linux.arm64 . && \
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o=aci-exporter.darwin.arm64 .

.PHONY: generate-html-coverage
generate-html-coverage:
go tool cover -html=cover.out -o coverage.html
@printf "Generated coverage html \n"

.PHONY: print-coverage
print-coverage:
@go tool cover -func cover.out

.PHONY: test-unittests
test-unittests:
go test -v -race -coverprofile cover.out ./...

.PHONY: test
test: fmt-check vet test-unittests generate-html-coverage print-coverage
@printf "Successfully run tests \n"

.PHONY: get-dependencies
get-dependencies:
go get -v -t -d ./...

.PHONY: vet
vet:
@go vet ./...
@go mod tidy

test-output:
$(shell echo $$GO_VERSION_NUMBER)

.PHONY: fmt-fix
fmt-fix:
@go mod download golang.org/x/tools
@go run golang.org/x/tools/cmd/goimports -w -l .

.PHONY: fmt-check
fmt-check:
@printf "Check formatting... \n"
@go mod download golang.org/x/tools
@if [[ $$( go run golang.org/x/tools/cmd/goimports -l . ) ]]; then printf "Files not properly formatted. Run 'make fmt-fix' \n"; exit 1; else printf "Check formatting finished \n"; fi
7 changes: 4 additions & 3 deletions aci-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

"github.com/Knetic/govaluate"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/tidwall/gjson"
"github.com/umisama/go-regexpcache"
"strconv"
"strings"
"time"
)

var arrayExtension = regexpcache.MustCompile("^(?P<stage_1>.*)\\.\\[(?P<child_name>.*)\\](?P<stage_2>.*)")
Expand Down
3 changes: 2 additions & 1 deletion aci-exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"strconv"
"time"

"net/http"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/segmentio/ksuid"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"net/http"
)

type loggingResponseWriter struct {
Expand Down

0 comments on commit 5f73bf2

Please sign in to comment.