Skip to content

Commit

Permalink
#74 Refactor to template
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj committed Aug 20, 2024
1 parent c3a52bf commit 332bd6f
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 139 deletions.
12 changes: 0 additions & 12 deletions .dockerignore

This file was deleted.

6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "daily"
interval: daily
- package-ecosystem: gomod
directory: /
schedule:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/go-test-darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ name: Go test darwin
on: [pull_request, workflow_dispatch]

env:
DYLD_LIBRARY_PATH: /opt/senzing/g2/lib:/opt/senzing/g2/lib/macos
LD_LIBRARY_PATH: /opt/senzing/g2/lib:/opt/senzing/g2/lib/macos
SENZING_TOOLS_DATABASE_URL: "sqlite3://na:na@nowhere/tmp/sqlite/G2C.db"
DYLD_LIBRARY_PATH: /opt/senzing/er/lib:/opt/senzing/er/lib/macos
LD_LIBRARY_PATH: /opt/senzing/er/lib:/opt/senzing/er/lib/macos

permissions:
contents: read
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/go-test-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ name: Go test linux
on: [push]

env:
LD_LIBRARY_PATH: /opt/senzing/g2/lib
SENZING_LOG_LEVEL: TRACE
SENZING_TOOLS_DATABASE_URL: sqlite3://na:na@nowhere/tmp/sqlite/G2C.db
LD_LIBRARY_PATH: /opt/senzing/er/lib

permissions:
contents: read
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/go-test-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Go test windows

on: [pull_request, workflow_dispatch]

env:
SENZING_TOOLS_DATABASE_URL: "sqlite3://na:na@nowhere/C:\\Temp\\sqlite\\G2C.db"

permissions:
contents: read

Expand Down Expand Up @@ -40,7 +37,7 @@ jobs:
senzingapi-version: ${{ matrix.senzingapi-version }}

- name: Add to "Path" environment variable
run: echo "C:\Program Files\Senzing\g2\lib" | Out-File -FilePath "$env:GITHUB_PATH" -Encoding utf8 -Append
run: echo "C:\Program Files\Senzing\er\lib" | Out-File -FilePath "$env:GITHUB_PATH" -Encoding utf8 -Append

- name: Run go test
run: |
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ jobs:
- name: Copy Senzing headers
run: |
mkdir --parents ./szconfig/gohelpers
cp /opt/senzing/g2/sdk/c/*.h ./szconfig/
cp /opt/senzing/g2/sdk/c/gohelpers/*.h ./szconfig/gohelpers
cp /opt/senzing/er/sdk/c/*.h ./szconfig/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szconfig/gohelpers
mkdir --parents ./szconfigmanager/gohelpers
cp /opt/senzing/g2/sdk/c/*.h ./szconfigmanager/
cp /opt/senzing/g2/sdk/c/gohelpers/*.h ./szconfigmanager/gohelpers
cp /opt/senzing/er/sdk/c/*.h ./szconfigmanager/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szconfigmanager/gohelpers
mkdir --parents ./szdiagnostic/gohelpers
cp /opt/senzing/g2/sdk/c/*.h ./szdiagnostic/
cp /opt/senzing/g2/sdk/c/gohelpers/*.h ./szdiagnostic/gohelpers
cp /opt/senzing/er/sdk/c/*.h ./szdiagnostic/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szdiagnostic/gohelpers
mkdir --parents ./szengine/gohelpers
cp /opt/senzing/g2/sdk/c/*.h ./szengine/
cp /opt/senzing/g2/sdk/c/gohelpers/*.h ./szengine/gohelpers
cp /opt/senzing/er/sdk/c/*.h ./szengine/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szengine/gohelpers
mkdir --parents ./szproduct/gohelpers
cp /opt/senzing/g2/sdk/c/*.h ./szproduct/
cp /opt/senzing/g2/sdk/c/gohelpers/*.h ./szproduct/gohelpers
cp /opt/senzing/er/sdk/c/*.h ./szproduct/
cp /opt/senzing/er/sdk/c/gohelpers/*.h ./szproduct/gohelpers
- name: Setup go
uses: actions/setup-go@v5
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ go.work
# Makefile
target/

.coverage
cover.out
coverage.html
coverage.out
50 changes: 30 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

Welcome to the project!

We encourage contribution in a manner consistent with the [Code of Conduct](CODE_OF_CONDUCT.md).
We encourage contribution in a manner consistent with the [Code of Conduct].
The following will guide you through the process.

There are a number of ways you can contribute:

1. [Asking questions](#questions)
1. [Requesting features](#feature-requests)
1. [Reporting bugs](#bug-reporting)
1. [Contributing code or documentation](#contributing-code-or-documentation)
1. [Asking questions]
1. [Requesting features]
1. [Reporting bugs]
1. [Contributing code or documentation]

## License Agreements

Expand All @@ -23,19 +23,19 @@ A license agreement is not needed for submitting feature request, bug reporting,
### Individual Contributor License Agreement

In order to contribute to this repository, an
[Individual Contributor License Agreement (ICLA)](.github/senzing-individual-contributor-license-agreement.pdf)
[Individual Contributor License Agreement (ICLA)]
must be completed, submitted and accepted.

### Corporate Contributor License Agreement

If the contribution to this repository is on behalf of a company, a
[Corporate Contributor License Agreement (CCLA)](.github/senzing-corporate-contributor-license-agreement.pdf)
[Corporate Contributor License Agreement (CCLA)]
must also be completed, submitted and accepted.

### Project License Agreement

The license agreement for this repository is stated in the
[LICENSE](LICENSE) file.
[LICENSE] file.

## Questions

Expand All @@ -50,7 +50,7 @@ TODO: Instead, use ???

All feature requests are "GitHub issues".
To request a feature, create a
[GitHub issue](https://help.github.com/articles/creating-an-issue/)
[GitHub issue]
in this repository.

When creating an issue, there will be a choice to create a "Bug report" or a "Feature request".
Expand All @@ -59,20 +59,17 @@ Choose "Feature request".
## Bug Reporting

All bug reports are "GitHub issues".
Before reporting on a bug, check to see if it has
[already been reported](https://github.com/search?q=+is%3Aissue+user%3Asenzing).
To report a bug, create a
[GitHub issue](https://help.github.com/articles/creating-an-issue/)
in this repository.
Before reporting on a bug, check to see if it has [already been reported].
To report a bug, create a [GitHub issue] in this repository.

When creating an issue, there will be a choice to create a "Bug report" or a "Feature request".
Choose "Bug report".

## Contributing code or documentation

To contribute code or documentation to the repository, you must have
[License Agreements](#license-agreements) in place.
This needs to be complete before a [Pull Request](#pull-requests) can be accepted.
[License Agreements] in place.
This needs to be complete before a [Pull Request] can be accepted.

### Setting up a development environment

Expand Down Expand Up @@ -116,9 +113,22 @@ TODO:
### Pull Requests

Code in the main branch is modified via GitHub pull request.
Follow GitHub's
[Creating a pull request from a branch](https://help.github.com/articles/creating-a-pull-request/)
or
[Creating a pull request from a fork](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) instructions.
Follow GitHub's [Creating a pull request from a branch] or
[Creating a pull request from a fork] instructions.

Accepting pull requests will be at the discretion of Senzing, Inc. and the repository owner(s).

[already been reported]: https://github.com/search?q=+is%3Aissue+user%3Asenzing
[Asking questions]: #questions
[Code of Conduct]: CODE_OF_CONDUCT.md
[Contributing code or documentation]: #contributing-code-or-documentation
[Corporate Contributor License Agreement (CCLA)]: .github/senzing-corporate-contributor-license-agreement.pdf
[Creating a pull request from a branch]: https://help.github.com/articles/creating-a-pull-request/
[Creating a pull request from a fork]: https://help.github.com/articles/creating-a-pull-request-from-a-fork/
[GitHub issue]: https://help.github.com/articles/creating-an-issue/
[Individual Contributor License Agreement (ICLA)]: .github/senzing-individual-contributor-license-agreement.pdf
[LICENSE]: LICENSE
[License Agreements]: #license-agreements
[Pull Request]: #pull-requests
[Reporting bugs]: #bug-reporting
[Requesting features]: #feature-requests
56 changes: 33 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Makefile for go-cmdhelping.
# Makefile for Go project

# Detect the operating system and architecture.

Expand All @@ -15,13 +15,13 @@ PROGRAM_NAME := $(shell basename `git rev-parse --show-toplevel`)
MAKEFILE_PATH := $(abspath $(firstword $(MAKEFILE_LIST)))
MAKEFILE_DIRECTORY := $(shell dirname $(MAKEFILE_PATH))
TARGET_DIRECTORY := $(MAKEFILE_DIRECTORY)/target
DOCKER_CONTAINER_NAME := $(PROGRAM_NAME)
DOCKER_IMAGE_NAME := senzing/$(PROGRAM_NAME)
DOCKER_BUILD_IMAGE_NAME := $(DOCKER_IMAGE_NAME)-build
BUILD_VERSION := $(shell git describe --always --tags --abbrev=0 --dirty | sed 's/v//')
DIST_DIRECTORY := $(MAKEFILE_DIRECTORY)/dist
BUILD_TAG := $(shell git describe --always --tags --abbrev=0 | sed 's/v//')
BUILD_ITERATION := $(shell git log $(BUILD_TAG)..HEAD --oneline | wc -l | sed 's/^ *//')
BUILD_VERSION := $(shell git describe --always --tags --abbrev=0 --dirty | sed 's/v//')
GIT_REMOTE_URL := $(shell git config --get remote.origin.url)
GIT_REPOSITORY_NAME := $(shell basename `git rev-parse --show-toplevel`)
GIT_VERSION := $(shell git describe --always --tags --long --dirty | sed -e 's/\-0//' -e 's/\-g.......//')
GO_PACKAGE_NAME := $(shell echo $(GIT_REMOTE_URL) | sed -e 's|^git@github.com:|github.com/|' -e 's|\.git$$||' -e 's|Senzing|senzing|')
PATH := $(MAKEFILE_DIRECTORY)/bin:$(PATH)

Expand All @@ -33,9 +33,10 @@ GO_ARCH = $(word 2, $(GO_OSARCH))

# Conditional assignment. ('?=')
# Can be overridden with "export"
# Example: "export LD_LIBRARY_PATH=/path/to/my/senzing/er/lib"

LD_LIBRARY_PATH ?= /opt/senzing/g2/lib
GOBIN ?= $(shell go env GOPATH)/bin
LD_LIBRARY_PATH ?= /opt/senzing/er/lib

# Export environment variables.

Expand Down Expand Up @@ -63,10 +64,11 @@ hello-world: hello-world-osarch-specific
# Dependency management
# -----------------------------------------------------------------------------

.PHONY: dependencies-for-make
dependencies-for-make:
.PHONY: dependencies-for-development
dependencies-for-development:
@go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
@go install github.com/vladopajic/go-test-coverage/v2@latest
@go install golang.org/x/tools/cmd/godoc@latest
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.58.1


Expand All @@ -88,22 +90,29 @@ setup: setup-osarch-specific
# -----------------------------------------------------------------------------

.PHONY: lint
lint:
@${GOBIN}/golangci-lint run --config=.github/linters/.golangci.yaml
lint: golangci-lint

# -----------------------------------------------------------------------------
# Build
# -----------------------------------------------------------------------------

PLATFORMS := darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64 windows/arm64
$(PLATFORMS):
@echo Building $(TARGET_DIRECTORY)/$(GO_OS)-$(GO_ARCH)/$(PROGRAM_NAME)
$(info Building $(TARGET_DIRECTORY)/$(GO_OS)-$(GO_ARCH)/$(PROGRAM_NAME))
@GOOS=$(GO_OS) GOARCH=$(GO_ARCH) go build -o $(TARGET_DIRECTORY)/$(GO_OS)-$(GO_ARCH)/$(PROGRAM_NAME)


.PHONY: build
build: build-osarch-specific


# -----------------------------------------------------------------------------
# Run
# -----------------------------------------------------------------------------

.PHONY: run
run: run-osarch-specific

# -----------------------------------------------------------------------------
# Test
# -----------------------------------------------------------------------------
Expand All @@ -122,15 +131,8 @@ coverage: coverage-osarch-specific
.PHONY: check-coverage
check-coverage: export SENZING_LOG_LEVEL=TRACE
check-coverage:
go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
${GOBIN}/go-test-coverage --config=.github/coverage/.testcoverage.yaml

# -----------------------------------------------------------------------------
# Run
# -----------------------------------------------------------------------------

.PHONY: run
run: run-osarch-specific
@go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
@${GOBIN}/go-test-coverage --config=.github/coverage/testcoverage.yaml

# -----------------------------------------------------------------------------
# Documentation
Expand All @@ -154,19 +156,27 @@ clean: clean-osarch-specific

.PHONY: help
help:
@echo "Build $(PROGRAM_NAME) version $(BUILD_VERSION)-$(BUILD_ITERATION)".
@echo "Makefile targets:"
$(info Build $(PROGRAM_NAME) version $(BUILD_VERSION)-$(BUILD_ITERATION))
$(info Makefile targets:)
@$(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs


.PHONY: print-make-variables
print-make-variables:
@$(foreach V,$(sort $(.VARIABLES)), \
$(if $(filter-out environment% default automatic, \
$(origin $V)),$(warning $V=$($V) ($(value $V)))))
$(origin $V)),$(info $V=$($V) ($(value $V)))))


.PHONY: update-pkg-cache
update-pkg-cache:
@GOPROXY=https://proxy.golang.org GO111MODULE=on \
go get $(GO_PACKAGE_NAME)@$(BUILD_TAG)

# -----------------------------------------------------------------------------
# Specific programs
# -----------------------------------------------------------------------------

.PHONY: golangci-lint
golangci-lint:
@${GOBIN}/golangci-lint run --config=.github/linters/.golangci.yaml
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ the recommendation is not to use it yet.

`go-cmdhelping` contains utility packages for working with [viper] and [cobra].

[![Go Reference](https://pkg.go.dev/badge/github.com/senzing-garage/go-cmdhelping.svg)](https://pkg.go.dev/github.com/senzing-garage/go-cmdhelping)
[![Go Report Card](https://goreportcard.com/badge/github.com/senzing-garage/go-cmdhelping)](https://goreportcard.com/report/github.com/senzing-garage/go-cmdhelping)
[![License](https://img.shields.io/badge/License-Apache2-brightgreen.svg)](https://github.com/senzing-garage/go-cmdhelping/blob/main/LICENSE)
[![Go Reference Badge]][Package reference]
[![Go Report Card Badge]][Go Report Card]
[![License Badge]][License]
[![go-test-linux.yaml Badge]][go-test-linux.yaml]
[![go-test-darwin.yaml Badge]][go-test-darwin.yaml]
[![go-test-windows.yaml Badge]][go-test-windows.yaml]

[![go-test-linux.yaml](https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-linux.yaml/badge.svg)](https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-linux.yaml)
[![go-test-darwin.yaml](https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-darwin.yaml/badge.svg)](https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-darwin.yaml)
[![go-test-windows.yaml](https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-windows.yaml/badge.svg)](https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-windows.yaml)
[![golangci-lint.yaml Badge]][golangci-lint.yaml]

## Overview

Expand Down Expand Up @@ -52,9 +53,23 @@ See [main.go] for an example of use.
[Development]: docs/development.md
[Errors]: docs/errors.md
[Examples]: docs/examples.md
[Go Reference Badge]: https://pkg.go.dev/badge/github.com/senzing-garage/go-cmdhelping.svg
[Go Report Card Badge]: https://goreportcard.com/badge/github.com/senzing-garage/go-cmdhelping
[Go Report Card]: https://goreportcard.com/report/github.com/senzing-garage/go-cmdhelping
[go-test-darwin.yaml Badge]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-darwin.yaml/badge.svg
[go-test-darwin.yaml]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-darwin.yaml
[go-test-linux.yaml Badge]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-linux.yaml/badge.svg
[go-test-linux.yaml]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-linux.yaml
[go-test-windows.yaml Badge]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-windows.yaml/badge.svg
[go-test-windows.yaml]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/go-test-windows.yaml
[golangci-lint.yaml Badge]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/golangci-lint.yaml/badge.svg
[golangci-lint.yaml]: https://github.com/senzing-garage/go-cmdhelping/actions/workflows/golangci-lint.yaml
[License Badge]: https://img.shields.io/badge/License-Apache2-brightgreen.svg
[License]: https://github.com/senzing-garage/go-cmdhelping/blob/main/LICENSE
[main.go]: main.go
[option.ContextVariable]: option/option.go
[Senzing Garage]: https://github.com/senzing-garage-garage
[Senzing Quick Start guides]: https://docs.senzing.com/quickstart/
[Senzing]: https://senzing.com/
[viper]: https://github.com/spf13/viper
[Package reference]: https://pkg.go.dev/github.com/senzing-garage/go-cmdhelping
Loading

0 comments on commit 332bd6f

Please sign in to comment.