deploy-dotorg.sh 2.8 KB

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