Skip to content

Commit

Permalink
Create Bash script to build & push Redocly documentation to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoon97 committed Aug 2, 2023
1 parent 686c86e commit dd0d452
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions build_and_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

GIT_COMMIT_MSG="Build and publish Redocly documentation"
REDOCLY_GIT_BRANCH=redocly-build
REDOCLY_NPM_PKG=@redocly/cli
REDOCLY_OUTPUT_DIR=docs

console_log () {
local COLOR_BLUE="\033[0;34m"
local COLOR_OFF="\033[0m"
echo -e "${COLOR_BLUE}[Build & Push]:${COLOR_OFF} $1"
}

# If $REDOCLY_GIT_BRANCH doesn't exist, create it
if git rev-parse --verify $REDOCLY_GIT_BRANCH > /dev/null; then
console_log "Branch $REDOCLY_GIT_BRANCH found, attempting to check out..."

if [[ $(git rev-parse --abbrev-ref HEAD) != "$REDOCLY_GIT_BRANCH" ]]; then
git checkout $REDOCLY_GIT_BRANCH
else
console_log "Branch $REDOCLY_GIT_BRANCH is already checked out, skipping..."
fi
else
console_log "Branch $REDOCLY_GIT_BRANCH doesn't exist, attempting to create..."
git checkout -b $REDOCLY_GIT_BRANCH
fi

# Install $REDOCLY_NPM_PKG CLI if it doesn't exist
if [[ $(pnpm list --depth 0 -g | grep -q $REDOCLY_NPM_PKG; echo $?) == 1 ]]; then
console_log "Package $REDOCLY_NPM_PKG not found, attempting to install it..."
pnpm add -g $REDOCLY_NPM_PKG
fi

console_log "Deleting and recreating $REDOCLY_OUTPUT_DIR"
rm -r $REDOCLY_OUTPUT_DIR && mkdir $REDOCLY_OUTPUT_DIR

console_log "Bundling and building Redocly documentation..."
redocly bundle spec.json --ext=json -o $REDOCLY_OUTPUT_DIR/bundled.json
redocly build-docs $REDOCLY_OUTPUT_DIR/bundled.json -o $REDOCLY_OUTPUT_DIR/index.html

# Remove bundled JSON since it's no longer needed
rm $REDOCLY_OUTPUT_DIR/bundled.json

# Commit & push changes to GitHub
console_log "Committing with message '$GIT_COMMIT_MSG'"
git commit --allow-empty -m "$GIT_COMMIT_MSG"
git push -u origin $REDOCLY_GIT_BRANCH

0 comments on commit dd0d452

Please sign in to comment.