deploy-dotorg.sh 2.8 KB

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