From e451328f76ba71755a94a0aaba78ad5a217a55fc Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 18 Jan 2023 12:06:29 -0500 Subject: [PATCH] tools: Avoid double-tagging in wporg SVN (#28437) The command used to tag a release in SVN has an unfortunate failure modde if the tag already exists: instead of simply failing, it will create a `trunk` directory inside the tag. This PR does two things to try to avoid this situation: * The manual `deploy-to-svn.sh` script will now confirm if someone tries to run it on a plugin that is set up for auto-publish. * Both that and the auto-publish will abort if they detect the tag already exists (but note this check is subject to races). --- .../files/wp-svn-autopublish.sh | 7 ++++++- tools/deploy-to-svn.sh | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/files/gh-wp-svn-autopublish/files/wp-svn-autopublish.sh b/.github/files/gh-wp-svn-autopublish/files/wp-svn-autopublish.sh index 8064d3e26c6be..befbaa5a5c306 100755 --- a/.github/files/gh-wp-svn-autopublish/files/wp-svn-autopublish.sh +++ b/.github/files/gh-wp-svn-autopublish/files/wp-svn-autopublish.sh @@ -37,9 +37,14 @@ svn up trunk echo '::endgroup::' echo "::group::Checking out SVN tags (shallowly)" -svn up tags --depth=empty +svn up tags --depth=immediates echo '::endgroup::' +if [[ -e "tags/$TAG" ]]; then + echo "::error::Tag $TAG already exists in SVN. Aborting." + exit 1 +fi + echo "::group::Deleting everything in trunk except for .svn directories" find trunk ! \( -path '*/.svn/*' -o -path "*/.svn" \) \( ! -type d -o -empty \) -delete [[ -e trunk ]] || mkdir -p trunk # If there were no .svn directories, trunk itself might have been removed. diff --git a/tools/deploy-to-svn.sh b/tools/deploy-to-svn.sh index 6e20d085fc8b0..26be309886c69 100755 --- a/tools/deploy-to-svn.sh +++ b/tools/deploy-to-svn.sh @@ -84,6 +84,12 @@ if [[ -z "$WPSLUG" ]]; then fi $FAIL && exit 1 +if jq -e '.extra["wp-svn-autopublish"] // false' "$PLUGIN_DIR/composer.json" &>/dev/null; then + yellow "$PLUGIN_NAME is set up to automatically publish to WordPress.org via GitHub Actions." + yellow $'\e[1mIf you run this script in addition to the auto-publish, you\'ll likely wind up with a broken tag (see https://github.com/Automattic/jetpack/issues/28400).' + proceed_p '' 'Really publish to SVN manually?' +fi + # Check build dir. if [[ -z "$BUILD_DIR" ]]; then TMPDIR="${TMPDIR:-/tmp}" @@ -124,9 +130,13 @@ printf "\r\e[K" success "Done!" info "Checking out SVN tags shallowly to $DIR/tags" -svn -q up tags --depth=empty +svn -q up tags --depth=immediates success "Done!" +if [[ -e "tags/$SVNTAG" ]]; then + die "Tag $SVNTAG already exists in SVN. Aborting." +fi + info "Deleting everything in trunk except for .svn directories" find trunk ! \( -path '*/.svn/*' -o -path "*/.svn" \) \( ! -type d -o -empty \) -delete [[ -e trunk ]] || mkdir -p trunk # If there were no .svn directories, trunk itself might have been removed.