deploy-dotorg.sh 2.8 KB

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