From dd070c0798cc5ffb28a2dceedad15aea131754b4 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 9 Jul 2020 13:36:46 -0400 Subject: [PATCH 1/3] Now checks for branch before pushing --- doxy_gen_and_deploy.sh | 65 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/doxy_gen_and_deploy.sh b/doxy_gen_and_deploy.sh index fba8950e..d83d16ae 100644 --- a/doxy_gen_and_deploy.sh +++ b/doxy_gen_and_deploy.sh @@ -141,7 +141,7 @@ if [ ${IS_PULL} == 1 ]; then echo "This is a Pull Request, we're done!" exit 0 else - echo "This is a Commit, Uploading documentation..." + echo "This is a Commit, we may want to upload documentation..." fi cd code_docs/${REPO_NAME} @@ -151,36 +151,41 @@ cd code_docs/${REPO_NAME} # Only upload if Doxygen successfully created the documentation. # Check this by verifying that the html directory and the file html/index.html # both exist. This is a good indication that Doxygen did it's work. -if [ -d "html" ] && [ -f "html/index.html" ]; then - - echo 'Uploading documentation to the gh-pages branch...' - # Add everything in this directory (the Doxygen code documentation) to the - # gh-pages branch. - # GitHub is smart enough to know which files have changed and which files have - # stayed the same and will only update the changed files. - echo 'Adding all files' - git add --all - - if [ -n "$(git status --porcelain)" ]; then - echo "Changes to commit" +if echo $GITHUB_REF | grep -q 'master\|main'; then + if [ -d "html" ] && [ -f "html/index.html" ]; then + + echo 'Uploading documentation to the gh-pages branch...' + # Add everything in this directory (the Doxygen code documentation) to the + # gh-pages branch. + # GitHub is smart enough to know which files have changed and which files have + # stayed the same and will only update the changed files. + echo 'Adding all files' + git add --all + + if [ -n "$(git status --porcelain)" ]; then + echo "Changes to commit" + else + echo "No changes to commit" + exit 0 + fi + + # Commit the added files with a title and description containing the Travis CI + # build number and the GitHub commit reference that issued this build. + echo 'Git committing' + git commit -m "Deploy code docs to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" -m "Commit: ${TRAVIS_COMMIT}" + + # Force push to the remote gh-pages branch. + # The ouput is redirected to /dev/null to hide any sensitive credential data + # that might otherwise be exposed. + echo 'Git pushing' + git push --force "https://${AUTH}@github.com/${REPO_SLUG}.git" > /dev/null 2>&1 else - echo "No changes to commit" - exit 0 + echo '' >&2 + echo 'Warning: No documentation (html) files have been found!' >&2 + echo 'Warning: Not going to push the documentation to GitHub!' >&2 + exit 1 fi - - # Commit the added files with a title and description containing the Travis CI - # build number and the GitHub commit reference that issued this build. - echo 'Git committing' - git commit -m "Deploy code docs to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" -m "Commit: ${TRAVIS_COMMIT}" - - # Force push to the remote gh-pages branch. - # The ouput is redirected to /dev/null to hide any sensitive credential data - # that might otherwise be exposed. - echo 'Git pushing' - git push --force "https://${AUTH}@github.com/${REPO_SLUG}.git" > /dev/null 2>&1 else - echo '' >&2 - echo 'Warning: No documentation (html) files have been found!' >&2 - echo 'Warning: Not going to push the documentation to GitHub!' >&2 - exit 1 + echo "Branch is not master or main, we're done!" + exit 0 fi From 97adf2eb9e9f00d73a03d37e3a47dc50a683467e Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 10 Jul 2020 10:00:06 -0400 Subject: [PATCH 2/3] Switched to checking for default branch instead --- doxy_gen_and_deploy.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doxy_gen_and_deploy.sh b/doxy_gen_and_deploy.sh index d83d16ae..e23a7772 100644 --- a/doxy_gen_and_deploy.sh +++ b/doxy_gen_and_deploy.sh @@ -146,12 +146,19 @@ fi cd code_docs/${REPO_NAME} + + + + ################################################################################ ##### Upload the documentation to the gh-pages branch of the repository. ##### # Only upload if Doxygen successfully created the documentation. # Check this by verifying that the html directory and the file html/index.html # both exist. This is a good indication that Doxygen did it's work. -if echo $GITHUB_REF | grep -q 'master\|main'; then +CURRENT_BRANCH_NAME="${GITHUB_REF##*/}" +readonly DEFAULT_BRANCH_NAME="$(curl "https://api.github.com/repos/${GITHUB_REPOSITORY}" | jq --raw-output .default_branch)" + +if [[ "$CURRENT_BRANCH_NAME" = "$DEFAULT_BRANCH_NAME" ]]; then if [ -d "html" ] && [ -f "html/index.html" ]; then echo 'Uploading documentation to the gh-pages branch...' From 7b8f9c2510a39abc212f35e1e7a140f70b254a07 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 10 Jul 2020 10:10:40 -0400 Subject: [PATCH 3/3] changed which environment variables are used for travis compatability --- doxy_gen_and_deploy.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doxy_gen_and_deploy.sh b/doxy_gen_and_deploy.sh index e23a7772..7b0c1aa2 100644 --- a/doxy_gen_and_deploy.sh +++ b/doxy_gen_and_deploy.sh @@ -51,6 +51,7 @@ else export BUILD_DIR=${TRAVIS_BUILD_DIR} export AUTH=${GH_REPO_TOKEN} export REPO_SLUG=${TRAVIS_REPO_SLUG} + export GITHUB_REF=${TRAVIS_BRANCH} if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then export IS_PULL=1 fi @@ -156,7 +157,7 @@ cd code_docs/${REPO_NAME} # Check this by verifying that the html directory and the file html/index.html # both exist. This is a good indication that Doxygen did it's work. CURRENT_BRANCH_NAME="${GITHUB_REF##*/}" -readonly DEFAULT_BRANCH_NAME="$(curl "https://api.github.com/repos/${GITHUB_REPOSITORY}" | jq --raw-output .default_branch)" +readonly DEFAULT_BRANCH_NAME="$(curl "https://api.github.com/repos/${REPO_SLUG}" | jq --raw-output .default_branch)" if [[ "$CURRENT_BRANCH_NAME" = "$DEFAULT_BRANCH_NAME" ]]; then if [ -d "html" ] && [ -f "html/index.html" ]; then