-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.sh
executable file
·145 lines (122 loc) · 4.89 KB
/
deploy.sh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
set -eo
# Uncomment this when debugging the script.
#set -x
#########################################
# SETUP DEFAULTS #
#########################################
VERSION="${VERSION:-${GITHUB_REF#refs/tags/}}"; VERSION="${VERSION#v}"
SLUG="${SLUG:-${GITHUB_REPOSITORY#*/}}"
SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/"
SVN_DIR="${HOME}/svn-${SLUG}"
# If the version is not set, check if package.json exists and get the version from there otherwise exit.
if [[ -z "$VERSION" || ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [ -f ./package.json ]; then
VERSION=$(node -p "require('./package.json').version")
else
VERSION=""
fi
fi
#########################################
# CHECK IF EVERYTHING IS SET CORRECTLY #
#########################################
for var in USERNAME PASSWORD SLUG VERSION; do
if [ -z "${!var}" ]; then
echo "x︎ $var is not set. Exiting..."
exit 1
fi
done
# Log the slug.
echo "ℹ︎ SLUG is $SLUG"
# Log the version.
echo "ℹ︎ VERSION is $VERSION"
echo "version=$VERSION" >> "${GITHUB_OUTPUT}"
# Log the SVN URL.
echo "ℹ︎ SVN_URL is $SVN_URL"
#########################################
# PREPARE FILES FOR DEPLOYMENT #
#########################################
# Checkout the SVN repo
echo "➤ Checking out SVN repo..."
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR" >> /dev/null || exit 1
cd "$SVN_DIR" || exit
svn update --set-depth infinity assets >> /dev/null
svn update --set-depth infinity trunk >> /dev/null
svn update --set-depth immediates tags >> /dev/null
# Copy files to the SVN repo
echo "➤ Copying files..."
# If .dist ignore file exists, use it to exclude files from the SVN repo, otherwise use the default.
if [[ -r "$GITHUB_WORKSPACE/.distignore" ]]; then
echo "ℹ︎ Using .distignore"
rsync -rc --exclude-from="$GITHUB_WORKSPACE/.distignore" "$GITHUB_WORKSPACE/" trunk/ --delete --delete-excluded
else
rsync -rc --exclude '.git' --exclude '.github' --exclude '.gitignore' --exclude '.distignore' --exclude 'node_modules' "$GITHUB_WORKSPACE/" trunk/ --delete --delete-excluded
fi
# Remove empty directories from trunk
find trunk -type d -empty -delete
echo "✓ Files copied!"
# Copy assets
# If .wordpress-org is a directory and contains files, copy them to the SVN repo.
if [[ -d "$GITHUB_WORKSPACE/.wordpress-org" ]]; then
echo "➤ Copying assets..."
rsync -rc "$GITHUB_WORKSPACE/.wordpress-org/" assets/ --delete
# Fix screenshots getting force downloaded when clicking them
# https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/
if test -d "$SVN_DIR/assets" && test -n "$(find "$SVN_DIR/assets" -maxdepth 1 -name "*.png" -print -quit)"; then
svn propset svn:mime-type "image/png" "$SVN_DIR/assets/"*.png || true
fi
if test -d "$SVN_DIR/assets" && test -n "$(find "$SVN_DIR/assets" -maxdepth 1 -name "*.jpg" -print -quit)"; then
svn propset svn:mime-type "image/jpeg" "$SVN_DIR/assets/"*.jpg || true
fi
if test -d "$SVN_DIR/assets" && test -n "$(find "$SVN_DIR/assets" -maxdepth 1 -name "*.gif" -print -quit)"; then
svn propset svn:mime-type "image/gif" "$SVN_DIR/assets/"*.gif || true
fi
if test -d "$SVN_DIR/assets" && test -n "$(find "$SVN_DIR/assets" -maxdepth 1 -name "*.svg" -print -quit)"; then
svn propset svn:mime-type "image/svg+xml" "$SVN_DIR/assets/"*.svg || true
fi
echo "✓ Assets copied!"
fi
# Copy tag
echo "➤ Copying tag..."
if svn ls "https://plugins.svn.wordpress.org/$SLUG/tags/$VERSION" >>/dev/null 2>&1; then
echo "ℹ︎ Tag already exists. Pulling files ..."
svn update --set-depth infinity "$SVN_DIR/tags/$VERSION"
rsync -rc "$SVN_DIR/trunk/" "$SVN_DIR/tags/$VERSION/" --delete --delete-excluded
echo "✓ Tag files synced !"
else
echo "ℹ︎ Tag does not exist. Creating tag ..."
svn copy "$SVN_DIR/trunk" "$SVN_DIR/tags/$VERSION" >>/dev/null
echo "✓ Tag created!"
fi
echo "✓ Tag copied!"
# Update contents.
echo "➤ Preparing files..."
svn add . --force > /dev/null
# SVN delete all deleted files
# Also suppress stdout here
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %@ > /dev/null
svn update # Fix directory is out of date error
svn status
echo "✓ Files updated!"
# Generate zip file
if $GENERATE_ZIP; then
echo "➤ Generating zip file..."
ln -s "${SVN_DIR}/trunk" "${SVN_DIR}/${SLUG}"
zip -r "${GITHUB_WORKSPACE}/${SLUG}.zip" "$SLUG"
unlink "${SVN_DIR}/${SLUG}"
echo "zip_path=${GITHUB_WORKSPACE}/${SLUG}.zip" >> "${GITHUB_OUTPUT}"
echo "✓ Zip file generated!"
fi
# If dry run, then exit.
if $DRY_RUN; then
echo "ℹ︎ Dry run: Files not committed."
exit 0
fi
# Check if there are changes to commit.
if [[ -n "$(svn status "$SVN_DIR")" ]]; then
echo "➤ Committing changes..."
svn commit -m "Update to version $VERSION" --no-auth-cache --non-interactive --username "$USERNAME" --password "$PASSWORD"
echo "✓ Plugin deployed!"
else
echo "ℹ︎ No changes to commit."
fi