forked from 10up/action-wordpress-plugin-asset-update
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·106 lines (83 loc) · 3.08 KB
/
entrypoint.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
#!/bin/bash
# Note that this does not use pipefail because if the grep later
# doesn't match I want to be able to show an error first
set -eo
# Ensure SVN username and password are set
# IMPORTANT: while secrets are encrypted and not viewable in the GitHub UI,
# they are by necessity provided as plaintext in the context of the Action,
# so do not echo or use debug mode unless you want your secrets exposed!
if [[ -z "$SVN_USERNAME" ]]; then
echo "Set the SVN_USERNAME secret"
exit 1
fi
if [[ -z "$SVN_PASSWORD" ]]; then
echo "Set the SVN_PASSWORD secret"
exit 1
fi
# Allow some ENV variables to be customized
if [[ -z "$SLUG" ]]; then
SLUG=${GITHUB_REPOSITORY#*/}
fi
echo "ℹ︎ SLUG is $SLUG"
if [[ -z "$ASSETS_DIR" ]]; then
ASSETS_DIR=".wordpress-org"
fi
echo "ℹ︎ ASSETS_DIR is $ASSETS_DIR"
if [[ -z "$README_NAME" ]]; then
README_NAME="readme.txt"
fi
echo "ℹ︎ README_NAME is $README_NAME"
SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/"
SVN_DIR="/github/svn-${SLUG}"
# Checkout just trunk and assets for efficiency
# Stable tag will come later, if applicable
echo "➤ Checking out .org repository..."
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR"
cd "$SVN_DIR"
svn update --set-depth infinity assets
svn update --set-depth infinity trunk
echo "➤ Copying files..."
# Copy readme to /trunk
cp "$GITHUB_WORKSPACE/$README_NAME" trunk/$README_NAME
# Copy dotorg assets to /assets
rsync -rc "$GITHUB_WORKSPACE/$ASSETS_DIR/" assets/ --delete --delete-excluded
echo "➤ Preparing files..."
svn status
if [[ -z $(svn stat) ]]; then
echo "🛑 Nothing to deploy!"
exit 0
# Check if there is more than just the readme.txt modified in trunk
# The leading whitespace in the pattern is important
# so it doesn't match potential readme.txt in subdirectories!
elif svn stat trunk | grep -qvi " trunk/$README_NAME$"; then
echo "🛑 Other files have been modified; changes not deployed"
exit 1
fi
# Readme also has to be updated in the .org tag
echo "➤ Preparing stable tag..."
STABLE_TAG=$(grep -m 1 "^Stable tag:" "trunk/$README_NAME" | tr -d '\r\n' | awk -F ' ' '{print $NF}')
if [[ -z "$STABLE_TAG" ]]; then
echo "ℹ︎ Could not get stable tag from $README_NAME";
HAS_STABLE=1
else
echo "ℹ︎ STABLE_TAG is $STABLE_TAG"
if svn info "^/$SLUG/tags/$STABLE_TAG" > /dev/null 2>&1; then
svn update --set-depth infinity "tags/$STABLE_TAG"
# Not doing the copying in SVN for the sake of easy history
rsync -c "trunk/$README_NAME" "tags/$STABLE_TAG/"
else
echo "ℹ︎ Tag $STABLE_TAG not found"
fi
fi
# Add everything and commit to SVN
# The force flag ensures we recurse into subdirectories even if they are already added
# Suppress stdout in favor of svn status later for readability
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
# Now show full SVN status
svn status
echo "➤ Committing files..."
svn commit -m "Updating readme/assets from GitHub" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
echo "✓ Plugin deployed!"