Skip to content

Commit f8c356c

Browse files
llecoqbrmzkw
authored andcommitted
fix: Call make gen-doc in make test
Signed-off-by: llecoq <[email protected]>
1 parent 74bafd3 commit f8c356c

File tree

3 files changed

+44
-32
lines changed

3 files changed

+44
-32
lines changed

.github/workflows/main.yml

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ jobs:
1616
make test
1717
- name: golangci-lint
1818
uses: golangci/golangci-lint-action@v3
19-
- name: "Test gen doc"
20-
run: |
21-
make gen-doc
22-
# there should not be a diff
23-
git diff --quiet || (echo >&2 "make gen-doc has a diff" && false)
2419
build:
2520
name: Upload Release Asset
2621
runs-on: ubuntu-latest

Makefile

+34-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
TEST_OPTS=-v -test.timeout 300s
22

3+
define gen-doc-in-dir
4+
rm -f ./$1/*
5+
go run cmd/gen-doc/gen-doc.go $1
6+
sed -i.bak 's/.*koyeb completion.*//' ./$1/*.md
7+
sed -i.bak 's/### SEE ALSO.*//' ./$1/*.md
8+
cat ./$1/koyeb.md >> ./$1/reference.md
9+
cat ./$1/koyeb_login.md >> ./$1/reference.md
10+
cat ./$1/koyeb_apps.md >> ./$1/reference.md
11+
cat ./$1/koyeb_apps_*.md >> ./$1/reference.md
12+
cat ./$1/koyeb_domains.md >> ./$1/reference.md
13+
cat ./$1/koyeb_domains_*.md >> ./$1/reference.md
14+
cat ./$1/koyeb_secrets.md >> ./$1/reference.md
15+
cat ./$1/koyeb_secrets_*.md >> ./$1/reference.md
16+
cat ./$1/koyeb_services.md >> ./$1/reference.md
17+
cat ./$1/koyeb_services_*.md >> ./$1/reference.md
18+
cat ./$1/koyeb_deployments.md >> ./$1/reference.md
19+
cat ./$1/koyeb_deployments_*.md >> ./$1/reference.md
20+
cat ./$1/koyeb_instances.md >> ./$1/reference.md
21+
cat ./$1/koyeb_instances_*.md >> ./$1/reference.md
22+
cat ./$1/koyeb_version.md >> ./$1/reference.md
23+
find ./$1 -type f -not -name 'reference.md' -delete
24+
endef
25+
326
help: ## help
427
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_0-9-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
528

@@ -13,30 +36,18 @@ fmt: ## apply go format
1336
gofmt -s -w ./
1437

1538
gen-doc: ## generate markdown documentation
16-
rm -f ./docs/*
17-
go run cmd/gen-doc/gen-doc.go
18-
sed -i.bak 's/.*koyeb completion.*//' ./docs/*.md
19-
sed -i.bak 's/### SEE ALSO.*//' ./docs/*.md
20-
cat ./docs/koyeb.md >> ./docs/reference.md
21-
cat ./docs/koyeb_login.md >> ./docs/reference.md
22-
cat ./docs/koyeb_apps.md >> ./docs/reference.md
23-
cat ./docs/koyeb_apps_*.md >> ./docs/reference.md
24-
cat ./docs/koyeb_domains.md >> ./docs/reference.md
25-
cat ./docs/koyeb_domains_*.md >> ./docs/reference.md
26-
cat ./docs/koyeb_secrets.md >> ./docs/reference.md
27-
cat ./docs/koyeb_secrets_*.md >> ./docs/reference.md
28-
cat ./docs/koyeb_services.md >> ./docs/reference.md
29-
cat ./docs/koyeb_services_*.md >> ./docs/reference.md
30-
cat ./docs/koyeb_deployments.md >> ./docs/reference.md
31-
cat ./docs/koyeb_deployments_*.md >> ./docs/reference.md
32-
cat ./docs/koyeb_instances.md >> ./docs/reference.md
33-
cat ./docs/koyeb_instances_*.md >> ./docs/reference.md
34-
cat ./docs/koyeb_version.md >> ./docs/reference.md
35-
find ./docs -type f -not -name 'reference.md' -delete
39+
$(call gen-doc-in-dir,docs)
3640

3741
test: tidy cmd pkg
38-
test -z "`gofmt -d ./cmd ./pkg | tee /dev/stderr`"
39-
go test $(TEST_OPTS) ./...
42+
@mkdir -p ./.temp
43+
@$(call gen-doc-in-dir,.temp)
44+
@diff -r -q ./docs ./.temp > /dev/null && { \
45+
test -z "`gofmt -d ./cmd ./pkg | tee /dev/stderr`"; \
46+
go test $(TEST_OPTS) ./...; \
47+
} || { \
48+
echo >&2 "make gen-doc has a diff"; \
49+
}
50+
@rm -rf ./.temp;
4051

4152
lint:
42-
golangci-lint run -v ./...
53+
golangci-lint run -v ./...

cmd/gen-doc/gen-doc.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ package main
22

33
import (
44
"log"
5+
"os"
56
"path"
67
"strings"
78

89
"github.com/koyeb/koyeb-cli/pkg/koyeb"
910
"github.com/spf13/cobra/doc"
1011
)
1112

12-
func genMarkdownDocumentation() {
13+
func genMarkdownDocumentation(outputDir string) {
1314
rootCmd := koyeb.GetRootCommand()
1415
linkHandler := func(name string) string {
1516
base := strings.TrimSuffix(name, path.Ext(name))
1617
return "#" + strings.Replace(strings.ToLower(base), "_", "-", -1)
1718
}
1819

1920
filePrepender := func(filename string) string {
20-
if filename == "docs/koyeb.md" {
21+
if filename == outputDir+"/koyeb.md" {
2122
return `---
2223
title: "Koyeb CLI Reference"
2324
shortTitle: Reference
@@ -34,12 +35,17 @@ If you have not installed the Koyeb CLI yet, please read the [installation guide
3435
return ""
3536
}
3637

37-
err := doc.GenMarkdownTreeCustom(rootCmd, "./docs", filePrepender, linkHandler)
38+
err := doc.GenMarkdownTreeCustom(rootCmd, outputDir, filePrepender, linkHandler)
3839
if err != nil {
3940
log.Fatal(err)
4041
}
4142
}
4243

4344
func main() {
44-
genMarkdownDocumentation()
45+
outputDir := "./docs"
46+
if len(os.Args) > 1 {
47+
outputDir = os.Args[1]
48+
}
49+
50+
genMarkdownDocumentation(outputDir)
4551
}

0 commit comments

Comments
 (0)