Skip to content

Commit

Permalink
chore: build doc - WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Sep 11, 2024
1 parent 7850698 commit b607993
Showing 1 changed file with 92 additions and 16 deletions.
108 changes: 92 additions & 16 deletions generateDoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
# Software description: A SwiftUI components library with code examples for Orange Unified Design System
#

# Controls on script
set -euo pipefail

echo "👉 Generating docs..."
# The name of the Git branch hosting GitHub Pages service
GH_PAGES_BRANCH="gh-pages"

DOCS_DIRECTORY=./docs
mkdir -p ${DOCS_DIRECTORY}
# The generated name of the ZIP containing the generated sources of documentation (for archive)
timestamp=$(date +%s)
DOCUMENTATION_ZIP_NAME="documentation-$timestamp.zip"
DOCUMENTATION_ZIP_LOCATION="/tmp/$DOCUMENTATION_ZIP_NAME"

# Path where the documentation will be
DOCS_DIRECTORY="./docs"
mkdir -p "$DOCS_DIRECTORY"

# The targets to build documentation of
TARGETS="OUDS \
OUDSThemesSosh \
OUDSThemesInverse \
Expand All @@ -30,34 +39,101 @@ TARGETS="OUDS \
OUDSModules \
OUDSFoundations"

# Step 1 - For each target, build the DocC documentation
# ------------------------------------------------------

# Start timer (for elapsed time computation)
SECONDS=0

echo "🍊👉 Generating docs..."

currentBranch=$(git rev-parse --abbrev-ref HEAD)
echo "🍊🔨 Cleaning Git repository before generation (current Git branch is '$currentBranch')"
git reset --hard
git clean -fd
git branch -D "$GH_PAGES_BRANCH"
git fetch origin

for target in ${TARGETS}
do
echo "👉 Generating docs for $target..."
echo "🍊👉 Generating docs for $target..."
swift package --allow-writing-to-directory "$target-docs" generate-documentation --disable-indexing --transform-for-static-hosting --output-path "$target-docs" --target "$target"

cp -r $target-docs/* ${DOCS_DIRECTORY}
cp -r $target-docs/* $DOCS_DIRECTORY
modified_target=$(echo $target | tr '-' '_' | tr '[:upper:]' '[:lower:]')
cp -r $target-docs/index/index.json "${DOCS_DIRECTORY}/index/$modified_target.json"
echo "👍 Docs generated for $target!"
cp -r $target-docs/index/index.json "$DOCS_DIRECTORY/index/$modified_target.json"
echo "🍊👍 Docs generated for $target!"
done

echo "👉 Updating index.html..."
# Step 2 - Add CNAME file for GitHub Pages
# ----------------------------------------

echo "🍊👉 Updating CNAME file"
echo "ios.unified-design-system.orange.com" > "$DOCS_DIRECTORY/CNAME"
echo "🍊👍 Updated!"

# Step 3 - Update global HTML file
# --------------------------------

echo "🍊👉 Updating index.html..."

# TODO: Stylesheet

echo "<!DOCTYPE html><html><head></head><body><ol>" > ${DOCS_DIRECTORY}/index.html
echo "<!DOCTYPE html><html><head></head><body><ol>" > $DOCS_DIRECTORY/index.html

for target in ${TARGETS}
do
cp -R $target-docs/data/documentation/* ${DOCS_DIRECTORY}/data/documentation/
cp -R $target-docs/documentation/* ${DOCS_DIRECTORY}/documentation/
cp -R $target-docs/data/documentation/* $DOCS_DIRECTORY/data/documentation/
cp -R $target-docs/documentation/* $DOCS_DIRECTORY/documentation/
rm -r "$target-docs"
modified_target=$(echo $target | tr '-' '_' | tr '[:upper:]' '[:lower:]')
echo "<li><a href=\"./documentation/$modified_target\">$target</a></li>" >> ${DOCS_DIRECTORY}/index.html
echo "<li><a href=\"./documentation/$modified_target\">$target</a></li>" >> $DOCS_DIRECTORY/index.html
done

echo "</ol></body></html>" >> ${DOCS_DIRECTORY}/index.html
echo "</ol></body></html>" >> $DOCS_DIRECTORY/index.html

echo "🍊👍 index.html updated!"

# Step 4 - Checkout to GitHub Pages dedicated branch
# --------------------------------------------------

echo "🍊👉 Versioning documentation in GitHub Pages branch (it can take a lot of time)..."

echo "🍊🔨 Stashing things"
git stash -u

echo "🍊🔨 Checkout GitHub Pages branch"
git checkout $GH_PAGES_BRANCH

echo "🍊🔨 Unstashing things"
git stash apply

echo "🍊🔨 Adding things"
git add $DOCS_DIRECTORY

filesCount=`find $DOCS_DIRECTORY -type f | wc -l`

echo "🍊🔨 Commiting things"
git commit -m $'doc: update DocC documentation for GitHub Pages\n\nWARNING: This is an automatic commit'

echo "🍊🔨 Pushing things"
git push origin

echo "🍊🔨 Cleaning stashes"
git stash clear

commitHash=`git rev-parse HEAD`

echo "🍊🔨 Going back to previous Git branch"
git checkout "$currentBranch"

echo "🍊👍 Pushed with commit '$commitHash'"
echo "🍊🎉 Documentation also available in $DOCS_DIRECTORY"
echo "🍊🧮 There are '$filesCount' in $DOCS_DIRECTORY!"

echo "👍 index.html updated!"
echo "🍊👉 Zipping documentation folder"
zip -r "$DOCUMENTATION_ZIP_LOCATION" "$DOCS_DIRECTORY"
echo "🍊👍 Documentation ZIP available at $DOCUMENTATION_ZIP_LOCATION"

echo "👍 Docs generated!"
echo "🍊⌛ Elapsed time: $SECONDS seconds"

echo "🎉 Documentation available in ${DOCS_DIRECTORY}"

0 comments on commit b607993

Please sign in to comment.