refactor: Project directories (#541)

This commit is contained in:
James Read 2025-03-22 01:06:59 +00:00 committed by GitHub
parent b4c886d5d3
commit ff31abe66c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
76 changed files with 100 additions and 73 deletions

View File

@ -1,6 +1,9 @@
name: Buf CI
on:
push:
paths:
- 'proto/**'
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
delete:
@ -16,13 +19,16 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: 'service/go.mod'
cache: true
- name: grpc
run: make -w grpc
- uses: bufbuild/buf-action@v1
- name: make service
run: make -w service
- uses: bufbuild/buf-action@v1.1.0
with:
token: ${{ secrets.BUF_TOKEN }}
# Change setup_only to true if you only want to set up the Action and not execute other commands.

View File

@ -31,7 +31,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: 'service/go.mod'
cache: true
- name: Print go version
@ -40,14 +40,14 @@ jobs:
- name: grpc
run: make -w grpc
- name: make daemon
run: make -w daemon-compile-x64-lin
- name: make service
run: make -w service
- name: make webui
run: make -w webui-dist
- name: unit tests
run: make -w daemon-unittests
run: make -w service-unittests
- name: integration tests
run: cd integration-tests && make -w

View File

@ -31,7 +31,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: 'service/go.mod'
cache: true
- name: Print go version

View File

@ -47,7 +47,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: 'service/go.mod'
cache: true
- name: grpc

View File

@ -21,7 +21,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: 'service/go.mod'
cache: true
- name: Print go version

10
.gitignore vendored
View File

@ -1,10 +1,10 @@
**/*.swp
**/*.swo
gen/
/OliveTin
/OliveTin.armhf
/OliveTin.exe
reports
service/gen/
service/OliveTin
service/OliveTin.armhf
service/OliveTin.exe
service/reports
releases/
dist/
installation-id.txt

View File

@ -2,12 +2,14 @@ project_name: OliveTin
version: 2
before:
hooks:
- go mod download
- go generate ./...
- make service-prep
builds:
- env:
- CGO_ENABLED=0
binary: OliveTin
main: main.go
dir: service
goos:
- linux
- windows
@ -25,8 +27,6 @@ builds:
- 6
- 7
main: cmd/OliveTin/main.go
ignore:
- goos: darwin
goarch: arm # Mac does not work on [32bit] arm

View File

@ -2,52 +2,22 @@ define delete-files
python -c "import shutil;shutil.rmtree('$(1)', ignore_errors=True)"
endef
compile: daemon-compile-currentenv
service:
$(MAKE) -wC service
daemon-compile-currentenv:
go build github.com/OliveTin/OliveTin/cmd/OliveTin
daemon-compile-armhf:
go env -w GOARCH=arm GOARM=6
go build -o OliveTin.armhf github.com/OliveTin/OliveTin/cmd/OliveTin
go env -u GOARCH GOARM
daemon-compile-x64-lin:
go env -w GOOS=linux
go build -o OliveTin github.com/OliveTin/OliveTin/cmd/OliveTin
go env -u GOOS
daemon-compile-x64-win:
go env -w GOOS=windows GOARCH=amd64
go build -o OliveTin.exe github.com/OliveTin/OliveTin/cmd/OliveTin
go env -u GOOS GOARCH
daemon-compile: daemon-compile-armhf daemon-compile-x64-lin daemon-compile-x64-win
daemon-codestyle:
go fmt ./...
go vet ./...
gocyclo -over 4 cmd internal
gocritic check ./...
daemon-unittests:
$(call delete-files,reports)
mkdir reports
go test ./... -coverprofile reports/unittests.out
go tool cover -html=reports/unittests.out -o reports/unittests.html
service-prep:
$(MAKE) -wC service prep
service-unittests:
$(MAKE) -wC service unittests
it:
cd integration-tests && make
$(MAKE) -wC integration-tests
go-tools:
go install "github.com/bufbuild/buf/cmd/buf"
go install "github.com/fzipp/gocyclo/cmd/gocyclo"
go install "github.com/go-critic/go-critic/cmd/gocritic"
go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
go install "google.golang.org/protobuf/cmd/protoc-gen-go"
$(MAKE) -wC service go-tools
proto: grpc
grpc: go-tools
$(MAKE) -wC proto
@ -98,4 +68,4 @@ clean:
$(call delete-files,reports)
$(call delete-files,gen)
.PHONY: grpc
.PHONY: grpc proto service

View File

@ -1,3 +0,0 @@
//go:generate make grpc
package main

View File

@ -35,10 +35,10 @@ class OliveTinTestRunnerStartLocalProcess extends OliveTinTestRunner {
async start (cfg) {
let stdout = ""
let stderr = ""
console.log(" OliveTin starting local process...")
this.ot = spawn('./../OliveTin', ['-configdir', 'configs/' + cfg + '/'])
this.ot = spawn('./../service/OliveTin', ['-configdir', 'configs/' + cfg + '/'])
let logStdout = false

View File

@ -1,15 +1,15 @@
version: v1
plugins:
- name: go
out: ../gen/grpc/
out: ../service/gen/grpc/
opt: paths=source_relative
- name: go-grpc
out: ../gen/grpc/
out: ../service/gen/grpc/
opt: paths=source_relative,require_unimplemented_servers=false
- name: grpc-gateway
out: ../gen/grpc/
out: ../service/gen/grpc/
opt: paths=source_relative
# - name: swagger

View File

@ -1,6 +1,8 @@
# Generated by buf. DO NOT EDIT.
version: v2
version: v1
deps:
- name: buf.build/googleapis/googleapis
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 751cbe31638d43a9bfb6162cd2352e67
digest: b5:51ba5c31f244fd74420f0e66d13f2b5dd6024dcfe1a29dc45bd8f6e61c1444c828b9add9e7dd25a4513ebbee8097a970e0712a2e2cd955c2d60cf8905204f51a
digest: shake256:87f55470d9d124e2d1dedfe0231221f4ed7efbc55bc5268917c678e2d9b9c41573a7f9a557f6d8539044524d9fc5ca8fbb7db05eb81379d168285d76b57eb8a4

View File

@ -1,4 +1,4 @@
version: v2
version: v1
deps:
- buf.build/googleapis/googleapis
lint:

View File

@ -5,7 +5,7 @@ tmp_dir = "tmp"
[build]
args_bin = []
bin = "./OliveTin"
cmd = "go build -o OliveTin github.com/OliveTin/OliveTin/cmd/OliveTin"
cmd = "go build -o OliveTin"
delay = 1
exclude_dir = ["assets", "tmp", "vendor", "testdata", "webui.dev", "webui"]
exclude_file = []

48
service/Makefile Normal file
View File

@ -0,0 +1,48 @@
define delete-files
python -c "import shutil;shutil.rmtree('$(1)', ignore_errors=True)"
endef
compile-currentenv:
go build
prep:
go mod download
go generate ./...
compile-armhf:
go env -w GOARCH=arm GOARM=6
go build -o OliveTin.armhf
go env -u GOARCH GOARM
compile-x64-lin:
go env -w GOOS=linux
go build -o OliveTin
go env -u GOOS
compile-x64-win:
go env -w GOOS=windows GOARCH=amd64
go build -o OliveTin.exe
go env -u GOOS GOARCH
compile: compile-armhf compile-x64-lin compile-x64-win
codestyle:
go fmt ./...
go vet ./...
gocyclo -over 4 internal
gocritic check ./...
unittests:
$(call delete-files,reports)
mkdir reports
go test ./... -coverprofile reports/unittests.out
go tool cover -html=reports/unittests.out -o reports/unittests.html
go-tools:
go install "github.com/bufbuild/buf/cmd/buf"
go install "github.com/fzipp/gocyclo/cmd/gocyclo"
go install "github.com/go-critic/go-critic/cmd/gocritic"
go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
go install "google.golang.org/protobuf/cmd/protoc-gen-go"

3
service/generate.go Normal file
View File

@ -0,0 +1,3 @@
//go:generate make -wC ../
package main

View File

@ -14,5 +14,5 @@ func TestGetWebuiDir(t *testing.T) {
dir := findWebuiDir()
assert.Equal(t, "./webui", dir, "Finding the webui dir")
assert.Equal(t, "../webui/", dir, "Finding the webui dir")
}

View File

@ -108,6 +108,7 @@ func initViperConfig(configDir string) {
viper.SetConfigName("config.yaml")
viper.SetConfigType("yaml")
viper.AddConfigPath(configDir)
viper.AddConfigPath("../")
viper.AddConfigPath("/config") // For containers.
viper.AddConfigPath("/etc/OliveTin/")