Skip to content

Commit

Permalink
Add preprocessor bash script for syncing documentation files to wiki
Browse files Browse the repository at this point in the history
Change documentation file names to be more user-friendly by removing the special characters.
Thus add refactoring within the script that renames the files (to be compatible with GItHub wiki) before pushing to wiki.
Also add preprocessing within the script that automatically replaces pre-defined macros within documentation files with correct and updated links.

This commit makes bi-directional syncing much more tedious, so it has been dropped. Only changes in the docs folder in the main repo will be pushed to the wiki. Changes directly to the wiki repo will no longer be persisted.
The contribution guidelines will need to be significantly udpated after this commit.
The script could also be converted into CMake instead of bash if need be,
  • Loading branch information
Arastais committed Jan 17, 2024
1 parent e52680e commit 5719797
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 116 deletions.
67 changes: 67 additions & 0 deletions .github/actions/wiki_sync/refactor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
# 'docs' folder needs to be set as the working directory

# Declare arrays
declare -a titles
declare -a keys

# Special characters that are used for refactoring
dash=$(echo -e "\xE2\x80\x90")
dash_url="%E2%80%90"
colon=$(echo -e "\xEA\x9E\x89")
colon_url="%EA%9E%89"

# Output colors
cyan="\033[1;36m"
green="\033[1;32m"
reset="\033[0m"

# Store the file name and id for each extension
# Also refactor the file names
cd Extensions
for file in XLE-*.md; do
id=$(grep -oP "XLE-\K[0-9]+" <<< ${file%.md})
name=$(grep -oP "XLE-([0-9]+)=\K.*" <<< ${file%.md})
keys[$id]=$(sed -e "s/-/$dash/g" -e "s/_/-/g" <<< $name)
titles[$id]=$(sed "s/_/ /g" <<< $name)
echo -e "${cyan}Found '${green}XLE-$id${cyan}: ${titles[$id]}' ${reset}(Refactoring to '${keys[$id]}')"
mv $file "XLE$dash$id$colon-${keys[$id]}.md"
done

# Refactor extension set file names
cd ../Extension\ Sets
extset_list=""
extset_list_macro='\${EXTSET_LIST}'
for file in *.md; do
name=$(grep -oP '\`\K(.*?)(?=\`)' <<< "$file")
renamed=$(sed -e "s/-/$dash/g" -e "s/_/-/g" <<< "$file")
extset_list="$extset_list[$name](Extension-Set-$renamed)\n\n"
echo -e "${cyan}Found extension set \`${green}$name${cyan}\` ${reset}(Renaming to 'Extension-Set-$renamed')"
mv $file "Extension-Set-$renamed"
done

# Replace ${XLE-#}, ${XLE-#_LINK}, and ${XLE-#_NAME} macros in each file
cd ..
for file in ./Extensions/*.md ./Extension\ Sets/*.md; do
for id in $(grep -oP '\${XLE-\K([0-9]+)(?=.*?})' "$file" | sort -u); do
macro_prefix='\${XLE-'$id
link="XLE$dash_url$id$colon_url-${keys[$id]}"
name="${titles[$id]}"
sed -i \
-e "s|${macro_prefix}}|[XLE-$id: $name]($link)<br\/>|g" \
-e "s|${macro_prefix}_LINK}|$link|g" \
-e "s|${macro_prefix}_NAME}|$name|g" \
"$file"
done;
done

# Replace ${XLE_LIST} and ${EXTSET_LIST}in _Sidebar.md
ext_list=""
ext_list_macro='\${XLE_LIST}'
for id in "${!titles[@]}"; do
ext_list="$ext_list[XLE-$id: ${titles[$id]}](XLE$dash_url$id$colon_url-${keys[$id]}) <br\/>\n"
done
sed -i \
-e "s|$ext_list_macro|$ext_list|g" \
-e "s|$extset_list_macro|$extset_list|g" \
"_Sidebar.md"
94 changes: 30 additions & 64 deletions .github/workflows/wiki_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,23 @@ on:
push:
paths:
- "docs/**"
workflow_dispatch:
repository_dispatch:
types: [docs]
gollum:


env:
docs: $GITHUB_WORKSPACE/main/docs
wiki: $GITHUB_WORKSPACE/wiki
docs: ./main/docs
wiki: ./wiki
#suffix: [github-actions-bot]

jobs:
check-diff:
name: Check for changes
runs-on: ubuntu-latest
if: github.sender.login != 'github-actions[bot]'
outputs:
DIFF: ${{ steps.diff-check.outputs.DIFF }}
steps:
- name: Print Sender (For Logging Purposes)
run: echo "${{ github.event.sender.login }}"
- name: Checkout Main Repo
uses: actions/checkout@v3
with:
path: main
- name: Checkout Wiki Repo
uses: actions/checkout@v3
with:
path: wiki
repository: ${{github.repository}}.wiki
- name: Check for Differences
id: diff-check
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "DIFF<<$EOF" >> "$GITHUB_OUTPUT"
# The echo is here to put a newline so that github doesn't complain about a missing newline
diff -qr --exclude=.git "${{env.docs}}" "${{env.wiki}}" >> "$GITHUB_OUTPUT" && echo "" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Print Output
run: echo "${{steps.diff-check.outputs.DIFF}}"


jobs:
sync:
name: Sync Docs with Wiki
name: Sync Docs to Wiki
runs-on: ubuntu-latest
needs: check-diff
permissions:
contents: write
if: needs.check-diff.outputs.DIFF != ''
steps:
- name: Checkout Main Repo
uses: actions/checkout@v3
Expand All @@ -62,66 +33,61 @@ jobs:
path: wiki
repository: ${{github.repository}}.wiki
#token: ${{env.token}}
# Go to source folder
- name: Set Wiki as Source Folder
if: github.event_name == 'gollum'
run: |
echo "SRC=${{env.wiki}}" >> $GITHUB_ENV
echo "DST=${{env.docs}}" >> $GITHUB_ENV
- name: Set Docs as Source Folder
if: github.event_name != 'gollum'
run: |
echo "SRC=${{env.docs}}" >> $GITHUB_ENV
echo "DST=${{env.wiki}}" >> $GITHUB_ENV
- name: Get Commit Author
id: get-author
working-directory: ${{env.SRC}}
working-directory: ${{env.docs}}
run: echo "AUTHOR=$(git log -1 --format="%an")" >> $GITHUB_OUTPUT
- name: Get Commit Email
id: get-email
working-directory: ${{env.SRC}}
working-directory: ${{env.docs}}
run: echo "EMAIL=$(git log -1 --format="%ae")" >> $GITHUB_OUTPUT
- name: Print Commit Message
working-directory: ${{env.SRC}}
working-directory: ${{env.docs}}
run: echo "$(git log -1 --format="%B")"
- name: Get Commit Message
id: get-message
working-directory: ${{env.SRC}}
working-directory: ${{env.docs}}
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "MESSAGE<<$EOF" >> "$GITHUB_OUTPUT"
git log -1 --format="%B" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Get Source Commit Subject
id: get-src-sub
working-directory: ${{env.SRC}}
working-directory: ${{env.docs}}
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "SUB<<$EOF" >> "$GITHUB_OUTPUT"
git log -1 --format="%s" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Get Destination Commit Subject
id: get-dst-sub
working-directory: ${{env.DST}}
working-directory: ${{env.wiki}}
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "SUB<<$EOF" >> "$GITHUB_OUTPUT"
git log -1 --format="%s" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Copy Source Files to Destination
- name: Preprocess and Refactor Files
working-directory: ${{env.docs}}
run: |
chmod +x ../.github/actions/wiki_sync/refactor.sh
../.github/actions/wiki_sync/refactor.sh
shell: bash
- name: Copy Doc Files to Wiki
run: |
rsync -avzr --delete --exclude='.git/' "${{env.SRC}}/" "${{env.DST}}/"
rsync -avzr --delete --exclude='.git/' "${{env.docs}}/" "${{env.wiki}}/"
- name: Push
working-directory: ${{env.DST}}
working-directory: ${{env.wiki}}
run: |
export GIT_AUTHOR_NAME="github-actions[bot]"
export GIT_AUTHOR_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
export GIT_COMMITTER_NAME="${{ steps.get-author.outputs.AUTHOR }}"
export GIT_COMMITTER_EMAIL="${{ steps.get-email.outputs.EMAIL }}"
#export GIT_AUTHOR_NAME="${{ steps.get-author.outputs.AUTHOR }}"
#export GIT_AUTHOR_EMAIL="${{ steps.get-email.outputs.EMAIL }}"
#export GIT_COMMITTER_NAME="github-actions[bot]"
#export GIT_COMMITTER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
#export GIT_AUTHOR_NAME="github-actions[bot]"
#export GIT_AUTHOR_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
#export GIT_COMMITTER_NAME="${{ steps.get-author.outputs.AUTHOR }}"
#export GIT_COMMITTER_EMAIL="${{ steps.get-email.outputs.EMAIL }}"
export GIT_AUTHOR_NAME="${{ steps.get-author.outputs.AUTHOR }}"
export GIT_AUTHOR_EMAIL="${{ steps.get-email.outputs.EMAIL }}"
export GIT_COMMITTER_NAME="github-actions[bot]"
export GIT_COMMITTER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
git add .
if [ "${{ steps.get-src-sub.outputs.SUB }}" = ${{ steps.get-dst-sub.outputs.SUB }}]; then
git commit --amend --no-edit
Expand Down
12 changes: 0 additions & 12 deletions docs/Extension Sets/Extension-Set-`ini`.md

This file was deleted.

12 changes: 0 additions & 12 deletions docs/Extension Sets/Extension-Set-`json`.md

This file was deleted.

12 changes: 0 additions & 12 deletions docs/Extension Sets/Extension-Set-`toml`.md

This file was deleted.

12 changes: 12 additions & 0 deletions docs/Extension Sets/`ini`.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**Functionality:** INI Backwards Compatibility

**Version**: 1.0

**Created On**: May 18th, 2023

**Extension List:**

${XLE-2}
${XLE-6}
${XLE-8}
${XLE-9}
12 changes: 12 additions & 0 deletions docs/Extension Sets/`json`.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**Functionality:** JSON Backwards Compatibility

**Version**: 1.0

**Created On**: May 17th, 2023

**Extension List:**

${XLE-3}
${XLE-5}
${XLE-6}
${XLE-7}
12 changes: 12 additions & 0 deletions docs/Extension Sets/`toml`.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**Functionality:** TOML Backwards Compatibility

**Version**: 1.0

**Created On**: May 17th, 2023

**Extension List:**

${XLE-2}
${XLE-3}
${XLE-6}
${XLE-8}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ In addition to JSON compatiblity, this extension can be used for convenience pur
The below example demonstrates how, for example, a C++ enum can be seamlessly copied into an XSON object;
The enum contents are unchanged.

Note that in this specific example, [XLE-2 (Equals as Key-Value Separator)](XLE%u20102%uA789-Equals-as-Key%u2010Value-Separator)
Note that in this specific example, [XLE-2 (${XLE-2_NAME})](${XLE-2_LINK})
is needed due to C++'s syntax.
<table><tr>

Expand Down
File renamed without changes.
17 changes: 2 additions & 15 deletions docs/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@

<details><summary><h1>Extensions</h1></summary>

[XLE-0: Schema Files](XLE%E2%80%900%EA%9E%89-Schema-Files)<br>
[XLE-1: Omit Key-Value Separator](XLE%E2%80%901%EA%9E%89-Omit-Key%E2%80%90Value-Separator)<br>
[XLE-2: Equals as Key-Value Separator](XLE%E2%80%902%EA%9E%89-Equals-as-Key%E2%80%90Value-Separator)<br>
[XLE-3: All Value Types in Arrays](XLE%E2%80%903%EA%9E%89-All-Value-Types-in-Arrays)</a><br>
[XLE-4: Escaped Characters](XLE%E2%80%904%EA%9E%89-Escaped-Characters)<br>
[XLE-5: Commas After Values](XLE%E2%80%905%EA%9E%89-Commas-After-Values)<br>
[XLE-6: Quoted Strings](XLE%E2%80%906%EA%9E%89-Quoted-Strings)<br>
[XLE-7: Root-Level Object or Array](XLE%E2%80%907%EA%9E%89-Root%E2%80%90Level-Object-or-Array)<br>
[XLE-8: Headers for Objects](XLE%E2%80%908%EA%9E%89-Headers-for-Objects)<br>
[XLE-9: Alternate Comment Characters](XLE%E2%80%909%EA%9E%89-Alternate-Comment-Characters)<br>
${XLE_LIST}

</details>

Expand All @@ -40,11 +31,7 @@
[//]: # (<a href="">qol</a><br>)
[//]: # (<a href="">qol-1.1</a>)

[ini](Extension-Set-`ini`)

[json](Extension-Set-`json`)

[toml](Extension-Set-`toml`)
${EXTSET_LIST}

[//]: # (<a href="">yaml</a>)
</details>
Expand Down

1 comment on commit 5719797

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

❌ Errors Count
❌ no-files-to-check 1
ℹ️ non-alpha-in-dictionary 1

See ❌ Event descriptions for more information.

Please sign in to comment.