Skip to content

Commit 76d81a2

Browse files
committed
initial structure
1 parent e930854 commit 76d81a2

File tree

9 files changed

+174
-0
lines changed

9 files changed

+174
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: build + test + lint
2+
on:
3+
pull_request:
4+
paths:
5+
- "go.sum"
6+
- "go.mod"
7+
- "**.go"
8+
- "Makefile"
9+
- ".github/workflows/ci.yaml"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-go@v2
17+
with:
18+
go-version: '1.18'
19+
- uses: actions/cache@v2
20+
with:
21+
path: ~/go/pkg/mod
22+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
23+
restore-keys: |
24+
${{ runner.os }}-go-
25+
- run: make build
26+
- run: make test
27+
28+
lint:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v2
32+
- uses: actions/setup-go@v2
33+
with:
34+
go-version: '1.18'
35+
- uses: golangci/golangci-lint-action@v3.1.0
36+
with:
37+
version: v1.45.2

.github/workflows/pre-release.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "pre-release"
2+
on:
3+
push:
4+
branches: [main]
5+
paths:
6+
- "go.sum"
7+
- "go.mod"
8+
- "**.go"
9+
- "Makefile"
10+
- ".github/workflows/pre-release.yaml"
11+
12+
jobs:
13+
pre-release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-go@v2
18+
with:
19+
go-version: '1.18'
20+
- uses: actions/cache@v2
21+
with:
22+
path: ~/go/pkg/mod
23+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
24+
restore-keys: |
25+
${{ runner.os }}-go-
26+
- run: make test
27+
- run: make release
28+
29+
- uses: "marvinpinto/action-automatic-releases@v1.2.1"
30+
with:
31+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
32+
automatic_release_tag: "latest"
33+
prerelease: true
34+
title: "Development Build"
35+
files: |
36+
dist/*
37+
LICENSE
38+
configs/*

.github/workflows/release.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "release"
2+
on:
3+
push:
4+
tags: ["v*"]
5+
6+
jobs:
7+
tagged-release:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/setup-go@v2
12+
with:
13+
go-version: '1.18'
14+
- uses: actions/cache@v2
15+
with:
16+
path: ~/go/pkg/mod
17+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
18+
restore-keys: |
19+
${{ runner.os }}-go-
20+
- run: make test
21+
- run: make release
22+
23+
- uses: "marvinpinto/action-automatic-releases@v1.2.1"
24+
with:
25+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
26+
prerelease: false
27+
files: |
28+
dist/*
29+
LICENSE
30+
configs/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
dist

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cSpell.words": [
3+
"Victron"
4+
],
5+
"go.lintTool": "golangci-lint",
6+
"go.testFlags": ["-race"],
7+
}

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
BUILD_DIR=./cmd/vedirect_exporter
2+
BINARY=vedirect-exporter
3+
4+
.PHONY: build test release
5+
6+
build:
7+
go mod verify
8+
go build -o dist/ $(BUILD_FLAGS) $(BUILD_DIR)
9+
10+
release:
11+
GOOS=linux GOARCH=arm64 go build -o dist/$(BINARY)-linux-arm64 $(BUILD_FLAGS) $(BUILD_DIR)
12+
GOOS=linux GOARCH=arm GOARM=7 go build -o dist/$(BINARY)-linux-armv7 $(BUILD_FLAGS) $(BUILD_DIR)
13+
GOOS=linux GOARCH=amd64 go build -o dist/$(BINARY)-linux-amd64 $(BUILD_FLAGS) $(BUILD_DIR)
14+
15+
test:
16+
go test -v -race ./...

cmd/vedirect_exporter/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"errors"
6+
"flag"
7+
"fmt"
8+
"log"
9+
"os"
10+
"os/signal"
11+
"syscall"
12+
13+
"github.com/lazy-electron-consulting/ve-direct-exporter/internal/start"
14+
)
15+
16+
func main() {
17+
flag.Usage = func() {
18+
fmt.Printf("Usage: %s [OPTIONS] config-file\n", os.Args[0])
19+
flag.PrintDefaults()
20+
}
21+
22+
flag.Parse()
23+
if flag.NArg() == 0 {
24+
flag.Usage()
25+
os.Exit(1)
26+
}
27+
28+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGHUP, syscall.SIGABRT)
29+
defer stop()
30+
err := start.Run(ctx)
31+
if err != nil && !errors.Is(err, context.Canceled) {
32+
log.Fatalf("exiting with errors %v\n", err)
33+
}
34+
35+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/lazy-electron-consulting/ve-direct-exporter
2+
3+
go 1.18

internal/start/start.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package start
2+
3+
import "context"
4+
5+
func Run(ctx context.Context) error {
6+
return nil
7+
}

0 commit comments

Comments
 (0)