diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..82dd251 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,36 @@ +{ + "name": "enumflag", + "portsAttributes": { + "6060": { + "label": "enumflag package documentation", + "onAutoForward": "notify", + "protocol": "http" + } + }, + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + "features": { + "ghcr.io/thediveo/devcontainer-features/local-pkgsite:0": {}, + "ghcr.io/thediveo/devcontainer-features/goreportcard:0": {}, + "ghcr.io/thediveo/devcontainer-features/go-mod-upgrade:0": {}, + "ghcr.io/thediveo/devcontainer-features/gocover:0": { + "num-programs": "1", + "race": true, + "verbose": true, + "html": true + } + }, + "remoteEnv": { + "GOPATH": "/home/vscode/go", + "PATH": "/home/vscode/go/bin:/go/bin:/usr/local/go/bin:${localEnv:PATH}" + }, + "customizations": { + "vscode": { + "extensions": [ + "stkb.rewrap", + "brunnerh.insert-unicode", + "mhutchie.git-graph", + "ms-vscode.makefile-tools" + ] + } + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 06512ba..a4c5444 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -45,40 +45,6 @@ "kind": "build", "isDefault": true } - }, - { - "label": "View Go module documentation", - "dependsOrder": "parallel", - "dependsOn": [ - "don't Run Task this! -- pkgsite service", - "don't Run Task this! -- view pkgsite" - ], - "problemMatcher": [] - }, - { - "label": "don't Run Task this! -- view pkgsite", - "command": "${input:pkgsite}", - }, - { - "label": "don't Run Task this! -- pkgsite service", - "type": "shell", - "command": "${workspaceFolder}/scripts/pkgsite.sh", - "presentation": { - "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared", - "showReuseMessage": false, - "close": true, - } - } - ], - "inputs": [ - { - "id": "pkgsite", - "type": "command", - "command": "simpleBrowser.api.open", - "args": "http://localhost:6060/github.com/thediveo/enumflag/v2" } ] } \ No newline at end of file diff --git a/Makefile b/Makefile index 68f1ce7..bb0ce6d 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,13 @@ help: ## list available targets clean: ## cleans up build and testing artefacts rm -f coverage.* -coverage: ## gathers coverage and updates README badge - @scripts/cov.sh - -pkgsite: ## serves Go documentation on port 6060 - @echo "navigate to: http://localhost:6060/github.com/thediveo/enumflag/v2" - @scripts/pkgsite.sh - -report: ## run goreportcard on this module - @scripts/goreportcard.sh - test: ## run unit tests go test -v -p=1 -race ./... -vuln: ## runs govulncheck - @scripts/vuln.sh +report: ## run goreportcard-cli on this module +# from ghcr.io/thediveo/devcontainer-features/goreportcard + goreportcard-cli -v ./.. -chores: ## updates Go binaries and NPM helper packages if necessary - @scripts/chores.sh +coverage: ## gathers coverage and updates README badge +# from ghcr.io/thediveo/devcontainer-features/gocover + gocover diff --git a/README.md b/README.md index a938e7a..650a5cc 100644 --- a/README.md +++ b/README.md @@ -344,14 +344,23 @@ func Example_slice() { } ``` +## DevContainer + +First method: + +1. in VSCode: Ctrl+Shift+P, "Dev Containers: Open Workspace in Container..." +2. select `enumflag.code-workspace` and off you go... + +Second method: + +1. In VSCode: Ctrl+Shift+P, "Dev Containers: Clone Repository in Container Volume..." +2. select "Github" +3. enter "thediveo/enumflag" and off you go... + ## VSCode Tasks The included `enumflag.code-workspace` defines the following tasks: -- **View Go module documentation** task: installs `pkgsite`, if not done already - so, then starts `pkgsite` and opens VSCode's integrated ("simple") browser to - show the go-plugger/v2 documentation. - - **Build workspace** task: builds all, including the shared library test plugin. @@ -374,18 +383,12 @@ The included `enumflag.code-workspace` defines the following tasks: ## Make Targets -- `make`: lists all targets. -- `make coverage`: runs all tests with coverage and then **updates the coverage - badge in `README.md`**. -- `make pkgsite`: installs [`x/pkgsite`](golang.org/x/pkgsite/cmd/pkgsite), as - well as the [`browser-sync`](https://www.npmjs.com/package/browser-sync) and - [`nodemon`](https://www.npmjs.com/package/nodemon) npm packages first, if not - already done so. Then runs the `pkgsite` and hot reloads it whenever the - documentation changes. -- `make report`: installs - [`@gojp/goreportcard`](https://github.com/gojp/goreportcard) if not yet done - so and then runs it on the code base. +- `make`: lists available targets. - `make test`: runs all tests. +- `make coverage`: deprecated, use the `gocover` CLI command in the devcontainer + instead. +- `make report`: deprecated, use the `goreportcard-cli` CLI command in the + devcontainer instead. ## Contributing @@ -393,5 +396,5 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md). ## Copyright and License -`lxkns` is Copyright 2020, 2023 Harald Albrecht, and licensed under the Apache +`lxkns` is Copyright 2020, 2025 Harald Albrecht, and licensed under the Apache License, Version 2.0. diff --git a/scripts/chores.sh b/scripts/chores.sh deleted file mode 100755 index 21fe3da..0000000 --- a/scripts/chores.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -e - -echo "checking pkgsite..." -go install golang.org/x/pkgsite/cmd/pkgsite@latest - -echo "checking govulncheck..." -go install golang.org/x/vuln/cmd/govulncheck@latest - -echo "checking gobadge..." -go install github.com/AlexBeauchemin/gobadge@latest - -echo "checking goreportcard and friends..." -GOREPORTCARDTMPDIR="$(mktemp -d)" -trap 'rm -rf -- "$GOREPORTCARDTMPDIR"' EXIT -git clone https://github.com/gojp/goreportcard.git "$GOREPORTCARDTMPDIR" -(cd "$GOREPORTCARDTMPDIR" && make install && go install ./cmd/goreportcard-cli) -go install github.com/gordonklaus/ineffassign@latest -go install github.com/client9/misspell/cmd/misspell@latest - -echo "checking pkgsite NPM helpers..." -(cd $HOME && npm update --silent browser-sync) -(cd $HOME && npm update --silent nodemon) diff --git a/scripts/cov.sh b/scripts/cov.sh deleted file mode 100755 index e5c51a9..0000000 --- a/scripts/cov.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -e - -if ! command -v gobadge &>/dev/null; then - export PATH="$(go env GOPATH)/bin:$PATH" - if ! command -v gobadge &>/dev/null; then - go install github.com/AlexBeauchemin/gobadge@latest - fi -fi - -# As of Go 1.20 (and later) we now use the new coverage profiling support that -# also *cough* covers integration tests (even if this particular project might -# not use the latter). The benefit of this slightly more involved approach is -# that we don't need external coverage profile file processing tools anymore, -# but can achieve our goal with just using the standard Go toolchain. - -# First, we set up a temporary directory to receive the coverage (binary) -# files... -GOCOVERTMPDIR="$(mktemp -d)" -trap 'rm -rf -- "$GOCOVERTMPDIR"' EXIT -# Now run the (unit) tests with coverage, but don't use the existing textual -# format and instead tell "go test" to produce the new binary coverage data file -# format. This way we can easily run multiple coverage (integration) tests, as -# needed, without worrying about how to aggregate the coverage data later. The -# new Go toolchain already does this for us. -go test -cover -v -p=1 -count=1 -race ./... -args -test.gocoverdir="$GOCOVERTMPDIR" -# Finally transform the coverage information collected in potentially multiple -# runs into the well-proven textual format so we can process it as we have come -# to learn and love. -go tool covdata textfmt -i="$GOCOVERTMPDIR" -o=coverage.out -go tool cover -html=coverage.out -o=coverage.html -go tool cover -func=coverage.out -o=coverage.out -gobadge -filename=coverage.out -green=80 -yellow=50 diff --git a/scripts/goreportcard.sh b/scripts/goreportcard.sh deleted file mode 100755 index 26adee5..0000000 --- a/scripts/goreportcard.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -set -e - -if ! command -v goreportcard-cli &>/dev/null; then - export PATH="$(go env GOPATH)/bin:$PATH" - if ! command -v goreportcard-cli &>/dev/null; then - rm -rf /tmp/goreportcard || true - git clone https://github.com/gojp/goreportcard.git /tmp/goreportcard - (cd /tmp/goreportcard && make install && go install ./cmd/goreportcard-cli) - rm -rf /tmp/goreportcard || true - # Install a somewhat recent ineffassign over the totally outdated one - # that goreportcard still insists of infecting the system with. - go install github.com/gordonklaus/ineffassign@latest - # Install the missing misspell, oh well... - go install github.com/client9/misspell/cmd/misspell@latest - fi -fi - -goreportcard-cli -v ./... diff --git a/scripts/pkgsite.sh b/scripts/pkgsite.sh deleted file mode 100755 index 88c0e7a..0000000 --- a/scripts/pkgsite.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -e - -if ! command -v pkgsite &>/dev/null; then - export PATH="$(go env GOPATH)/bin:$PATH" - if ! command -v pkgsite &>/dev/null; then - go install golang.org/x/pkgsite/cmd/pkgsite@master - fi -fi - -# In case the user hasn't set an explicit installation location, avoid polluting -# our own project... -npm list --depth=0 browser-sync &>/dev/null || \ - (cd $HOME && npm install browser-sync) - -npm list --depth=0 nodemon &>/dev/null || \ - (cd $HOME && npm install nodemon) - -# https://stackoverflow.com/a/2173421 -trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT - -# https://mdaverde.com/posts/golang-local-docs -npm exec -- browser-sync start --port 6060 --proxy localhost:6061 --reload-delay 2000 --reload-debounce 5000 --no-ui --no-open & -PKGSITE=$(which pkgsite) -npm exec -- nodemon --signal SIGTERM --watch './**/*' -e go --exec "browser-sync --port 6060 reload && $PKGSITE -http=localhost:6061 ." diff --git a/scripts/vuln.sh b/scripts/vuln.sh deleted file mode 100755 index 1aaf917..0000000 --- a/scripts/vuln.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -e - -if ! command -v govulncheck &>/dev/null; then - export PATH="$(go env GOPATH)/bin:$PATH" - if ! command -v govulncheck &>/dev/null; then - echo "installing govulncheck..." - go install golang.org/x/vuln/cmd/govulncheck@latest - fi -fi -if [[ $(find "$(go env GOPATH)/bin/govulncheck" -mtime +1 -print) ]]; then - echo "updating govulncheck to @latest..." - go install golang.org/x/vuln/cmd/govulncheck@latest -fi - -govulncheck ./...