Skip to content

Commit

Permalink
Restructured repository allowing for the storing of multiple versions (
Browse files Browse the repository at this point in the history
…#29)

Restructed the repository to allow for multiple versions to be
maintained together. The following changes were done:

- Updated the deployment script to allow for the Redocly bundles to be
deployed whenever a new version is available.
- Automatically created a header html to allow for the linking to a
specific version.
- Updated the versions by one bugfix to allow for the link fixes within
the openapi.yaml.
  • Loading branch information
miller79 authored Oct 11, 2024
1 parent 2698347 commit bdbd4f9
Show file tree
Hide file tree
Showing 4 changed files with 1,717 additions and 33 deletions.
71 changes: 63 additions & 8 deletions .github/scripts/create-redoc-static-html.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
#!/bin/bash
set -e

echo "Getting started"
declare currentFolder=$(pwd)
declare publicFolder="$currentFolder/public"
declare allFolders

# Bundle docs into zero-dependency HTML file
npx redoc-cli bundle openapi.yaml && \
mv redoc-static.html index.html && \
echo "Changed name from redoc-static.html to index.html" && \
# Add favicon
sed -i '7 i \ \ <link rel="icon" type="image/png" href="images/favicon.png"/>' index.html && \
echo -e "\nDone!"
# Creates static html files for openapi.yaml file in the current directory
loadStaticHtmlToFolder() {
local folder="$1"

echo "Creating folder $publicFolder/$folder"
mkdir -p $publicFolder/$folder

echo "Running redocly/cli build-docs command on $currentFolder/$folder/openapi.yaml and saving it to $publicFolder/$folder/index.html"
npx @redocly/cli@latest build-docs $currentFolder/$folder/openapi.yaml -o $publicFolder/$folder/index.html
}

# Selects all folders in the current directory
selectAllFoldersInDirectory() {
local -n folders=$1

echo "Selecting all folders in $currentFolder"

# Use glob pattern to get all directories
for dir in "$currentFolder"/*/; do
# Check if it's a directory
if [ -d "$dir" ] && [[ "$dir" != */images/ ]] && [[ "$dir" != */public/ ]]; then
folders+=("$dir")
fi
done

# Stripping the path and getting only the folder name
folders=("${folders[@]%/}")
folders=("${folders[@]##*/}")
}

# Initializes the public folder
initializePublicFolder() {
echo "Creating $publicFolder"
mkdir -p $publicFolder

echo "Copying $currentFolder/images folder to $publicFolder"
cp -r $currentFolder/images $publicFolder
}

# Creates index.html file
createIndexHtml() {
local -n folders=$1

echo "Creating index.html in $publicFolder"
local indexHtml="$publicFolder/index.html"
echo "<html><head><title>SSC API</title></head><body><h1>SSC API</h1><ul>" > $indexHtml
for folder in "${folders[@]}"; do
echo "<li><a href=\"$folder/\">$folder</a></li>" >> $indexHtml
done
echo "</ul></body></html>" >> $indexHtml
}

selectAllFoldersInDirectory allFolders
initializePublicFolder
createIndexHtml allFolders

for directory in "${allFolders[@]}"; do
loadStaticHtmlToFolder $directory
done
7 changes: 3 additions & 4 deletions .github/workflows/deploy-redoc-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Build docs
run: ./.github/scripts/create-redoc-static-html.sh
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3 # https://github.com/peaceiris/actions-gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: .
publish_dir: ./public
force_orphan: true
exclude_assets: '.github,openapi.yaml,.redocly.yaml,LICENSE,README.md,make.sh'

permissions:
contents: write
Loading

0 comments on commit bdbd4f9

Please sign in to comment.