fsaintjacques commented on a change in pull request #8: ARROW-4473: [Website] 
Support test site deployment
URL: https://github.com/apache/arrow-site/pull/8#discussion_r310727786
 
 

 ##########
 File path: build-and-deploy.sh
 ##########
 @@ -0,0 +1,51 @@
+#!/bin/bash
+set -ev
+
+if [ "${TRAVIS_BRANCH}" = "master" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" 
]; then
+
+    if [ -z "${GITHUB_PAT}" ]; then
+        # Don't build because we can't publish
+        echo "To publish the site, you must set a GITHUB_PAT at"
+        echo "https://travis-ci.org/"${TRAVIS_REPO_SLUG}"/settings";
+        exit 1
+    fi
+
+    # Set git config so that the author of the deployed site commit is the same
+    # as the author of the commit we're building
+    export AUTHOR_EMAIL=$(git log -1 --pretty=format:%ae)
+    export AUTHOR_NAME=$(git log -1 --pretty=format:%an)
+    git config --global user.email "${AUTHOR_EMAIL}"
+    git config --global user.name "${AUTHOR_NAME}"
+
+    if [ "${TRAVIS_REPO_SLUG}" = "apache/arrow-site" ]; then
+        # Production
+        export TARGET_BRANCH=asf-site
+        export BASE_URL=https://arrow.apache.org
+    else
+        # On a fork, so we'll deploy to GitHub Pages
+        export TARGET_BRANCH=gh-pages
+        # You could supply an alternate BASE_URL, but that's not necessary
+        # because we can infer it based on GitHub Pages conventions
+        if [ -z "${BASE_URL}" ]; then
+            export BASE_URL="https://"$(echo $TRAVIS_REPO_SLUG | sed 
's@/@.github.io/@')
+        fi
+    fi
+    # Set the site.baseurl
+    perl -pe 's@^baseurl.*@baseurl: '"${BASE_URL}"'@' -i _config.yml
 
 Review comment:
   Why not sed?
   
   ```
   01:arrow-site/ (master) $ grep -E '^baseurl' _config.yml 
   baseurl:
   01:arrow-site/ (master) $ sed -i -e's#^baseurl:.*#baseurl: HI#' _config.yml 
   01:arrow-site/ (master✗) $ grep -E '^baseurl' _config.yml 
   baseurl: HI
   01:arrow-site/ (master✗) $ sed -i -e's#^baseurl:.*#baseurl: NOPENOPENOPE#' 
_config.yml 
   01:arrow-site/ (master✗) $ grep -E '^baseurl' _config.yml 
   baseurl: NOPENOPENOPE
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to