2021-11-10 17:50:35 +00:00
#!/bin/bash
# Make sure SVN credentials and project slug are set
2022-01-18 16:32:26 +00:00
if [ [ -z " $SVN_USERNAME " ] ] && [ [ $1 != "preview" ] ] ; then
2021-11-10 17:50:35 +00:00
echo "Set the SVN_USERNAME secret"
exit 1
fi
2022-01-18 16:32:26 +00:00
if [ [ -z " $SVN_PASSWORD " ] ] && [ [ $1 != "preview" ] ] ; then
2021-11-10 17:50:35 +00:00
echo "Set the SVN_PASSWORD secret"
exit 1
fi
2024-06-24 13:30:13 +00:00
# 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
2021-11-10 17:50:35 +00:00
rm -rf ./deploy
2024-06-24 13:30:13 +00:00
# Do things for all of the themes
for THEME_SLUG in */ ; do
# 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."
2021-11-10 17:50:35 +00:00
continue ;
fi
2024-06-24 13:30:13 +00:00
# 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."
2021-11-10 17:50:35 +00:00
continue ;
fi
2024-06-24 13:30:13 +00:00
if test -f " ./ ${ THEME_SLUG } /style.css " ; then
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:]]' )
SVN_URL = " https://themes.svn.wordpress.org/ ${ THEME_SLUG } / "
SVN_DIR = " $PWD /deploy/ ${ THEME_SLUG } "
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
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
# 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
2022-01-18 16:32:26 +00:00
2024-06-24 13:30:13 +00:00
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
2022-01-18 16:32:26 +00:00
2024-06-24 13:30:13 +00:00
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
2021-11-10 17:50:35 +00:00
2024-06-24 13:30:13 +00:00
# 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' { } \;
2021-11-10 17:50:35 +00:00
2024-06-24 13:30:13 +00:00
# Remove files from the previous version
svn status $SVN_DIR /$THEME_VERSION | grep "^\!" | sed 's/^\! *//g' | xargs svn rm;
2022-01-18 16:32:26 +00:00
2024-06-24 13:30:13 +00:00
# Add the version to SVN
svn add $SVN_DIR /$THEME_VERSION --force --depth infinity -q > /dev/null
2021-11-10 17:50:35 +00:00
2022-01-18 16:32:26 +00:00
echo "➤ Committing files..."
2022-10-25 13:54:00 +00:00
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
echo 'Commit failed.'
exit 1
fi
2022-01-18 16:32:26 +00:00
fi
2022-08-22 20:45:49 +00:00
done