diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml new file mode 100644 index 0000000..5c286ad --- /dev/null +++ b/.github/workflows/goreleaser.yaml @@ -0,0 +1,26 @@ +name: goreleaser + +on: + push: + tags: + - 'v*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.21.x + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{secrets.GH_GOREL}} diff --git a/.github/workflows/run_checks.yaml b/.github/workflows/run_checks.yaml new file mode 100644 index 0000000..0603acd --- /dev/null +++ b/.github/workflows/run_checks.yaml @@ -0,0 +1,32 @@ +name: run_checks + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - run: sudo apt-get install pcre2-utils + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.22' + + - run: go install github.com/gordonklaus/ineffassign@latest + - run: go install honnef.co/go/tools/cmd/staticcheck@latest + - run: go install github.com/client9/misspell/cmd/misspell@latest + - run: go install github.com/fzipp/gocyclo/cmd/gocyclo@latest + - run: go install github.com/google/addlicense@latest + - run: wget https://github.com/go-task/task/releases/download/v3.36.0/task_linux_amd64.deb + - run: sudo dpkg -i task_linux_amd64.deb + - run: rm task_linux_amd64.deb + - run: task check + diff --git a/.gitignore b/.gitignore index 37501c7..eb53b56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .* !/.gitignore +!/.github +!/.goreleaser.yaml /build +/dist # Added by vscode's C# extension /go-ldlm.sln diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..887918e --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,60 @@ +builds: + - binary: ldlm-lock + id: ldlm-lock + main: ./cmd/lock + targets: + - "windows_amd64" + - "linux_amd64" + - "linux_arm64" + - "darwin_amd64" + - "darwin_arm64" + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + - binary: ldlm-server + id: ldlm-server + main: ./cmd/server + targets: + - "windows_amd64" + - "linux_amd64" + - "linux_arm64" + - "darwin_amd64" + - "darwin_arm64" + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + + +gomod: + proxy: true + +archives: + - name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}" + files: + - README.md + - LICENSE + - examples/ + format_overrides: + - goos: windows + format: zip + +release: + draft: true + +snapshot: + name_template: "{{.Tag}}" + +checksum: + name_template: "ldlm_checksums.txt" + +nfpms: + - vendor: imoore76@yahoo.com + homepage: https://github.com/imoore76/go-ldlm + maintainer: Ian Moore + description: Light weight Distributed Lock Manager server implemented over gRPC + license: Apache 2.0 + formats: + - deb + - rpm + file_name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}" + diff --git a/cmd/server/main.go b/cmd/server/main.go index 2c289e2..52d8bdb 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -32,10 +32,13 @@ import ( // Configurature struct for app configuration type Config struct { ConfigFile config.File `desc:"Path to yaml configuration file" default:"" short:"c"` + Version bool `desc:"Show version and exit" default:"false"` constants.LogLevelConfig server.ServerConfig } +var Version string + func main() { conf := config.Configure[Config](&config.Options{ @@ -43,6 +46,11 @@ func main() { Args: os.Args[1:], }) + if conf.Version { + fmt.Printf("Version: %s\n", Version) + os.Exit(0) + } + log.SetLevel(conf.LogLevel) if stopper, err := server.Run(&conf.ServerConfig); err != nil { diff --git a/examples/config/ldlm-config.ini b/examples/config/ldlm-config.ini deleted file mode 100644 index 86d64b5..0000000 --- a/examples/config/ldlm-config.ini +++ /dev/null @@ -1,4 +0,0 @@ -listen_address = "0.0.0.0:4000" -lock_gc_interval = "60m" -lock_gc_min_idle = "10m" -log_level = info diff --git a/taskfile.yaml b/taskfile.yaml index bc36684..f9d42ae 100644 --- a/taskfile.yaml +++ b/taskfile.yaml @@ -179,7 +179,7 @@ tasks: license_headers: desc: "Make sure source files have headers" cmds: - - addlicense -check -ignore **/.* ./ + - addlicense -check -ignore '**/.*' -ignore '.*/**' ./ add_license_headers: desc: "Make sure source files have headers" @@ -187,7 +187,7 @@ tasks: preconditions: - test "{{.CLI_ARGS}}" != "" cmds: - - addlicense -ignore **/.* ./ {{.CLI_ARGS}} + - addlicense -ignore '**/.*' -ignore '.*/**' ./ {{.CLI_ARGS}} check_readme_google: desc: "Make sure README.md has common items"