deploy-dotorg.sh 2.8 KB

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