Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82c4d21

Browse files
committed
Testing publishing of documentation to gh-pages
1 parent 169f61c commit 82c4d21

2 files changed

Lines changed: 84 additions & 68 deletions

File tree

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,24 @@ jobs:
209209
)
210210
}}
211211
212+
- name: Copy and push documentation to utPLSQL-github-io repo
213+
env:
214+
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
215+
run: .travis/push_docs_to_github_io.sh
216+
shell: bash
217+
if: |
218+
${{
219+
github.repository == 'utPLSQL/utPLSQL'
220+
&& (github.ref_type == 'branch'
221+
&& ( startsWith(env.CURRENT_BRANCH,'release/')
222+
|| env.CURRENT_BRANCH == 'develop'
223+
|| env.CURRENT_BRANCH == 'feature/github_actions'
224+
)
225+
|| github.ref_type == 'tag'
226+
)
227+
}}
228+
229+
212230
213231
# TODO - add slack notifications
214232
# TODO - add push of documentation

.travis/push_docs_to_github_io.sh

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,81 +17,79 @@ LATEST_DOCS_BRANCH="develop"
1717
GITHUB_IO_REPO='utPLSQL/utPLSQL.github.io'
1818
GITHUB_IO_BRANCH='main'
1919

20-
# TRAVIS_* variables are set by travis directly and only need to be if testing externally
2120

22-
# We deploy only when building on develop branch or on TAG (release)
23-
if [ "${PULL_REQUEST_NAME}" == "false" ] && { [ "${CURRENT_BRANCH}" == "${LATEST_DOCS_BRANCH}" ] || [ -n "${TAG_NAME}" ]; }; then
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.
2423

25-
# ENV Variable checks are to help with configuration troubleshooting, they silently exit with unique message.
26-
# Anyone one of them not set can be used to turn off this functionality.
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; }
2728

28-
# If a version of the project is not defined
29-
[[ -n "${UTPLSQL_VERSION}" ]] || { echo "variable UTPLSQL_VERSION is not defines or missing value"; exit 1; }
30-
# Fail if the markdown documentation is not present.
31-
[[ -f ./docs/index.md ]] || { echo "file docs/index.md not found"; exit 1; }
29+
# Store latest commit SHA to be used when committing and pushing to github.io repo
30+
SHA=`git rev-parse --verify HEAD`
3231

33-
# Store latest commit SHA to be used when committing and pushing to github.io repo
34-
SHA=`git rev-parse --verify HEAD`
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} .
3536

36-
# clone the repository and switch to GITHUB_IO_BRANCH branch
37-
mkdir pages
38-
cd ./pages
39-
git clone --depth 1 https://${github_api_token}@github.com/${GITHUB_IO_REPO} -b ${GITHUB_IO_BRANCH} .
37+
git config user.email "github-actions[bot]@users.noreply.github.com"
38+
git config user.name "github-actions[bot]"
4039

41-
mkdir -p utPLSQL
42-
cd ./utPLSQL
43-
#clear out develop documentation directory and copy docs contents to it.
44-
echo "updating 'develop' documentation directory"
45-
mkdir -p ./develop
46-
rm -rf ./develop/**./* || exit 0
47-
cp -a ../../docs/. ./develop
40+
mkdir -p utPLSQL
41+
cd ./utPLSQL
42+
#clear out develop documentation directory and copy docs contents to it.
43+
echo "updating 'develop' documentation directory"
44+
mkdir -p ./develop
45+
rm -rf ./develop/**./* || exit 0
46+
cp -a ../../docs/. ./develop
4847

49-
# If a Tagged Build then copy to it's own directory as well and to the 'latest' release directory
50-
if [ -n "${TAG_NAME}" ]; then
51-
echo "Creating directory ./${UTPLSQL_VERSION}"
52-
mkdir -p ./${UTPLSQL_VERSION}
53-
rm -rf ./${UTPLSQL_VERSION}/**./* || exit 0
54-
cp -a ../../docs/. ./${UTPLSQL_VERSION}
55-
echo "Populating 'latest' directory"
56-
mkdir -p ./latest
57-
rm -rf ./latest/**./* || exit 0
58-
cp -a ../../docs/. ./latest
59-
fi
60-
# Stage changes for commit
61-
git add .
48+
# If a Tagged Build then copy to it's own directory as well and to the 'latest' release directory
49+
if [ "${GITHUB_REF_TYPE}" == "tag" ]; then
50+
echo "Creating directory ./${UTPLSQL_VERSION}"
51+
mkdir -p ./${UTPLSQL_VERSION}
52+
rm -rf ./${UTPLSQL_VERSION}/**./* || exit 0
53+
cp -a ../../docs/. ./${UTPLSQL_VERSION}
54+
echo "Populating 'latest' directory"
55+
mkdir -p ./latest
56+
rm -rf ./latest/**./* || exit 0
57+
cp -a ../../docs/. ./latest
58+
fi
59+
# Stage changes for commit
60+
git add .
6261

63-
#Check if there are doc changes, if none exit the script
64-
if [[ -z `git diff HEAD --exit-code` ]]; then
65-
echo "No changes to docs detected."
66-
exit 0
67-
fi
68-
#Changes where detected, so we need to update the version log.
69-
now=$(date +"%d %b %Y - %r")
70-
if [ ! -f index.md ]; then
71-
echo "---" >>index.md
72-
echo "layout: default" >>index.md
73-
echo "---" >>index.md
74-
echo "<!-- Auto generated from .travis/push_docs_to_github_io.sh -->" >>index.md
75-
echo "# Documentation versions" >>index.md
76-
echo "" >>index.md
77-
echo "" >>index.md #- 7th line - placeholder for latest release doc
78-
echo "" >>index.md #- 8th line - placeholder for develop branch doc
79-
echo "" >>index.md
80-
echo "## Released Version Doc History" >>index.md
81-
echo "" >>index.md
82-
fi
83-
#If build running on a TAG - it's a new release - need to add it to documentation
84-
if [ -n "${TAG_NAME}" ]; then
85-
sed -i '7s@.*@'" - [Latest ${TAG_NAME} documentation](latest/) - Created $now"'@' index.md
86-
#add entry to the top of version history (line end of file - ## Released Version Doc History
87-
sed -i '12i'" - [${TAG_NAME} documentation](${UTPLSQL_VERSION}/) - Created $now" index.md
88-
fi
89-
#replace 4th line in log
90-
sed -i '8s@.*@'" - [Latest development version](develop/) - Created $now"'@' index.md
91-
#Add and Commit the changes back to pages repo.
92-
git add .
93-
git commit -m "Deploy to gh-pages branch: base commit ${SHA}"
94-
# Now that we're all set up, we can push.
95-
git push --quiet origin HEAD:${GITHUB_IO_BRANCH}
62+
#Check if there are doc changes, if none exit the script
63+
if [[ -z `git diff HEAD --exit-code` ]]; then
64+
echo "No changes to docs detected."
65+
exit 0
66+
fi
67+
#Changes where detected, so we need to update the version log.
68+
now=$(date +"%d %b %Y - %r")
69+
if [ ! -f index.md ]; then
70+
echo "---" >>index.md
71+
echo "layout: default" >>index.md
72+
echo "---" >>index.md
73+
echo "<!-- Auto generated from .travis/push_docs_to_github_io.sh -->" >>index.md
74+
echo "# Documentation versions" >>index.md
75+
echo "" >>index.md
76+
echo "" >>index.md #- 7th line - placeholder for latest release doc
77+
echo "" >>index.md #- 8th line - placeholder for develop branch doc
78+
echo "" >>index.md
79+
echo "## Released Version Doc History" >>index.md
80+
echo "" >>index.md
81+
fi
82+
#If build running on a TAG - it's a new release - need to add it to documentation
83+
if [ "${GITHUB_REF_TYPE}" == "tag" ]; then
84+
sed -i '7s@.*@'" - [Latest ${CURRENT_BRANCH} documentation](latest/) - Created $now"'@' index.md
85+
#add entry to the top of version history (line end of file - ## Released Version Doc History
86+
sed -i '12i'" - [${CURRENT_BRANCH} documentation](${UTPLSQL_VERSION}/) - Created $now" index.md
9687
fi
88+
#replace 4th line in log
89+
sed -i '8s@.*@'" - [Latest development version](develop/) - Created $now"'@' index.md
90+
#Add and Commit the changes back to pages repo.
91+
git add .
92+
git commit -m "Deploy to gh-pages branch: base commit ${SHA}"
93+
# Now that we're all set up, we can push.
94+
git push --quiet origin HEAD:${GITHUB_IO_BRANCH}
9795

0 commit comments

Comments
 (0)