|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Based on `push_docs_to_gh_pages.sh` |
| 4 | +# Significant alterations |
| 5 | +# - Support for multiple copies of documentation, |
| 6 | +# - only clearing out develop |
| 7 | +# - index.md logging doc history |
| 8 | + |
| 9 | +# How to run: |
| 10 | +# - From repository root .github/scripts/push_docs_to_gh_pages.sh |
| 11 | + |
| 12 | +# Required files / directories (relative from repo root) |
| 13 | +# - File: "docs/index.md" with that contains develop docs |
| 14 | + |
| 15 | +# Required ENV Variables |
| 16 | +LATEST_DOCS_BRANCH="develop" |
| 17 | +GITHUB_IO_REPO='utPLSQL/utPLSQL.github.io' |
| 18 | +GITHUB_IO_BRANCH='main' |
| 19 | +DOCS_DIR='../../docs/.' |
| 20 | + |
| 21 | +# ENV Variable checks are to help with configuration troubleshooting, they silently exit with unique message. |
| 22 | +# Anyone one of them not set can be used to turn off this functionality. |
| 23 | + |
| 24 | +# If a version of the project is not defined |
| 25 | +[[ -n "${UTPLSQL_VERSION}" ]] || { echo "variable UTPLSQL_VERSION is not defines or missing value"; exit 1; } |
| 26 | +# Fail if the markdown documentation is not present. |
| 27 | +[[ -f ./docs/index.md ]] || { echo "file docs/index.md not found"; exit 1; } |
| 28 | + |
| 29 | +# Store latest commit SHA to be used when committing and pushing to github.io repo |
| 30 | +SHA=`git rev-parse --verify HEAD` |
| 31 | + |
| 32 | +# clone the repository and switch to GITHUB_IO_BRANCH branch |
| 33 | +mkdir pages |
| 34 | +cd ./pages |
| 35 | +git clone --depth 1 https://${API_TOKEN_GITHUB}@github.com/${GITHUB_IO_REPO} -b ${GITHUB_IO_BRANCH} . |
| 36 | + |
| 37 | +mkdir -p utPLSQL |
| 38 | +cd ./utPLSQL |
| 39 | +#clear out develop documentation directory and copy docs contents to it. |
| 40 | +echo "updating 'develop' documentation directory" |
| 41 | +mkdir -p ./develop |
| 42 | +rm -rf ./develop/**./* || exit 0 |
| 43 | +cp -a ${DOCS_DIR} ./develop |
| 44 | + |
| 45 | +# If a Tagged Build then copy to it's own directory as well and to the 'latest' release directory |
| 46 | +if [ "${GITHUB_REF_TYPE}" == "tag" ]; then |
| 47 | + echo "Creating directory ./${UTPLSQL_VERSION}" |
| 48 | + mkdir -p ./${UTPLSQL_VERSION} |
| 49 | + rm -rf ./${UTPLSQL_VERSION}/**./* || exit 0 |
| 50 | + cp -a ${DOCS_DIR} ./${UTPLSQL_VERSION} |
| 51 | + echo "Populating 'latest' directory" |
| 52 | + mkdir -p ./latest |
| 53 | + rm -rf ./latest/**./* || exit 0 |
| 54 | + cp -a ${DOCS_DIR} ./latest |
| 55 | +fi |
| 56 | +# Stage changes for commit |
| 57 | +git add . |
| 58 | + |
| 59 | +#Check if there are doc changes, if none exit the script |
| 60 | +if [[ -z `git diff HEAD --exit-code` ]]; then |
| 61 | + echo "No changes to docs detected." |
| 62 | + exit 0 |
| 63 | +fi |
| 64 | +#Changes where detected, so we need to update the version log. |
| 65 | +now=$(date +"%d %b %Y - %r") |
| 66 | +if [ ! -f index.md ]; then |
| 67 | + echo "---" >>index.md |
| 68 | + echo "layout: default" >>index.md |
| 69 | + echo "---" >>index.md |
| 70 | + echo "<!-- Auto generated from .github/scripts/push_docs_to_github_io.sh -->" >>index.md |
| 71 | + echo "# Documentation versions" >>index.md |
| 72 | + echo "" >>index.md |
| 73 | + echo "" >>index.md #- 7th line - placeholder for latest release doc |
| 74 | + echo "" >>index.md #- 8th line - placeholder for develop branch doc |
| 75 | + echo "" >>index.md |
| 76 | + echo "## Released Version Doc History" >>index.md |
| 77 | + echo "" >>index.md |
| 78 | +fi |
| 79 | +#If build running on a TAG - it's a new release - need to add it to documentation |
| 80 | +if [ "${GITHUB_REF_TYPE}" == "tag" ]; then |
| 81 | + sed -i '7s@.*@'" - [Latest ${CI_ACTION_REF_NAME} documentation](latest/) - Created $now"'@' index.md |
| 82 | + #add entry to the top of version history (line end of file - ## Released Version Doc History |
| 83 | + sed -i '12i'" - [${CI_ACTION_REF_NAME} documentation](${UTPLSQL_VERSION}/) - Created $now" index.md |
| 84 | +fi |
| 85 | +#replace 4th line in log |
| 86 | +sed -i '8s@.*@'" - [Latest development version](develop/) - Created $now"'@' index.md |
| 87 | +#Add and Commit the changes back to pages repo. |
| 88 | +git add . |
| 89 | +git commit -m "Deploy to gh-pages branch: base commit ${SHA}" |
| 90 | +# Now that we're all set up, we can push. |
| 91 | +git push --quiet origin HEAD:${GITHUB_IO_BRANCH} |
| 92 | + |
0 commit comments