deploy-dotorg.sh 2.8 KB

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