deploy-dotorg.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # Make sure SVN credentials and project slug are set
  3. if [[ -z "$SVN_USERNAME" ]] && [[ $1 != "preview" ]]; then
  4. echo "Set the SVN_USERNAME secret"
  5. exit 1
  6. fi
  7. if [[ -z "$SVN_PASSWORD" ]] && [[ $1 != "preview" ]]; then
  8. echo "Set the SVN_PASSWORD secret"
  9. exit 1
  10. fi
  11. rm -rf ./deploy
  12. # Look into all the themes we expect to deploy
  13. declare -a THEMES_TO_DEPLOY=(
  14. "archeo"
  15. "blockbase"
  16. "disco"
  17. "geologist"
  18. "lettre"
  19. "livro"
  20. "mayland-blocks"
  21. "pendant"
  22. "pixl"
  23. "quadrat"
  24. "rainfall"
  25. "remote"
  26. "seedlet-blocks"
  27. "skatepark"
  28. "stewart"
  29. "upsidedown"
  30. "videomaker"
  31. "vivre"
  32. "zoologist"
  33. )
  34. for THEME_SLUG in ${THEMES_TO_DEPLOY[@]} ; do
  35. THEME_VERSION=$(cat ./${THEME_SLUG}/style.css \
  36. | grep Version \
  37. | head -1 \
  38. | awk -F: '{ print $2 }' \
  39. | sed 's/[",]//g' \
  40. | sed 's/-wpcom//g' \
  41. | tr -d '[[:space:]]')
  42. # TODO: This does take into account the -wpcom appended to some theme versions.
  43. # Ideally that can be removed from all of the themes versioning in this repository.
  44. # I'm not convinced it's helpful...
  45. printf "\n\nAttempting to deploy theme ${THEME_SLUG} version ${THEME_VERSION}\n"
  46. SVN_URL="https://themes.svn.wordpress.org/${THEME_SLUG}/"
  47. SVN_DIR="$PWD/deploy/${THEME_SLUG}"
  48. svn checkout --depth immediates "$SVN_URL" "$SVN_DIR" --no-auth-cache --non-interactive > /dev/null
  49. if [ ! -d "$SVN_DIR" ]; then
  50. echo "No theme by that slug to be checked out. Probably not a theme. Moving on."
  51. continue;
  52. fi
  53. if [ -d "$SVN_DIR/$THEME_VERSION" ]; then
  54. rm -rf $SVN_DIR
  55. echo "Release already exists. Moving on."
  56. continue;
  57. fi
  58. directories=($SVN_DIR/*)
  59. last_directory=${directories[${#directories[@]}-1]}
  60. echo "➤ Copying previous version of theme '${THEME_SLUG}' to svn repository... "
  61. svn update --set-depth infinity ${last_directory} --non-interactive
  62. svn cp ${last_directory} $SVN_DIR/$THEME_VERSION
  63. echo "➤ Copying theme '${THEME_SLUG}' version '${THEME_VERSION}' to svn repository... "
  64. rsync -rc --delete --include=theme.json --exclude-from './dotorg-exclude.txt' ./$THEME_SLUG/ $SVN_DIR/$THEME_VERSION
  65. # Remove the wpcom-specific tags used in some themes
  66. find $SVN_DIR/$THEME_VERSION/style.css -type f -exec sed -i '' 's/, auto-loading-homepage//g' {} \;
  67. # Remove files from the previous version
  68. svn status $SVN_DIR/$THEME_VERSION | grep "^\!" | sed 's/^\! *//g' | xargs svn rm;
  69. # Add the version to SVN
  70. svn add $SVN_DIR/$THEME_VERSION --force --depth infinity -q > /dev/null
  71. if [[ $1 == "preview" ]]; then
  72. svn status $SVN_DIR
  73. else
  74. echo "➤ Committing files..."
  75. svn commit $SVN_DIR -m "Update to version ${THEME_VERSION} from GitHub" --no-auth-cache --non-interactive --username ${SVN_USERNAME} --password ${SVN_PASSWORD} 2>&1 | grep 'svn: E'
  76. if [[ $? -eq 0 ]]; then
  77. echo 'Commit failed.'
  78. exit 1
  79. fi
  80. fi
  81. done