Skip to content

Commit 9b0926e

Browse files
authored
Merge pull request #11585 from owncloud/fix_some_dev_docs_stuff
[docs-only] Fix docs build process
2 parents 4cc248d + 2a4ab8d commit 9b0926e

File tree

7 files changed

+202
-102
lines changed

7 files changed

+202
-102
lines changed

.drone.star

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ KEYCLOAK_IMAGE = "quay.io/keycloak/keycloak:26.2.5"
4141
POSTGRES_ALPINE_IMAGE = "postgres:alpine3.18"
4242
TRIVY_IMAGE = "aquasec/trivy:latest"
4343

44+
# the hugo version needs to be the same as in owncloud.github.io
45+
OC_CI_HUGO_STATIC_IMAGE = "hugomods/hugo:base-0.129.0"
46+
4447
DEFAULT_PHP_VERSION = "8.4"
4548
DEFAULT_NODEJS_VERSION = "22"
4649

@@ -482,7 +485,7 @@ def main(ctx):
482485

483486
build_release_helpers = \
484487
changelog() + \
485-
docs() + \
488+
documentation() + \
486489
licenseCheck(ctx)
487490

488491
test_pipelines = \
@@ -2376,11 +2379,11 @@ def releaseDockerReadme(ctx, repo, build_type):
23762379
},
23772380
}
23782381

2379-
def docs():
2382+
def documentation():
23802383
return [{
23812384
"kind": "pipeline",
23822385
"type": "docker",
2383-
"name": "docs",
2386+
"name": "documentation",
23842387
"platform": {
23852388
"os": "linux",
23862389
"arch": "amd64",
@@ -2389,23 +2392,29 @@ def docs():
23892392
{
23902393
"name": "docs-generate",
23912394
"image": OC_CI_GOLANG,
2395+
# "pull": "always",
23922396
"environment": DRONE_HTTP_PROXY_ENV,
23932397
"commands": ["make docs-generate"],
23942398
},
23952399
{
2396-
"name": "prepare",
2400+
"name": "docs-copy",
23972401
"image": OC_CI_GOLANG,
23982402
"environment": DRONE_HTTP_PROXY_ENV,
2399-
"commands": [
2400-
"make -C docs docs-copy",
2401-
],
2403+
"commands": ["make docs-copy"],
24022404
},
24032405
{
2404-
"name": "test",
2406+
"name": "docs-hugo-drone-prep",
24052407
"image": OC_CI_GOLANG,
24062408
"environment": DRONE_HTTP_PROXY_ENV,
2409+
"commands": ["make docs-hugo-drone-prep"],
2410+
},
2411+
{
2412+
"name": "docs-build",
2413+
"image": OC_CI_HUGO_STATIC_IMAGE,
2414+
"environment": DRONE_HTTP_PROXY_ENV,
24072415
"commands": [
2408-
"make -C docs test",
2416+
"cd hugo",
2417+
"hugo",
24092418
],
24102419
},
24112420
{
@@ -2437,6 +2446,7 @@ def docs():
24372446
"commands": [
24382447
"tree docs/hugo/public",
24392448
"rm -rf docs/hugo",
2449+
"rm -rf hugo",
24402450
],
24412451
},
24422452
],

Makefile

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ endif
8181
include .make/recursion.mk
8282

8383
.PHONY: help
84+
DEFAULT_GOAL := help
8485
help:
8586
@echo "Please use 'make <target>' where <target> is one of the following:"
8687
@echo
88+
@echo -e "${GREEN}List all available .PHONY targets:${RESET}\n"
89+
@echo -e "\tmake list\t\t${BLUE}sorted alphabetically${RESET}"
90+
@echo -e "${BLACK}---------------------------------------------------------${RESET}"
8791
@echo -e "${GREEN}Testing with test suite natively installed:${RESET}\n"
8892
@echo -e "${PURPLE}\tdocs: https://owncloud.dev/ocis/development/testing/#testing-with-test-suite-natively-installed${RESET}\n"
8993
@echo -e "\tmake test-acceptance-api\t\t${BLUE}run API acceptance tests${RESET}"
@@ -94,14 +98,13 @@ help:
9498
@echo -e "${RED}You also should have a look at other available Makefiles:${RESET}"
9599
@echo
96100
@echo -e "${GREEN}oCIS:${RESET}\n"
97-
@echo -e "${PURPLE}\tdocs: https://owncloud.dev/ocis/development/build/${RESET}\n"
101+
@echo -e "${PURPLE}\tdocs: https://owncloud.dev/ocis/ocis/build-docs/${RESET}\n"
98102
@echo -e "\tsee ./ocis/Makefile"
99103
@echo -e "\tor run ${YELLOW}make -C ocis help${RESET}"
100104
@echo
101105
@echo -e "${GREEN}Documentation:${RESET}\n"
102-
@echo -e "${PURPLE}\tdocs: https://owncloud.dev/ocis/development/build-docs/${RESET}\n"
103-
@echo -e "\tsee ./docs/Makefile"
104-
@echo -e "\tor run ${YELLOW}make -C docs help${RESET}"
106+
@echo -e "${PURPLE}\tdocs: https://owncloud.dev/ocis/build-docs/${RESET}\n"
107+
@echo -e "\trun ${YELLOW}make list | grep docs-\t\t${BLUE}note: run all docs command via this makefile${RESET}"
105108
@echo
106109
@echo -e "${GREEN}Testing with test suite in docker:${RESET}\n"
107110
@echo -e "${PURPLE}\tdocs: https://owncloud.dev/ocis/development/testing/#testing-with-test-suite-in-docker${RESET}\n"
@@ -117,6 +120,12 @@ help:
117120
@echo -e "\tmake test-gherkin-lint-fix\t${BLUE}apply lint fixes to gherkin feature files${RESET}"
118121
@echo
119122

123+
.PHONY: list
124+
list:
125+
@echo -e 'Available .PHONY targets: \n'
126+
@grep -P -o '(?<=^\.PHONY: )(.*)' Makefile | sort -u
127+
@echo
128+
120129
.PHONY: clean-tests
121130
clean-tests:
122131
@rm -Rf vendor-bin/**/vendor vendor-bin/**/composer.lock tests/acceptance/output
@@ -159,33 +168,57 @@ clean:
159168
$(MAKE) --no-print-directory -C $$mod clean || exit 1; \
160169
done
161170

162-
.PHONY: docs-generate
171+
# generate the docs
172+
# intents and comments are intentional...
173+
.PHONY: docs-generate # 1. prepare docs
163174
docs-generate:
164-
# empty the folders first to only have files that are generated without remnants
175+
@echo 'Empty folders first to only have those files that are generated without remnants.'
165176
find docs/services/_includes/ -type f \( -name "*" ! -name ".git*" \) -delete || exit 1
166177

167-
# generate the services md files for dev docs
178+
@echo 'Generate content from services.'
168179
@for mod in $(OCIS_MODULES); do \
169180
$(MAKE) --no-print-directory -C $$mod docs-generate || exit 1; \
170181
done
171182

172-
# generate envvar adoc and md tables for dev and admin docs
173-
$(MAKE) --no-print-directory -C docs docs-generate || exit 1
174-
175-
# only copy all added/removed/deprecated files that have been created for a release + .gitkeep
176-
# note that files are locally ignored via _include/.gitignore for pushing, but required by the drone process
177-
# for markdown, if e.g. an `_index.md` file would be present containing links, hugo thinks it must render and fails
178-
# the -I flag followed by % cp % means that all passed arguments will concatenated to the last %
179-
find docs/services/general-info/envvars/env-var-deltas/ -type f \( -name ".gitkeep" -o -name "*-added.*" -o -name "*-removed.*" -o -name "*-deprecated.*" \) | xargs -I % cp % docs/services/_includes/adoc/env-var-deltas/
180-
181-
.PHONY: docs-drone-test
182-
# imitate a full drone run to build docs without pushing to the web.
183-
# this can help identify uncaught issues when running `make -C docs docs-serve` only.
184-
docs-drone-test:
185-
$(MAKE) --no-print-directory docs-generate
186-
$(MAKE) --no-print-directory -C docs docs-copy
187-
$(MAKE) --no-print-directory -C docs test
188-
183+
@$(MAKE) --no-print-directory -C docs docs-run-helpers || exit 1
184+
185+
# initialize the docs build environment
186+
@$(MAKE) --no-print-directory -C docs docs-init
187+
188+
# copy required resources into hugo/content
189+
.PHONY: docs-copy # 2. copy required doc resources
190+
docs-copy:
191+
@$(MAKE) --no-print-directory -C docs docs-copy
192+
193+
# the docs-build|serve commands requires that docs-init was run first for the required data to exists
194+
# create a docs build
195+
.PHONY: docs-build # 3. build prepared docs
196+
docs-build:
197+
@$(MAKE) --no-print-directory -C docs docs-build
198+
199+
# serve built docs with hugo
200+
.PHONY: docs-serve # serve the docs build
201+
docs-serve:
202+
@$(MAKE) --no-print-directory -C docs docs-serve
203+
204+
# clean up doc build artifacts
205+
.PHONY: docs-clean # clean all docs artifacts, must be run as sudo
206+
docs-clean:
207+
@$(MAKE) --no-print-directory -C docs docs-clean
208+
209+
# imitate a full drone run locally to build docs without pushing to the web.
210+
# this can help identify uncaught issues when running `make docs-serve` only.
211+
.PHONY: docs-local # run all steps as drone would do it (1, 2, 3)
212+
docs-local:
213+
@$(MAKE) --no-print-directory docs-generate
214+
@$(MAKE) --no-print-directory docs-copy
215+
@$(MAKE) --no-print-directory docs-build
216+
217+
# prepare a link from the root to the hugo folder because the image requires it
218+
# note that on local building, the referenced container of inside the hugo/makefile is used
219+
.PHONY: docs-hugo-drone-prep # only used for drone !
220+
docs-hugo-drone-prep:
221+
@$(MAKE) --no-print-directory -C docs docs-hugo-drone-prep
189222

190223
.PHONY: check-env-var-annotations
191224
check-env-var-annotations:

docs/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
hugo/
22
grpc_apis/
3-
mutagen.yml.lock
43
helpers/output/*
54
services/**/_index.md

docs/Makefile

Lines changed: 83 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,96 @@
11
SHELL := bash
2+
# we need an override so that this variable is cleanly set in this makefile
3+
# else it might come from somewhere else
4+
override HUGO := $(CURDIR)/hugo
5+
override HDIR := $(HUGO)/.git
26

3-
include ../.bingo/Variables.mk
7+
# if the directory exists, print that we do not need to prepare
8+
hugo-exists:
9+
@if [ -d $(HDIR) ]; then \
10+
echo; \
11+
echo 'Build environment for hugo exists, nothing to setup, continuing.'; \
12+
fi
413

14+
# if the directory does not extist, initialize the framework and create the theme
15+
$(HDIR):
16+
@echo 'Initialize the hugo framework and build the theme, no docs get built.'
17+
@mkdir -p $(HUGO)/content/
18+
@mkdir -p $(HUGO)/extensions/
19+
@mkdir -p $(HUGO)/public/
20+
@cd $(HUGO) && git init
21+
@cd $(HUGO) && git config advice.detachedHead false
22+
@cd $(HUGO) && git remote rm origin || true
23+
@cd $(HUGO) && git remote add origin https://github.com/owncloud/owncloud.github.io
24+
@cd $(HUGO) && git fetch --depth=1
25+
@cd $(HUGO) && git checkout origin/main -f
26+
@$(MAKE) -C $(HUGO) --no-print-directory theme
27+
28+
# print available make targets
529
.PHONY: help
30+
.DEFAULT_GOAL := help
631
help:
7-
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk -F'[:;##]' '{printf "\033[36m%-30s\033[0m %s\n", $$2, $$NF}'
32+
@echo -e 'Available .PHONY targets: \n'
33+
@grep -P -o '(?<=^\.PHONY: )(.*)' Makefile | sort -u
34+
@echo
35+
36+
# alternative target because we also use it in the root's makefile
37+
.PHONY:list
38+
list: help
839

9-
.PHONY: docs-generate
10-
docs-generate: ## run docs-generate for all oCIS services
40+
# for drone only. drone uses an image for hugo that needs the hugo folder in the root
41+
# CURDIR will work for make only but not when running manually in the shell
42+
.PHONY: docs-hugo-drone-prep
43+
docs-hugo-drone-prep:
44+
@echo
45+
@echo 'Linking directory hugo for drone.'
46+
@rm -f ../hugo
47+
@ln -s $(HUGO) ../hugo
48+
49+
# generate data from sources such as services
50+
.PHONY: docs-run-helpers
51+
docs-run-helpers:
52+
@echo
53+
@echo 'Generate envvar adoc and md tables for all oCIS services used for dev and admin docs'
1154
@pushd helpers && go run .; popd
1255

56+
# create the docs build environment
1357
.PHONY: docs-init
14-
docs-init:
15-
@mkdir -p hugo/content/
16-
@mkdir -p hugo/public/
17-
@touch hugo/public/.nojekyll
18-
@cd hugo && git init
19-
@cd hugo && git config advice.detachedHead false
20-
@cd hugo && git remote rm origin || true
21-
@cd hugo && git remote add origin https://github.com/owncloud/owncloud.github.io
22-
@cd hugo && git fetch --depth=1
23-
@cd hugo && git checkout origin/main -f
24-
@$(MAKE) -C hugo theme
58+
docs-init: hugo-exists $(HDIR)
59+
# if there is nothing to do, stop printing that
60+
# another way would be https://stackoverflow.com/questions/58039810/makefiles-what-is-an-order-only-prerequisite
61+
@:
2562

26-
.PHONY: docs-serve
27-
docs-serve: docs-init docs-generate docs-copy ## serve docs with hugo
28-
@bash -c "trap 'trap - SIGINT SIGTERM ERR; $(MAKE) --no-print-directory docs-sync-stop; exit 0' SIGINT SIGTERM ERR; $(MAKE) --no-print-directory docs-sync-start && $(MAKE) --no-print-directory hugo-serve"
63+
# the docs-build|serve commands require that docs-init was run first for the required data to exists
64+
# create a docs build
65+
.PHONY: docs-build
66+
docs-build:
67+
@echo
68+
@echo 'Building ocis for owncloud.dev'
69+
@$(MAKE) -C $(HUGO) --no-print-directory hugo-build
70+
@echo 'To view the rendered docs in the browser, run: make docs-serve'
2971

30-
.PHONY: test
31-
test: $(HUGO)
32-
@cd hugo && $(HUGO)
33-
34-
.PHONY: hugo-serve
35-
hugo-serve: $(HUGO)
36-
@cd hugo && $(HUGO) server
72+
# serve built docs with hugo
73+
.PHONY: docs-serve
74+
docs-serve:
75+
@$(MAKE) -C $(HUGO) --no-print-directory hugo-server
3776

77+
# copy required resources into hugo
3878
.PHONY: docs-copy
39-
docs-copy: docs-init docs-sync-start docs-sync-stop
40-
41-
.PHONY: docs-sync-start
42-
docs-sync-start: $(MUTAGEN)
43-
@$(MUTAGEN) project terminate || true
44-
@$(MUTAGEN) daemon stop || true
45-
@$(MUTAGEN) project start
46-
@$(MUTAGEN) project flush
47-
48-
.PHONY: docs-sync-stop
49-
docs-sync-stop: $(MUTAGEN)
50-
@$(MUTAGEN) project terminate
51-
@$(MUTAGEN) daemon stop
52-
53-
.PHONY: clean
54-
clean: ## clean up docs build artifacts
55-
@rm -rf hugo
79+
docs-copy:
80+
@echo
81+
@echo 'Syncing required doc files and directories for the build process.'
82+
# brace expansion not with sh
83+
@rsync --delete -ax --exclude={hugo,templates,Makefile,.gitignore,README.md} ./ $(HUGO)/content/
84+
85+
# clean up docs build artifacts (removing the hugo folder)
86+
.PHONY: docs-clean
87+
docs-clean:
88+
# NOTE: the whitespace at the beginning of the ifeq/else/endif statements is intentional.
89+
@echo
90+
ifneq ($(shell id -u), 0)
91+
@echo "You must run the clean command using sudo or as root because some doc files are created by root"
92+
else
93+
@echo 'Clean up docs build artifacts'
94+
@rm -rf $(HUGO)
95+
@echo "Removed folder: $(HUGO)"
96+
endif

docs/mutagen.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)