Skip to content

Commit 6023ca4

Browse files
authored
Merge pull request #77 from metal3d/develop
Merge Develop to prepare V3
2 parents 10b9342 + e0c829c commit 6023ca4

File tree

179 files changed

+10349
-4867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+10349
-4867
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ root = true
44
indent_style=tab
55
indent_size=4
66

7+
[*.md]
8+
trim_trailing_whitespace = false
9+
indent_style = space
10+
indent_size = 4
11+

.github/workflows/go-test.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Go-Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
push:
8+
branches:
9+
- master
10+
- develop
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: 1.21
20+
- name: Install Helm
21+
run: |
22+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
23+
chmod 700 get_helm.sh
24+
./get_helm.sh
25+
- name: Launch Test
26+
run: |
27+
go vet ./... && go test -coverprofile=coverprofile.out -json -v ./... > gotest.json
28+
- name: SonarCloud Scan
29+
uses: SonarSource/sonarcloud-github-action@master
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
33+
- name: Upload coverage reports to Codecov
34+
uses: codecov/codecov-action@v4.0.1
35+
with:
36+
token: ${{ secrets.CODECOV_TOKEN }}
37+
slug: metal3d/katenary
38+
file: ./coverprofile.out
39+
fail_ci_if_error: true
40+

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
.venv
12
dist/*
23
.cache/*
34
chart/*
45
*.yaml
56
*.yml
7+
!.markdownlint.yaml
8+
!generator/*.yaml
9+
doc/venv/*
610
!doc/mkdocs.yaml
711
!.readthedocs.yaml
812
./katenary
@@ -12,3 +16,10 @@ docker-compose*
1216
.credentials
1317
release.id
1418
configs/
19+
cover*
20+
.sq
21+
./katenary
22+
.aider*
23+
.python_history
24+
.bash_history
25+
katenary

.gitmodules

Whitespace-only changes.

.markdownlint.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# markdownlint configuration file
2+
default: true
3+
4+
MD013: # Line length
5+
line_length: 240
6+
7+
MD010: # Hard tabs
8+
code_blocks: false
9+
10+
# no inline HTML
11+
MD033: false
12+
13+
# heading as first line element...
14+
MD041: false
15+
16+
# list indentation
17+
MD007:
18+
indent: 4

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Patrice Ferlet
3+
Copyright (c) 2022-2024 Patrice Ferlet
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

+108-38
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,53 @@ VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo
44
CTN:=$(shell which podman 2>&1 1>/dev/null && echo "podman" || echo "docker")
55
PREFIX=~/.local
66

7+
GOVERSION=1.22
78
GO=container
89
OUT=katenary
9-
BLD_CMD=go build -ldflags="-X 'main.Version=$(VERSION)'" -o $(OUT) ./cmd/katenary/*.go
10+
BLD_CMD=go build -ldflags="-X 'katenary/generator.Version=$(VERSION)'" -o $(OUT) ./cmd/katenary
1011
GOOS=linux
1112
GOARCH=amd64
13+
SIGNER=metal3d@gmail.com
14+
15+
BUILD_IMAGE=docker.io/golang:$(GOVERSION)-alpine
16+
# SHELL=/bin/bash
17+
18+
# List of source files
19+
SOURCES=$(wildcard ./*.go ./*/*.go ./*/*/*.go)
20+
# List of binaries to build and sign
21+
BINARIES=dist/katenary-linux-amd64 dist/katenary-linux-arm64 dist/katenary.exe dist/katenary-darwin-amd64 dist/katenary-freebsd-amd64 dist/katenary-freebsd-arm64
22+
# List of signatures to build
23+
ASC_BINARIES=$(patsubst %,%.asc,$(BINARIES))
24+
25+
# defaults
26+
BROWSER=$(shell command -v epiphany || echo xdg-open)
27+
SHELL := bash
28+
# strict mode
29+
.SHELLFLAGS := -eu -o pipefail -c
30+
# One session per target
31+
.ONESHELL:
32+
.DELETE_ON_ERROR:
33+
MAKEFLAGS += --warn-undefined-variables
34+
MAKEFLAGS += --no-builtin-rules
35+
.PHONY: help clean build install tests test
1236

13-
BUILD_IMAGE=docker.io/golang:1.18-alpine
37+
all: build
1438

15-
.PHONY: help clean build
1639

17-
.ONESHELL:
1840
help:
19-
@cat <<EOF
41+
@cat <<EOF | fold -s -w 80
2042
=== HELP ===
2143
To avoid you to install Go, the build is made by podman or docker.
2244

23-
You can use:
45+
Installinf (you can use local Go by setting GO=local)):
46+
# use podman or docker to build
2447
$$ make install
48+
# or use local Go
49+
$$ make install GO=local
2550
This will build and install katenary inside the PREFIX(/bin) value (default is $(PREFIX))
2651

27-
To change the PREFIX to somewhere where only root or sudo users can save the binary, it is recommended to build before install:
52+
53+
To change the PREFIX to somewhere where only root or sudo users can save the binary, it is recommended to build before install, one more time you can use local Go by setting GO=local:
2854
$$ make build
2955
$$ sudo make install PREFIX=/usr/local
3056

@@ -47,29 +73,47 @@ help:
4773
$$ make build-all
4874
EOF
4975

50-
build: pull katenary
5176

52-
build-all:
53-
rm -f dist/*
54-
$(MAKE) _build-all
55-
56-
_build-all: pull dist dist/katenary-linux-amd64 dist/katenary-linux-arm64 dist/katenary.exe dist/katenary-darwin-amd64 dist/katenary-freebsd-amd64 dist/katenary-freebsd-arm64
77+
## Standard build
78+
build: pull katenary
5779

5880
pull:
5981
ifneq ($(GO),local)
6082
@echo -e "\033[1;32mPulling $(BUILD_IMAGE) docker image\033[0m"
6183
@$(CTN) pull $(BUILD_IMAGE)
6284
endif
6385

64-
dist:
86+
katenary: $(SOURCES) Makefile go.mod go.sum
87+
ifeq ($(GO),local)
88+
@echo "=> Build on host using go"
89+
else
90+
@echo "=> Build in container using" $(CTN)
91+
endif
92+
echo $(BLD_CMD)
93+
ifeq ($(GO),local)
94+
$(BLD_CMD)
95+
else ifeq ($(CTN),podman)
96+
@podman run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \
97+
--rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --userns keep-id -it $(BUILD_IMAGE) $(BLD_CMD)
98+
else
99+
@docker run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \
100+
--rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --user $(shell id -u):$(shell id -g) -e HOME=/tmp -it $(BUILD_IMAGE) $(BLD_CMD)
101+
endif
102+
echo "=> Stripping if possible"
103+
strip $(OUT) 2>/dev/null || echo "=> No strip available"
104+
105+
106+
## Release build
107+
dist: prepare $(BINARIES) $(ASC_BINARIES)
108+
109+
prepare: pull
65110
mkdir -p dist
66111

67112
dist/katenary-linux-amd64:
68113
@echo
69114
@echo -e "\033[1;32mBuilding katenary $(VERSION) for linux-amd64...\033[0m"
70115
$(MAKE) katenary GOOS=linux GOARCH=amd64 OUT=$@
71116

72-
73117
dist/katenary-linux-arm64:
74118
@echo
75119
@echo -e "\033[1;32mBuilding katenary $(VERSION) for linux-arm...\033[0m"
@@ -94,30 +138,16 @@ dist/katenary-freebsd-arm64:
94138
@echo
95139
@echo -e "\033[1;32mBuilding katenary $(VERSION) for freebsd-arm64...\033[0m"
96140
$(MAKE) katenary GOOS=freebsd GOARCH=arm64 OUT=$@
97-
98-
katenary: $(wildcard */*.go Makefile go.mod go.sum)
99-
ifeq ($(GO),local)
100-
@echo "=> Build in host using go"
101-
else
102-
@echo "=> Build in container using" $(CTN)
103-
endif
104-
echo $(BLD_CMD)
105-
ifeq ($(GO),local)
106-
$(BLD_CMD)
107-
else ifeq ($(CTN),podman)
108-
@podman run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \
109-
--rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --userns keep-id -it $(BUILD_IMAGE) $(BLD_CMD)
110-
else
111-
@docker run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \
112-
--rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --user $(shell id -u):$(shell id -g) -e HOME=/tmp -it $(BUILD_IMAGE) $(BLD_CMD)
113-
endif
114-
echo "=> Stripping if possible"
115-
strip $(OUT) 2>/dev/null || echo "=> No strip available"
116141

142+
gpg-sign:
143+
rm -f dist/*.asc
144+
$(MAKE) $(ASC_BINARIES)
117145

146+
dist/%.asc: dist/%
147+
gpg --armor --detach-sign --default-key $(SIGNER) $< &>/dev/null || exit 1
118148

119149
install: build
120-
cp katenary $(PREFIX)/bin/katenary
150+
install -Dm755 katenary $(PREFIX)/bin/katenary
121151

122152
uninstall:
123153
rm -f $(PREFIX)/bin/katenary
@@ -126,13 +156,27 @@ clean:
126156
rm -rf katenary dist/* release.id
127157

128158

159+
serve-doc: __label_doc
160+
@cd doc && \
161+
[ -d venv ] || python -m venv venv; \
162+
source venv/bin/activate && \
163+
echo "==> Installing requirements in the virtual env..."
164+
pip install -qq -r requirements.txt && \
165+
echo "==> Serving doc with mkdocs..." && \
166+
mkdocs serve
167+
129168
tests: test
130169
test:
131170
@echo -e "\033[1;33mTesting katenary $(VERSION)...\033[0m"
132-
go test -v ./...
171+
go test -coverprofile=cover.out ./...
172+
go tool cover -func=cover.out | grep "total:"
173+
go tool cover -html=cover.out -o cover.html
174+
if [ "$(BROWSER)" = "xdg-open" ]; then
175+
xdg-open cover.html
176+
else
177+
$(BROWSER) -i --new-window cover.html
178+
fi
133179

134-
135-
.ONESHELL:
136180
push-release: build-all
137181
@rm -f release.id
138182
# read personal access token from .git-credentials
@@ -154,3 +198,29 @@ push-release: build-all
154198
https://uploads.github.com/repos/metal3d/katenary/releases/$$(cat release.id)/assets?name=$$(basename $$i)
155199
done
156200
@rm -f release.id
201+
202+
203+
__label_doc:
204+
@command -v gomarkdoc || (echo "==> We need to install gomarkdoc..." && \
205+
go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest)
206+
@echo "=> Generating labels doc..."
207+
# short label doc
208+
go run ./cmd/katenary help-labels -m | \
209+
sed -i '
210+
/START_LABEL_DOC/,/STOP_LABEL_DOC/{/<!--/!d};
211+
/START_LABEL_DOC/,/STOP_LABEL_DOC/r/dev/stdin
212+
' doc/docs/labels.md
213+
# detailed label doc
214+
go run ./cmd/katenary help-labels -am | sed 's/^##/###/' | \
215+
sed -i '
216+
/START_DETAILED_DOC/,/STOP_DETAILED_DOC/{/<!--/!d};
217+
/START_DETAILED_DOC/,/STOP_DETAILED_DOC/r/dev/stdin
218+
' doc/docs/labels.md
219+
220+
echo "=> Generating Code documentation..."
221+
PACKAGES=$$(for f in $$(find . -name "*.go" -type f); do dirname $$f; done | sort -u)
222+
for pack in $$PACKAGES; do
223+
echo "-> Generating doc for $$pack"
224+
gomarkdoc --repository.default-branch $(shell git branch --show-current) -o doc/docs/packages/$$pack.md $$pack
225+
sed -i '/^## Index/,/^##/ { /## Index/d; /^##/! d }' doc/docs/packages/$$pack.md
226+
done

0 commit comments

Comments
 (0)