Skip to content

Commit

Permalink
tools: Avoid double-tagging in wporg SVN (#28437)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
anomiex authored Jan 18, 2023
1 parent 70e1161 commit e451328
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion tools/deploy-to-svn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e451328

Please sign in to comment.