build-release.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env bash
  2. set -ex
  3. #############
  4. # FUNCTIONS #
  5. #############
  6. MAKE='make --debug=v --output-sync'
  7. function build() {
  8. $MAKE build.all
  9. # quick check that go modules are tidied
  10. $MAKE mod.check
  11. }
  12. function publish() {
  13. build
  14. $MAKE -C build/release build BRANCH_NAME=${BRANCH_NAME} TAG_WITH_SUFFIX=${TAG_WITH_SUFFIX} GIT_API_TOKEN=${GIT_API_TOKEN}
  15. git status &
  16. git diff &
  17. $MAKE -C build/release publish BRANCH_NAME=${BRANCH_NAME} TAG_WITH_SUFFIX=${TAG_WITH_SUFFIX} AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW} GIT_API_TOKEN=${GIT_API_TOKEN}
  18. }
  19. function promote() {
  20. # automatically promote the master builds
  21. echo "Promoting from branch ${BRANCH_NAME}"
  22. $MAKE -C build/release promote BRANCH_NAME=${BRANCH_NAME} TAG_WITH_SUFFIX=${TAG_WITH_SUFFIX} CHANNEL=${CHANNEL} AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW}
  23. }
  24. #############
  25. # MAIN #
  26. #############
  27. # Load dot env file if available
  28. if [ -f .env ]; then
  29. # shellcheck disable=SC2046
  30. export $(grep -v '^#' .env | xargs -d '\n')
  31. fi
  32. # Use Git access token for accessing the docs repo if set
  33. # shellcheck disable=SC2034
  34. export DOCS_GIT_REPO="${DOCS_GIT_REPO:-git@github.com:rook/rook.github.io.git}"
  35. if [ -n "${GIT_API_TOKEN}" ]; then
  36. DOCS_GIT_REPO="${DOCS_GIT_REPO//git@/}"
  37. DOCS_GIT_REPO="${DOCS_GIT_REPO//:/\/}"
  38. export DOCS_GIT_REPO="https://${GIT_API_TOKEN}@${DOCS_GIT_REPO}"
  39. fi
  40. SHOULD_PROMOTE=true
  41. if [[ ${GITHUB_REF} =~ master ]]; then
  42. echo "Publishing from master"
  43. CHANNEL=master
  44. else
  45. echo "Tagging with suffix for release and tagged builds"
  46. TAG_WITH_SUFFIX=true
  47. CHANNEL=release
  48. # If a tag, find the source release branch
  49. if [[ $BRANCH_NAME = v* ]]; then
  50. TAG_NAME=${BRANCH_NAME}
  51. BRANCH_NAME=$(git branch -r --contain refs/tags/${BRANCH_NAME} | grep "origin/release-." | sed 's/origin\///' | xargs)
  52. if [[ $BRANCH_NAME = "" ]]; then
  53. echo "Branch name not found in tag $TAG_NAME"
  54. exit 1
  55. fi
  56. echo "Publishing tag ${TAG_NAME} in branch ${BRANCH_NAME}"
  57. else
  58. echo "Publishing from release branch ${BRANCH_NAME}"
  59. SHOULD_PROMOTE=false
  60. fi
  61. fi
  62. publish
  63. if [[ "$SHOULD_PROMOTE" = true ]]; then
  64. promote
  65. fi