entrypoint.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. set -e
  3. echo "Starting the Jekyll Action"
  4. if [ -z "${JEKYLL_PAT}" ]; then
  5. echo "No token provided. Please set the JEKYLL_PAT environment variable."
  6. exit 1
  7. fi
  8. if [ -n "${INPUT_JEKYLL_SRC}" ]; then
  9. JEKYLL_SRC=${INPUT_JEKYLL_SRC}
  10. echo "::debug ::Using parameter value ${JEKYLL_SRC} as a source directory"
  11. elif [ -n "${SRC}" ]; then
  12. JEKYLL_SRC=${SRC}
  13. echo "::debug ::Using SRC environment var value ${JEKYLL_SRC} as a source directory"
  14. else
  15. JEKYLL_SRC=$(find . -path ./vendor/bundle -prune -o -name '_config.yml' -exec dirname {} \;)
  16. echo "::debug ::Resolved ${JEKYLL_SRC} as a source directory"
  17. fi
  18. cd $JEKYLL_SRC
  19. echo "::debug ::Starting bundle install"
  20. bundle config path vendor/bundle
  21. bundle install --jobs 4 --retry 3
  22. echo "::debug ::Completed bundle install"
  23. JEKYLL_ENV=production bundle exec jekyll build -d build
  24. echo "Jekyll build done"
  25. cd build
  26. # No need to have GitHub Pages to run Jekyll
  27. touch .nojekyll
  28. # Is this a regular repo or an org.github.io type of repo
  29. case "${GITHUB_REPOSITORY}" in
  30. *.github.io) remote_branch="master" ;;
  31. *) remote_branch="gh-pages" ;;
  32. esac
  33. if [ "${GITHUB_REF}" = "refs/heads/${remote_branch}" ]; then
  34. echo "Cannot publish on branch ${remote_branch}"
  35. exit 1
  36. fi
  37. echo "Publishing to ${GITHUB_REPOSITORY} on branch ${remote_branch}"
  38. echo "::debug ::Pushing to https://${JEKYLL_PAT}@github.com/${GITHUB_REPOSITORY}.git"
  39. remote_repo="https://${JEKYLL_PAT}@github.com/${GITHUB_REPOSITORY}.git" && \
  40. git init && \
  41. git config user.name "${GITHUB_ACTOR}" && \
  42. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" && \
  43. git add . && \
  44. git commit -m "jekyll build from Action ${GITHUB_SHA}" && \
  45. git push --force $remote_repo master:$remote_branch && \
  46. rm -fr .git && \
  47. cd ..
  48. exit $?