From 1ba4d00b7a2fa1b7f3ecc8460ef9221856ef37e5 Mon Sep 17 00:00:00 2001 From: gregharvey Date: Mon, 17 Jan 2022 13:36:41 +0100 Subject: [PATCH 1/4] Adding CI to build and publish ce-dev docs automatically. --- .github/workflows/ce-dev-publish-docs.yml | 50 +++++++++++++++++++ .github/workflows/ce-provision-build-docs.yml | 48 ++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .github/workflows/ce-dev-publish-docs.yml create mode 100644 .github/workflows/ce-provision-build-docs.yml diff --git a/.github/workflows/ce-dev-publish-docs.yml b/.github/workflows/ce-dev-publish-docs.yml new file mode 100644 index 0000000..882fd8b --- /dev/null +++ b/.github/workflows/ce-dev-publish-docs.yml @@ -0,0 +1,50 @@ +name: Publish docs + +# Run this workflow on push to 1.x (e.g. on merge of PR to 1.x) +on: + push: + branches: + - 1.x + +jobs: + # Set the job key. The key is displayed as the job name + # when a job name is not provided + run-tests: + # Name the Job + name: Publish documentation + # Set the type of machine to run on + runs-on: ubuntu-20.04 + + steps: + # Configures global Git variables for committing + - name: Configure Git + run: | + git config --global user.email "sysadm@codeenigma.com" + git config --global user.name "Code Enigma CI" + # Installs the ce-dev stack + - name: Install ce-dev + run: | + cd /tmp + wget https://golang.org/dl/go1.15.8.linux-amd64.tar.gz + sudo tar -C /usr/local -xzf go1.15.8.linux-amd64.tar.gz + export PATH=$PATH:/usr/local/go/bin + git clone https://github.com/FiloSottile/mkcert && cd mkcert + go build -ldflags "-X main.Version=$(git describe --tags)" + sudo mv ./mkcert /usr/local/bin && cd ../ + sudo chmod +x /usr/local/bin/mkcert + rm -Rf mkcert + curl -sL https://raw.githubusercontent.com/codeenigma/ce-dev/1.x/install.sh | /bin/sh -s -- linux + # Uses the ce-dev stack to run Hugo to format and deploy the docs + - name: Publish documentation + run: | + cd + git clone https://github.com/codeenigma/wikis2pages.git + cd wikis2pages + /bin/bash init.sh https://${{ secrets.GITHUB_TOKEN }}@github.com/codeenigma/ce-dev.git 1.x + /bin/sh set-current.sh ce-dev-1.x + docker exec --user ce-dev --workdir /home/ce-dev/deploy/live.local wikis2pages-hugo hugo + /bin/sh .github-actions-push.sh + cd /home/runner/wikis2pages/public/ce-dev-1.x + git remote add ci https://${{ secrets.DOCS_GITHUB_TOKEN }}@github.com/codeenigma/ce-dev-docs.git + git push ci master + shell: bash diff --git a/.github/workflows/ce-provision-build-docs.yml b/.github/workflows/ce-provision-build-docs.yml new file mode 100644 index 0000000..bbd1c64 --- /dev/null +++ b/.github/workflows/ce-provision-build-docs.yml @@ -0,0 +1,48 @@ +name: Build docs + +# Run this workflow every time a new commit pushed to your repository +on: pull_request + +jobs: + # Set the job key. The key is displayed as the job name + # when a job name is not provided + build-docs: + # Name the Job + name: Build the documentation + # Set the type of machine to run on + runs-on: ubuntu-20.04 + + steps: + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout code + if: ${{ github.event.pull_request.head.ref != 'documentation' }} + uses: actions/checkout@v2 + + # Configures global Git variables for committing + - name: Configure Git + run: | + git config --global user.email "sysadm@codeenigma.com" + git config --global user.name "Code Enigma CI" + + # Builds the docs + - name: Build documentation + if: ${{ github.event.pull_request.head.ref != 'documentation' }} + run: | + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} + git fetch + git checkout documentation + contribute/toc.sh + git add docs + git diff --quiet && git diff --staged --quiet || git commit -am 'GitHub Actions - Rebuilt documentation.' && git push origin documentation + shell: bash + + # Create docs pull request + - name: Create a documentation pull request + if: ${{ github.event.pull_request.head.ref != 'documentation' && github.event.pull_request.base.ref == '1.x' }} + uses: devops-infra/action-pull-request@v0.4.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + source_branch: documentation + target_branch: ${{ github.event.pull_request.base.ref }} + title: Documentation update. + body: "**Automated pull request** created by GitHub Actions because of a documentation update." From c002862fddd4ef71ef54e0a1df06a7fda284342a Mon Sep 17 00:00:00 2001 From: gregharvey Date: Mon, 17 Jan 2022 13:41:07 +0100 Subject: [PATCH 2/4] ce-dev didn't have the toc.sh docs builder script. --- contribute/toc.sh | 140 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100755 contribute/toc.sh diff --git a/contribute/toc.sh b/contribute/toc.sh new file mode 100755 index 0000000..face006 --- /dev/null +++ b/contribute/toc.sh @@ -0,0 +1,140 @@ +#!/bin/sh +# shellcheck disable=SC2094 +# shellcheck disable=SC2129 +IFS=$(printf '\n\t') +set -e +OWN_DIR=$(dirname "$0") +cd "$OWN_DIR" || exit 1 +OWN_DIR=$(git rev-parse --show-toplevel) +cd "$OWN_DIR" || exit 1 +OWN_DIR=$(pwd -P) + +# @param +# $1 string filepath +cp_role_page(){ + RELATIVE=$(realpath --relative-to="$OWN_DIR" "$(dirname "$1")") + if [ ! -d "$OWN_DIR/docs/$RELATIVE" ]; then + mkdir -p "$OWN_DIR/docs/$RELATIVE" + fi + cp "$1" "$OWN_DIR/docs/$RELATIVE.md" +} + +# @param +# $1 string folder +cp_single_page(){ + if [ ! -d "$OWN_DIR/docs/$1" ]; then + mkdir "$OWN_DIR/docs/$1" + fi + cp "$OWN_DIR/$1/README.md" "$OWN_DIR/docs/$1.md" +} + +# @param +# $1 (string) filename +parse_role_variables(){ + TMP_MD=$(mktemp) + WRITE=1 + # Ensure we have a trailing line. + echo "" >> "$1" + while read -r LINE; do + case $LINE in + '') + echo "$LINE" >> "$TMP_MD" + generate_role_variables "$1" + WRITE=0 + ;; + '') + echo "$LINE" >> "$TMP_MD" + WRITE=1 + ;; + '') + echo "$LINE" >> "$TMP_MD" + WRITE=0 + ;; + '') + echo "$LINE" >> "$TMP_MD" + WRITE=1 + ;; + *) + if [ $WRITE = 1 ]; then + echo "$LINE" >> "$TMP_MD" + fi + ;; + esac + done < "$1" + printf '%s\n' "$(cat "$TMP_MD")" > "$1" + rm "$TMP_MD" +} + +# @param +# $1 (string) filename +generate_role_variables(){ + VAR_FILE="$(dirname "$1")/defaults/main.yml" + if [ -f "$VAR_FILE" ]; then + echo "## Default variables" >> "$TMP_MD" + echo '```yaml' >> "$TMP_MD" + cat "$VAR_FILE" >> "$TMP_MD" + echo "" >> "$TMP_MD" + echo '```' >> "$TMP_MD" + echo "" >> "$TMP_MD" + fi +} + +generate_roles_toc(){ + TMP_SIDEBAR=$(mktemp) + WRITE="true" + while read -r LINE; do + case $LINE in + " - [Roles](roles)") + echo "$LINE" >> "$TMP_SIDEBAR" + parse_roles_toc roles 2 + WRITE="false" + ;; + " -"*) + WRITE="true" + echo "$LINE" >> "$TMP_SIDEBAR" + ;; + *) + if [ "$WRITE" = "true" ]; then + echo "$LINE" >> "$TMP_SIDEBAR" + fi + ;; + esac + done < "$OWN_DIR/docs/_Sidebar.md" + mv "$TMP_SIDEBAR" "$OWN_DIR/docs/_Sidebar.md" +} + +parse_roles_toc(){ + ROLES=$(find "$OWN_DIR/$1" -mindepth 2 -maxdepth 2 -name "README.md" | sort) + for ROLE in $ROLES; do + WRITE="true" + INDENT=$(printf %$(($2 * 2))s) + RELATIVE=$(realpath --relative-to="$OWN_DIR" "$(dirname "$ROLE")") + while read -r LINE; do + case $LINE in + "# "*) + if [ "$WRITE" = "true" ]; then + TITLE=$(echo "$LINE" | cut -c 3-) + echo "$INDENT"" - [$TITLE](/$RELATIVE)" >> "$TMP_SIDEBAR" + WRITE="false" + fi + ;; + esac + done < "$ROLE" + parse_roles_toc "$RELATIVE" $(($2 + 1)) + done +} + +rm -rf "$OWN_DIR/docs/roles" +ROLE_PAGES=$(find "$OWN_DIR/roles" -name "README.md") +for ROLE_PAGE in $ROLE_PAGES; do + parse_role_variables "$ROLE_PAGE" +done +for ROLE_PAGE in $ROLE_PAGES; do + cp_role_page "$ROLE_PAGE" +done +generate_roles_toc + + +cp_single_page install +cp_single_page contribute +cp_single_page scripts \ No newline at end of file From 398cf8c85e6a0d66873ec2a97c21893378d26364 Mon Sep 17 00:00:00 2001 From: gregharvey Date: Mon, 17 Jan 2022 15:59:13 +0100 Subject: [PATCH 3/4] Removing doc push step from build job, it has its own job now. --- .github/workflows/ce-dev-build.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/ce-dev-build.yml b/.github/workflows/ce-dev-build.yml index 946aa33..d9c3601 100644 --- a/.github/workflows/ce-dev-build.yml +++ b/.github/workflows/ce-dev-build.yml @@ -51,16 +51,3 @@ jobs: body_path: RELEASE env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Build and publish docs - run: | - cd - curl -sL https://raw.githubusercontent.com/codeenigma/ce-dev/1.x/install.sh | /bin/sh -s -- linux - git clone https://github.com/codeenigma/wikis2pages.git - cd wikis2pages - /bin/sh init.sh https://${{ secrets.GITHUB_TOKEN }}@github.com/codeenigma/ce-dev.git 1.x - /bin/sh set-current.sh ce-dev-travis - docker exec --user ce-dev --workdir /home/ce-dev/deploy/live.local wikis2pages-hugo hugo - /bin/sh .github-actions-push.sh - cd /home/runner/wikis2pages/public/ce-dev-travis - git remote add ci https://${{ secrets.DOCS_GITHUB_TOKEN }}@github.com/codeenigma/ce-dev-docs.git - git push ci master From 597691f2432cd65b41b76aa1a8406dbdc2445aeb Mon Sep 17 00:00:00 2001 From: gregharvey Date: Tue, 18 Jul 2023 18:28:23 +0200 Subject: [PATCH 4/4] Updating docs URL for CI to https. --- .wikis2pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.wikis2pages.yml b/.wikis2pages.yml index f883060..51bc6ba 100644 --- a/.wikis2pages.yml +++ b/.wikis2pages.yml @@ -2,7 +2,7 @@ ce-dev-local: src: https://github.com/codeenigma/ce-dev.git src_branch: 1.x src_subdir: 'docs' - dest: git@github.com:codeenigma/ce-dev-docs.git + dest: https://github.com/codeenigma/ce-dev-docs.git dest_branch: master dest_subdir: 1.x title: ce-dev