Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 42ace4d

Browse files
authored
Documentation ci pr 1.x (#64)
* Adding CI to build and publish ce-dev docs automatically. * ce-dev didn't have the toc.sh docs builder script. * Removing doc push step from build job, it has its own job now.
1 parent fc5e73d commit 42ace4d

File tree

4 files changed

+238
-13
lines changed

4 files changed

+238
-13
lines changed

.github/workflows/ce-dev-build.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,3 @@ jobs:
5151
body_path: RELEASE
5252
env:
5353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54-
- name: Build and publish docs
55-
run: |
56-
cd
57-
curl -sL https://raw.githubusercontent.com/codeenigma/ce-dev/1.x/install.sh | /bin/sh -s -- linux
58-
git clone https://github.com/codeenigma/wikis2pages.git
59-
cd wikis2pages
60-
/bin/sh init.sh https://${{ secrets.GITHUB_TOKEN }}@github.com/codeenigma/ce-dev.git 1.x
61-
/bin/sh set-current.sh ce-dev-travis
62-
docker exec --user ce-dev --workdir /home/ce-dev/deploy/live.local wikis2pages-hugo hugo
63-
/bin/sh .github-actions-push.sh
64-
cd /home/runner/wikis2pages/public/ce-dev-travis
65-
git remote add ci https://${{ secrets.DOCS_GITHUB_TOKEN }}@github.com/codeenigma/ce-dev-docs.git
66-
git push ci master
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish docs
2+
3+
# Run this workflow on push to 1.x (e.g. on merge of PR to 1.x)
4+
on:
5+
push:
6+
branches:
7+
- 1.x
8+
9+
jobs:
10+
# Set the job key. The key is displayed as the job name
11+
# when a job name is not provided
12+
run-tests:
13+
# Name the Job
14+
name: Publish documentation
15+
# Set the type of machine to run on
16+
runs-on: ubuntu-20.04
17+
18+
steps:
19+
# Configures global Git variables for committing
20+
- name: Configure Git
21+
run: |
22+
git config --global user.email "sysadm@codeenigma.com"
23+
git config --global user.name "Code Enigma CI"
24+
# Installs the ce-dev stack
25+
- name: Install ce-dev
26+
run: |
27+
cd /tmp
28+
wget https://golang.org/dl/go1.15.8.linux-amd64.tar.gz
29+
sudo tar -C /usr/local -xzf go1.15.8.linux-amd64.tar.gz
30+
export PATH=$PATH:/usr/local/go/bin
31+
git clone https://github.com/FiloSottile/mkcert && cd mkcert
32+
go build -ldflags "-X main.Version=$(git describe --tags)"
33+
sudo mv ./mkcert /usr/local/bin && cd ../
34+
sudo chmod +x /usr/local/bin/mkcert
35+
rm -Rf mkcert
36+
curl -sL https://raw.githubusercontent.com/codeenigma/ce-dev/1.x/install.sh | /bin/sh -s -- linux
37+
# Uses the ce-dev stack to run Hugo to format and deploy the docs
38+
- name: Publish documentation
39+
run: |
40+
cd
41+
git clone https://github.com/codeenigma/wikis2pages.git
42+
cd wikis2pages
43+
/bin/bash init.sh https://${{ secrets.GITHUB_TOKEN }}@github.com/codeenigma/ce-dev.git 1.x
44+
/bin/sh set-current.sh ce-dev-1.x
45+
docker exec --user ce-dev --workdir /home/ce-dev/deploy/live.local wikis2pages-hugo hugo
46+
/bin/sh .github-actions-push.sh
47+
cd /home/runner/wikis2pages/public/ce-dev-1.x
48+
git remote add ci https://${{ secrets.DOCS_GITHUB_TOKEN }}@github.com/codeenigma/ce-dev-docs.git
49+
git push ci master
50+
shell: bash
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build docs
2+
3+
# Run this workflow every time a new commit pushed to your repository
4+
on: pull_request
5+
6+
jobs:
7+
# Set the job key. The key is displayed as the job name
8+
# when a job name is not provided
9+
build-docs:
10+
# Name the Job
11+
name: Build the documentation
12+
# Set the type of machine to run on
13+
runs-on: ubuntu-20.04
14+
15+
steps:
16+
# Checks out a copy of your repository on the ubuntu-latest machine
17+
- name: Checkout code
18+
if: ${{ github.event.pull_request.head.ref != 'documentation' }}
19+
uses: actions/checkout@v2
20+
21+
# Configures global Git variables for committing
22+
- name: Configure Git
23+
run: |
24+
git config --global user.email "sysadm@codeenigma.com"
25+
git config --global user.name "Code Enigma CI"
26+
27+
# Builds the docs
28+
- name: Build documentation
29+
if: ${{ github.event.pull_request.head.ref != 'documentation' }}
30+
run: |
31+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
32+
git fetch
33+
git checkout documentation
34+
contribute/toc.sh
35+
git add docs
36+
git diff --quiet && git diff --staged --quiet || git commit -am 'GitHub Actions - Rebuilt documentation.' && git push origin documentation
37+
shell: bash
38+
39+
# Create docs pull request
40+
- name: Create a documentation pull request
41+
if: ${{ github.event.pull_request.head.ref != 'documentation' && github.event.pull_request.base.ref == '1.x' }}
42+
uses: devops-infra/action-pull-request@v0.4.2
43+
with:
44+
github_token: ${{ secrets.GITHUB_TOKEN }}
45+
source_branch: documentation
46+
target_branch: ${{ github.event.pull_request.base.ref }}
47+
title: Documentation update.
48+
body: "**Automated pull request** created by GitHub Actions because of a documentation update."

contribute/toc.sh

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/sh
2+
# shellcheck disable=SC2094
3+
# shellcheck disable=SC2129
4+
IFS=$(printf '\n\t')
5+
set -e
6+
OWN_DIR=$(dirname "$0")
7+
cd "$OWN_DIR" || exit 1
8+
OWN_DIR=$(git rev-parse --show-toplevel)
9+
cd "$OWN_DIR" || exit 1
10+
OWN_DIR=$(pwd -P)
11+
12+
# @param
13+
# $1 string filepath
14+
cp_role_page(){
15+
RELATIVE=$(realpath --relative-to="$OWN_DIR" "$(dirname "$1")")
16+
if [ ! -d "$OWN_DIR/docs/$RELATIVE" ]; then
17+
mkdir -p "$OWN_DIR/docs/$RELATIVE"
18+
fi
19+
cp "$1" "$OWN_DIR/docs/$RELATIVE.md"
20+
}
21+
22+
# @param
23+
# $1 string folder
24+
cp_single_page(){
25+
if [ ! -d "$OWN_DIR/docs/$1" ]; then
26+
mkdir "$OWN_DIR/docs/$1"
27+
fi
28+
cp "$OWN_DIR/$1/README.md" "$OWN_DIR/docs/$1.md"
29+
}
30+
31+
# @param
32+
# $1 (string) filename
33+
parse_role_variables(){
34+
TMP_MD=$(mktemp)
35+
WRITE=1
36+
# Ensure we have a trailing line.
37+
echo "" >> "$1"
38+
while read -r LINE; do
39+
case $LINE in
40+
'<!--ROLEVARS-->')
41+
echo "$LINE" >> "$TMP_MD"
42+
generate_role_variables "$1"
43+
WRITE=0
44+
;;
45+
'<!--ENDROLEVARS-->')
46+
echo "$LINE" >> "$TMP_MD"
47+
WRITE=1
48+
;;
49+
'<!--TOC-->')
50+
echo "$LINE" >> "$TMP_MD"
51+
WRITE=0
52+
;;
53+
'<!--ENDTOC-->')
54+
echo "$LINE" >> "$TMP_MD"
55+
WRITE=1
56+
;;
57+
*)
58+
if [ $WRITE = 1 ]; then
59+
echo "$LINE" >> "$TMP_MD"
60+
fi
61+
;;
62+
esac
63+
done < "$1"
64+
printf '%s\n' "$(cat "$TMP_MD")" > "$1"
65+
rm "$TMP_MD"
66+
}
67+
68+
# @param
69+
# $1 (string) filename
70+
generate_role_variables(){
71+
VAR_FILE="$(dirname "$1")/defaults/main.yml"
72+
if [ -f "$VAR_FILE" ]; then
73+
echo "## Default variables" >> "$TMP_MD"
74+
echo '```yaml' >> "$TMP_MD"
75+
cat "$VAR_FILE" >> "$TMP_MD"
76+
echo "" >> "$TMP_MD"
77+
echo '```' >> "$TMP_MD"
78+
echo "" >> "$TMP_MD"
79+
fi
80+
}
81+
82+
generate_roles_toc(){
83+
TMP_SIDEBAR=$(mktemp)
84+
WRITE="true"
85+
while read -r LINE; do
86+
case $LINE in
87+
" - [Roles](roles)")
88+
echo "$LINE" >> "$TMP_SIDEBAR"
89+
parse_roles_toc roles 2
90+
WRITE="false"
91+
;;
92+
" -"*)
93+
WRITE="true"
94+
echo "$LINE" >> "$TMP_SIDEBAR"
95+
;;
96+
*)
97+
if [ "$WRITE" = "true" ]; then
98+
echo "$LINE" >> "$TMP_SIDEBAR"
99+
fi
100+
;;
101+
esac
102+
done < "$OWN_DIR/docs/_Sidebar.md"
103+
mv "$TMP_SIDEBAR" "$OWN_DIR/docs/_Sidebar.md"
104+
}
105+
106+
parse_roles_toc(){
107+
ROLES=$(find "$OWN_DIR/$1" -mindepth 2 -maxdepth 2 -name "README.md" | sort)
108+
for ROLE in $ROLES; do
109+
WRITE="true"
110+
INDENT=$(printf %$(($2 * 2))s)
111+
RELATIVE=$(realpath --relative-to="$OWN_DIR" "$(dirname "$ROLE")")
112+
while read -r LINE; do
113+
case $LINE in
114+
"# "*)
115+
if [ "$WRITE" = "true" ]; then
116+
TITLE=$(echo "$LINE" | cut -c 3-)
117+
echo "$INDENT"" - [$TITLE](/$RELATIVE)" >> "$TMP_SIDEBAR"
118+
WRITE="false"
119+
fi
120+
;;
121+
esac
122+
done < "$ROLE"
123+
parse_roles_toc "$RELATIVE" $(($2 + 1))
124+
done
125+
}
126+
127+
rm -rf "$OWN_DIR/docs/roles"
128+
ROLE_PAGES=$(find "$OWN_DIR/roles" -name "README.md")
129+
for ROLE_PAGE in $ROLE_PAGES; do
130+
parse_role_variables "$ROLE_PAGE"
131+
done
132+
for ROLE_PAGE in $ROLE_PAGES; do
133+
cp_role_page "$ROLE_PAGE"
134+
done
135+
generate_roles_toc
136+
137+
138+
cp_single_page install
139+
cp_single_page contribute
140+
cp_single_page scripts

0 commit comments

Comments
 (0)