Refactor dotorg deploy script to use an ignore file (#7806)

* Refactor dotorg deploy script to use an EXCLUSION list instead of INCLUSION list, ignore ALL classic themes, check existence of themes and version using HTTP instead of SVN

* Update deploy-dotorg.sh

* use .dotorg-ignore file for rsync and deployment

---------

Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com>
This commit is contained in:
Jason Crist 2024-06-24 09:30:13 -04:00 committed by GitHub
parent dd3e6d64be
commit f888f7b96f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 202 additions and 76 deletions

111
.dotorg-ignore Normal file
View file

@ -0,0 +1,111 @@
# Themes to be ignored when deploying to the WordPress.org theme repository
appleton
arbutus
artly
assembler
attar
awburn
azur
barnett
barnsbury23
beep
bennett
blank-canvas-3
block-canvas
blogorama
boxedbio
calvin
calyx
chanson
cortado
covr
craftfully
creatio-2
creatio
curriculum
dorna
dos
entry
epi
erma
eventual
exmoor
farrow
foam
grammerone
hall
hari
heiwa
ici
indice
infield
iotix
issue
jackson
kansei
kaze
kingsley
kiosko
lativ
loic
lois
luce
lynx
marl
masu
meraki
messagerie
montagna
mpho
muscat
mysa
nested
nook
organizer
otis
overlaid
perenne
pieria
poesis
pomme
programme
raw
reverie
ritratto
russell
screenplay
shhh
snd
spearhead-blocks
spiel
stage
startfit
sten
strand
sunderland
tenaz
texty
the-jazzers
the-menu
tu
twentytwentytwo-blue
twentytwentytwo-mint
twentytwentytwo-pink
twentytwentytwo-red
twentytwentytwo-swiss
verso
vetro
winkel
xanadu
# General paths to be ignored when deploying to the WordPress.org theme repository
inc/headstart
node_modules
package.json
.git
*.DS_Store
*.sh
*.map
*wpcom*
*.zip
postcss.config.js

View file

@ -11,96 +11,108 @@ if [[ -z "$SVN_PASSWORD" ]] && [[ $1 != "preview" ]]; then
exit 1
fi
# These themes either:
# are not (and not expected to be) deployed to wporg
# have been deployed to wporg, however they are not expected to be updated
# Note that all classic themes (those without a theme.json file) are ALSO ignored
# Get the directory of the script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IGNORE_FILE="$SCRIPT_DIR/.dotorg-ignore"
# Initialize an empty array for themes to ignore
THEMES_TO_IGNORE=()
# Read themes to ignore from .dotorg-ignore file, ignoring comments
if [[ -f "$IGNORE_FILE" ]]; then
while IFS= read -r line || [[ -n "$line" ]]; do
[[ "$line" =~ ^#.*$ ]] && continue
THEMES_TO_IGNORE+=("$line")
done < "$IGNORE_FILE"
else
echo ".dotorg-ignore file not found, proceeding without ignoring any themes."
fi
rm -rf ./deploy
# Look into all the themes we expect to deploy
# Do things for all of the themes
for THEME_SLUG in */ ; do
declare -a THEMES_TO_DEPLOY=(
"adventurer"
"archeo"
"bibimbap"
"bitacora"
"blockbase"
"course"
"ctlg"
"disco"
"geologist"
"george-lois"
"hey"
"lettre"
"lineup"
"livro"
"mayland-blocks"
"paimio"
"pendant"
"pixl"
"poema"
"quadrat"
"rainfall"
"remote"
"seedlet-blocks"
"skatepark"
"stewart"
"storia"
"upsidedown"
"vivre"
"zoologist"
)
for THEME_SLUG in ${THEMES_TO_DEPLOY[@]} ; do
THEME_VERSION=$(cat ./${THEME_SLUG}/style.css \
| grep Version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| sed 's/-wpcom//g' \
| tr -d '[[:space:]]')
# TODO: This does take into account the -wpcom appended to some theme versions.
# Ideally that can be removed from all of the themes versioning in this repository.
# I'm not convinced it's helpful...
printf "\n\nAttempting to deploy theme ${THEME_SLUG} version ${THEME_VERSION}\n"
SVN_URL="https://themes.svn.wordpress.org/${THEME_SLUG}/"
SVN_DIR="$PWD/deploy/${THEME_SLUG}"
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR" --no-auth-cache --non-interactive > /dev/null
if [ ! -d "$SVN_DIR" ]; then
echo "No theme by that slug to be checked out. Probably not a theme. Moving on."
# Skip any classic themes (assuming that none of our classic themes use a theme.json file)
if ! test -f "./${THEME_SLUG}/theme.json"; then
# echo "Ignoring classic theme ${THEME_SLUG}. Moving on."
continue;
fi
if [ -d "$SVN_DIR/$THEME_VERSION" ]; then
rm -rf $SVN_DIR
echo "Release already exists. Moving on."
# Skip any themes that are in the ignore list
if [[ " ${THEMES_TO_IGNORE[*]} " == *" ${THEME_SLUG//\//} "* ]]; then
# echo "Ignoring theme ${THEME_SLUG} from list. Moving on."
continue;
fi
directories=($SVN_DIR/*)
last_directory=${directories[${#directories[@]}-1]}
if test -f "./${THEME_SLUG}/style.css"; then
echo "➤ Copying previous version of theme '${THEME_SLUG}' to svn repository... "
svn update --set-depth infinity ${last_directory} --non-interactive
svn cp ${last_directory} $SVN_DIR/$THEME_VERSION
THEME_VERSION=$(cat ./${THEME_SLUG}/style.css \
| grep Version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| sed 's/-wpcom//g' \
| tr -d '[[:space:]]')
echo "➤ Copying theme '${THEME_SLUG}' version '${THEME_VERSION}' to svn repository... "
rsync -rc --delete --include=theme.json --exclude-from './dotorg-exclude.txt' ./$THEME_SLUG/ $SVN_DIR/$THEME_VERSION
SVN_URL="https://themes.svn.wordpress.org/${THEME_SLUG}/"
SVN_DIR="$PWD/deploy/${THEME_SLUG}"
# Remove the wpcom-specific tags used in some themes
find $SVN_DIR/$THEME_VERSION/style.css -type f -exec sed -i '' 's/, auto-loading-homepage//g' {} \;
response=$(curl -s -o /dev/null -w "%{http_code}" "$SVN_URL")
if [ "$response" != "200" ]; then
# echo "No theme with slug ${THEME_SLUG} to be updated. Moving on."
continue;
fi
# Remove files from the previous version
svn status $SVN_DIR/$THEME_VERSION | grep "^\!" | sed 's/^\! *//g' | xargs svn rm;
response=$(curl -s -o /dev/null -w "%{http_code}" "$SVN_URL/$THEME_VERSION/")
if [ "$response" == "200" ]; then
# echo "${THEME_SLUG} version '$THEME_VERSION' already deployed. Moving on."
continue;
fi
# Add the version to SVN
svn add $SVN_DIR/$THEME_VERSION --force --depth infinity -q > /dev/null
# printf "\n\nAttempting to deploy theme ${THEME_SLUG} version ${THEME_VERSION}\n"
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR" --no-auth-cache --non-interactive > /dev/null
if [ ! -d "$SVN_DIR" ]; then
continue;
fi
if [ -d "$SVN_DIR/$THEME_VERSION" ]; then
rm -rf $SVN_DIR
echo "${THEME_SLUG} version '$THEME_VERSION' already deployed. Moving on."
continue;
fi
directories=($SVN_DIR/*)
last_directory=${directories[${#directories[@]}-1]}
last_version="${last_directory##*/}"
echo "➤ Upgrading ${THEME_SLUG} from ${last_version} to $THEME_VERSION"
if [[ $1 == "preview" ]]; then
continue;
fi
echo "➤ Copying previous version of theme ('${last_directory}') '${THEME_SLUG}' to svn repository... "
svn update --set-depth infinity ${last_directory} --non-interactive
svn cp ${last_directory} $SVN_DIR/$THEME_VERSION
echo "➤ Copying theme '${THEME_SLUG}' version '${THEME_VERSION}' to svn repository... "
rsync -rc --delete --include=theme.json --exclude-from $IGNORE_FILE ./$THEME_SLUG/ $SVN_DIR/$THEME_VERSION
# Remove the wpcom-specific tags used in some themes
find $SVN_DIR/$THEME_VERSION/style.css -type f -exec sed -i '' 's/, auto-loading-homepage//g' {} \;
# Remove files from the previous version
svn status $SVN_DIR/$THEME_VERSION | grep "^\!" | sed 's/^\! *//g' | xargs svn rm;
# Add the version to SVN
svn add $SVN_DIR/$THEME_VERSION --force --depth infinity -q > /dev/null
if [[ $1 == "preview" ]]; then
svn status $SVN_DIR
else
echo "➤ Committing files..."
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'
if [[ $? -eq 0 ]]; then

View file

@ -1,5 +1,8 @@
#!/bin/zsh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IGNORE_FILE="$SCRIPT_DIR/.dotorg-ignore"
git remote update > /dev/null
current_branch=$(git branch --show-current)
hash_at_divergence=$(git merge-base origin/trunk ${current_branch})
@ -92,7 +95,7 @@ build-org-zip() {
# Copy the theme into a subfolder (excluding the excludables) to be packaged up in a zip
mkdir $THEME;
rsync -avzq --include='theme.json' --exclude $THEME --exclude-from '../dotorg-exclude.txt' ./ $THEME
rsync -avzq --include='theme.json' --exclude $THEME --exclude-from $IGNORE_FILE ./ $THEME
# Make sure the -wpcom version naming and tags aren't shipped
#NOTE: (can we be rid of that -wpcom 'versioning')