Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Dec 10, 2018
1 parent 62fc195 commit 3d8f9b4
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ doc.iml

# Temporary
doc-build
changelogs-build
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ALL_VERSIONS = 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 3.0 3.1 3.2 4.0 4.1 4.2 4.3 5.0
VERSIONS = 5.0 5.1
VERSION_DOCS = $(addprefix doc-, $(VERSIONS))
VERSION_ARCHIVES = $(addsuffix .archive, $(VERSIONS))
Expand All @@ -6,7 +7,7 @@ GENERIC_DOCS = site site-dev site-local

SITES = $(GENERIC_DOCS) $(VERSIONS)

.PHONY: prepare rudder-theme/build/ui-bundle.zip optipng doc-build build/sites/site/.htaccess build/history/5.0/.htaccess build/files $(SITES)
.PHONY: prepare rudder-theme/build/ui-bundle.zip optipng doc-build changelogs-build build/sites/site/.htaccess build/history/5.0/.htaccess build/files $(SITES)
.DEFAULT_GOAL := local

all: $(GENERIC_DOCS) build/sites/site/.htaccess build/history/5.0/.htaccess $(VERSION_ARCHIVES) build/files test
Expand All @@ -28,8 +29,19 @@ doc-build:
cd $@/src/reference && make
cd $@ && git add -f src/reference && git commit --allow-empty -m "Build master"

changelogs-build:
[ -d $@ ] || git clone https://github.com/amousset/rudder-doc.git $@
cd $@ && git checkout master && git pull
for version in $(ALL_VERSIONS); do \
cd $@ && git checkout master && git branch -df "branches/rudder/$$version" && git checkout -b "branches/rudder/$$version" ; \
sed -i 's@version: "5.0"@version: "$$version"@' src/changelogs/antora.yml ; \
sed -i 's@RUDDER_VERSION = 5.0@RUDDER_VERSION = $$version@' src/changelogs/dependencies/Makefile ; \
src/changelogs && make ; \
cd .. && git add -f src/changelogs && git commit --allow-empty -m "Build" ; \
done

# Prepare everything, even if not needed
prepare: doc-build
prepare: doc-build changelogs-build
cd src/reference && make

$(SITES): prepare rudder-theme/build/ui-bundle.zip
Expand Down
4 changes: 3 additions & 1 deletion site-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ content:
- url: ./doc-build
branches: ["branches/rudder/5.0", "master"]
start_path: src/reference

- url: .
branches: master
start_path: src/changelogs
4 changes: 3 additions & 1 deletion site-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ content:
- url: .
branches: HEAD
start_path: src/reference

- url: .
branches: HEAD
start_path: src/changelogs
21 changes: 20 additions & 1 deletion site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,23 @@ content:
- url: ./doc-build
branches: "branches/rudder/5.0"
start_path: src/reference

- url: ./changelogs-build
branches:
- "branches/rudder/2.3"
- "branches/rudder/2.4"
- "branches/rudder/2.5"
- "branches/rudder/2.6"
- "branches/rudder/2.7"
- "branches/rudder/2.8"
- "branches/rudder/2.9"
- "branches/rudder/2.10"
- "branches/rudder/2.11"
- "branches/rudder/3.0"
- "branches/rudder/3.1"
- "branches/rudder/3.2"
- "branches/rudder/4.0"
- "branches/rudder/4.1"
- "branches/rudder/4.2"
- "branches/rudder/4.3"
- "branches/rudder/5.0"
start_path: src/changelogs
4 changes: 4 additions & 0 deletions src/changelogs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
modules/*/nav.adoc
modules/*/pages/_partials/dyn/
modules/*/assets/images/graphviz/
modules/plugins/assets/
20 changes: 20 additions & 0 deletions src/changelogs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Rudder Changelog Makefile

.PHONY: clean nav

## Dynamic content

changelogs:
cd dependencies && make $@
cp -r dependencies/$@/* modules/ROOT/pages/
mv modules/ROOT/pages/main.adoc modules/ROOT/pages/index.adoc
echo "* xref:index.adoc[Main changelogs]" > modules/ROOT/nav.adoc
echo "* Plugins" >> modules/ROOT/nav.adoc
find modules/ROOT/pages/plugins -type f | sed 's/.*\///' | sed "s/\.adoc//" | sed -r 's@(.*)@** xref:plugins/\1.adoc[\1]@' | sort >> modules/ROOT/nav.adoc

## Clean

clean:
cd dependencies && make clean
rm -rf modules/*/nav.adoc
rm -rf modules/*/pages/*
6 changes: 6 additions & 0 deletions src/changelogs/antora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: changelogs
title: Changelogs
version: "5.0"
nav:
- modules/ROOT/nav.adoc

3 changes: 3 additions & 0 deletions src/changelogs/dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated files
/changelogs/
/rudder-tools-repo/
27 changes: 27 additions & 0 deletions src/changelogs/dependencies/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Builds dynamic dependencies from other repos

RUDDER_VERSION = 5.0

.PHONY: clean changelogs
all: changelogs

## Repos

rudder-tools-repo:
git clone https://github.com/Normation/rudder-tools.git rudder-tools-repo

## Dynamic content

changelogs: rudder-tools-repo
cd rudder-tools-repo && git checkout master
cd rudder-tools-repo && git pull
mkdir -p changelogs
cp -r rudder-tools-repo/release-data/changelogs/$(RUDDER_VERSION)/* changelogs/

## Clean

clean:
rm -rf changelogs

veryclean: clean
rm -rf changelogs rudder-tools-repo
72 changes: 72 additions & 0 deletions src/changelogs/tools/generate-nav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python

import os
import re
import sys

MODULE = sys.argv[1]
NAME = sys.argv[2]

MODULEDIR = "modules/"+MODULE
PAGESDIR = MODULEDIR+"/pages/"
TITLE = re.compile("^(=+) (.+)$")
ID = re.compile(r"^\[\[(.+),?.*\]\]$")

def remove_duplicate_underscore(string):
prev = ' '
res = []
for char in string:
if prev == '_' and char == '_':
pass
else:
res.append(char)
prev = char
return ''.join(res)

# reproduce asciidoc's behavior
def slugify(s):
s = "_" + s
s = s.lower()
s = s.strip()
s = re.sub('\W', '_', s)
s = remove_duplicate_underscore(s)
s = s.rstrip('_')
return s

# Get all standalone .adoc pages, sorted alphanumerically
# We exclude files in root (the index of the doc), _partials which are not actual pages

with open(MODULEDIR + "/nav.list") as f:
files = f.read().splitlines()
#files = sorted([file for root, dirs, files in os.walk('.') for file in files if file.endswith(".adoc") and not "_partials" in root])
#files = sorted([root.split('/', 1)[-1]+"/"+file for root, dirs, files in os.walk('.') for file in files if file.endswith(".adoc") and not "_partials" in root])

result = ["// Automatically generated list of content - do not edit", "* "+NAME]

os.chdir(PAGESDIR)

for file in files:
with open(file) as f:
content = f.read().splitlines()

prev = ""
first = True
for line in content:
search_title = TITLE.search(line)
if search_title:
level = search_title.group(1).count("=") + 1
title = search_title.group(2)
search_id = ID.search(prev)
if search_id:
page_id = search_id.group(1)
else:
page_id = slugify(title)
if level < 4:
if first:
result.append("*" * level + " xref:" + file + "[" + title + "]")
first = False
else:
result.append("*" * level + " xref:" + file + "#" + page_id + "[" + title + "]")
prev = line

print("\n".join(result))

0 comments on commit 3d8f9b4

Please sign in to comment.