Repository navigation
Expand file tree
/
Copy pathrevert-release.sh
More file actions
executable file
·126 lines (107 loc) · 3.56 KB
/
Copy pathrevert-release.sh
File metadata and controls
executable file
·126 lines (107 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
set -eo pipefail
# CAUTION!
# This script does one thing, which is to revert stable tag in WordPress.org svn to the prior tag.
# It should only be used in extreme emergency cases.
BASE=$(cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd)
. "$BASE/tools/includes/chalk-lite.sh"
. "$BASE/tools/includes/plugin-functions.sh"
. "$BASE/tools/includes/proceed_p.sh"
# Instructions
function usage {
cat <<-EOH
usage: $0 [options] <plugin>
This script does one thing, which is to revert stable tag in WordPress.org
svn to the prior tag. It should only be used in extreme emergency cases.
The <plugin> may be either the name of a directory in projects/plugins/,
or a path to a plugin directorty or file.
Options:
--dir <dir> Use the specified directory for the SVN checkout,
instead of creating a random directory in TMPDIR.
EOH
exit 1
}
# Process args.
ARGS=()
BUILD_DIR=
while [[ $# -gt 0 ]]; do
arg="$1"
shift
case $arg in
--dir)
BUILD_DIR="$1"
shift
;;
--dir=*)
BUILD_DIR="${arg#--dir=}"
;;
--help)
usage
;;
*)
ARGS+=( "$arg" )
;;
esac
done
if [[ ${#ARGS[@]} -ne 1 ]]; then
usage
fi
$INTERACTIVE || die "Input is not a terminal, aborting."
# Check plugin.
process_plugin_arg "${ARGS[0]}"
PLUGIN_NAME=$(jq --arg n "${ARGS[0]}" -r '.name // $n' "$PLUGIN_DIR/composer.json")
WPSLUG=$(jq -r '.extra["wp-plugin-slug"] // ""' "$PLUGIN_DIR/composer.json")
[[ -n "$WPSLUG" ]] || die "Plugin $PLUGIN_NAME has no WordPress.org plugin slug. Cannot deploy."
# Check build dir.
if [[ -z "$BUILD_DIR" ]]; then
TMPDIR="${TMPDIR:-/tmp}"
BUILD_DIR=$(mktemp -d "${TMPDIR%/}/revert-release.XXXXXXXX")
elif [[ ! -e "$BUILD_DIR" ]]; then
mkdir -p "$BUILD_DIR"
else
if [[ ! -d "$BUILD_DIR" ]]; then
proceed_p "$BUILD_DIR already exists, and is not a directory." "Delete it?"
elif [[ $(ls -A -- "$BUILD_DIR") ]]; then
proceed_p "Directory $BUILD_DIR already exists, and is not empty." "Delete it?"
fi
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
fi
cd "$BUILD_DIR"
DIR=$(pwd)
# Get JSON
JSON=$(curl -s "http://api.wordpress.org/plugins/info/1.0/$WPSLUG.json")
if ! jq -e '.' <<<"$JSON" &>/dev/null; then
die "Failed to retrieve JSON data from http://api.wordpress.org/plugins/info/1.0/$WPSLUG.json"
fi
# Current stable version
CURRENT_STABLE_VERSION=$(jq -r .version <<<"$JSON")
# Get all versions, strip anything with alpha characters such as -beta or trunk.
SVN_TMP=$(jq -r '.versions | keys[] | select( test( "^[0-9]+(\\.[0-9]+)+$" ) )' <<<"$JSON" | sort -V )
mapfile -t SVN_TAGS <<<"$SVN_TMP"
LAST_STABLE_TAG=${SVN_TAGS[-2]}
red CAUTION
echo "This script does one thing, which is to revert stable tag in WordPress.org svn to the prior tag."
echo "It should only be used in extreme emergency cases."
echo ""
yellow "Current stable tag: ${CURRENT_STABLE_VERSION}"
yellow "Revert to tag: ${LAST_STABLE_TAG}"
proceed_p "" "Continue?"
echo ""
info "Checking out SVN shallowly to $DIR"
svn -q checkout "https://plugins.svn.wordpress.org/$WPSLUG/" --depth=empty "$DIR"
success "Done!"
info "Checking out SVN trunk to $DIR/trunk"
svn -q up trunk
success "Done!"
# Update trunk to point to the last stable tag.
info "Modifying 'Stable tag:' value in trunk readme.txt"
sed -i.bak -e "s/Stable tag: .*/Stable tag: $LAST_STABLE_TAG/" trunk/readme.txt
rm trunk/readme.txt.bak # We need a backup file because macOS requires it.
echo ""
yellow "The diff you are about to commit:"
svn diff
echo ""
error "WARNING:"
proceed_p "You are about to revert the stable tag for Jetpack via the diff above." "Would you like to commit it now?"
svn ci -m "Revert stable tag"