-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
131 lines (108 loc) · 4.14 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
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
#!/bin/bash
set -eo
WORDPRESS_USERNAME="$INPUT_WORDPRESS_USERNAME"
WORDPRESS_PASSWORD="$INPUT_WORDPRESS_PASSWORD"
SLUG="$INPUT_SLUG"
VERSION="$INPUT_VERSION"
ASSETS_DIR="$INPUT_ASSETS_DIR"
IGNORE_FILE="$INPUT_IGNORE_FILE"
ASSETS_IGNORE_FILE="$INPUT_ASSETS_IGNORE_FILE"
# Ensure SVN username and password are set
# IMPORTANT: secrets are accessible by anyone with write access to the repository!
if [[ -z "$WORDPRESS_USERNAME" ]]; then
echo "🔴 Set the WORDPRESS_USERNAME secret"
exit 1
fi
if [[ -z "$WORDPRESS_PASSWORD" ]]; then
echo "🔴 Set the WORDPRESS_PASSWORD secret"
exit 1
fi
# Allow some ENV variables to be customized
if [[ -z "$SLUG" ]]; then
SLUG=${GITHUB_REPOSITORY#*/}
fi
# Does it even make sense for VERSION to be editable in a workflow definition?
if [[ -z "$VERSION" ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
if [[ -z "$ASSETS_DIR" ]]; then
ASSETS_DIR=".wordpress-org"
fi
if [[ -z "$IGNORE_FILE" ]]; then
IGNORE_FILE=".wporgignore"
fi
if [[ -z "$ASSETS_IGNORE_FILE" ]]; then
ASSETS_IGNORE_FILE=".wporgassetsignore"
fi
if [[ -z "$DIST_LOCATION" ]]; then
DIST_LOCATION="dist/"
fi
echo " "
echo '##[group] ➤ Workflow Arguments'
# Echo Plugin Slug
echo "ℹ︎ WordPress Plugin SLUG is $SLUG"
# Echo Plugin Version
echo "ℹ︎ VERSION is $VERSION"
# Echo Assets DIR
echo "ℹ︎ ASSETS_DIR is $ASSETS_DIR"
echo '##[endgroup]'
SVN_URL="http://plugins.svn.wordpress.org/${SLUG}/"
SVN_DIR="/github/svn-${SLUG}"
# Checkout just trunk and assets for efficiency
# Tagging will be handled on the SVN level
echo "##[group] ➤ 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 "##[endgroup]"
echo "##[group] ➤ Copying files..."
cd "$GITHUB_WORKSPACE"
# "Export" a cleaned copy to a temp directory
TMP_DIR="/github/archivetmp"
ASSET_TMP_DIR="/github/assettmp"
mkdir "$TMP_DIR"
mkdir "$ASSET_TMP_DIR"
echo ".git .github .gitignore .gitattributes ${ASSETS_DIR} ${IGNORE_FILE} ${ASSETS_IGNORE_FILE} node_modules" | tr " " "\n" >>"$GITHUB_WORKSPACE/$IGNORE_FILE"
echo "*.psd .DS_Store Thumbs.db ehthumbs.db ehthumbs_vista.db .git .github .gitignore .gitattributes ${ASSETS_DIR} ${IGNORE_FILE} ${ASSETS_IGNORE_FILE} node_modules" | tr " " "\n" >>"$GITHUB_WORKSPACE/$ASSETS_IGNORE_FILE"
echo "##[endgroup]"
# This will exclude everything in the $IGNORE_FILE file
echo "##[group] ➤ Removing Exlucded Files From Plugin Source"
rsync -r --delete --exclude-from="$GITHUB_WORKSPACE/$IGNORE_FILE" "./" "$TMP_DIR"
echo "##[endgroup]"
# This will exclude everything in the $ASSETS_IGNORE_FILE file
cd "$ASSETS_DIR"
echo "##[group] ➤ Removing Exlucded Files From Assets Folder"
rsync -r --delete --exclude-from="$GITHUB_WORKSPACE/$ASSETS_IGNORE_FILE" "./" "$ASSET_TMP_DIR"
cd "$SVN_DIR"
# Copy from clean copy to /trunk, excluding dotorg assets
# The --delete flag will delete anything in destination that no longer exists in source
rsync -rc "$TMP_DIR/" trunk/ --delete
# Copy dotorg assets to /assets
rsync -rc "$ASSET_TMP_DIR/" assets/ --delete
echo "##[endgroup]"
# 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
echo "##[group] ➤ 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
echo "##[endgroup]"
# Copy tag locally to make this a single commit
echo "##[group] ➤ Copying tag..."
svn cp "trunk" "tags/$VERSION"
echo "##[endgroup]"
echo "##[group] SVN Status"
svn status
echo "##[endgroup]"
echo "##[group] ➤ Committing files..."
svn commit -m "Update to version $VERSION from GitHub" --no-auth-cache --non-interactive --username "$WORDPRESS_USERNAME" --password "$WORDPRESS_PASSWORD"
echo "##[endgroup]
✓ Plugin deployed!"
echo "##[group] Creating Dist File"
mkdir "$GITHUB_WORKSPACE/$DIST_LOCATION"
zip -r9 "$GITHUB_WORKSPACE/$DIST_LOCATION/$SLUG-$VERSION.zip" "tags/$VERSION/"
zip -r9 "$GITHUB_WORKSPACE/$DIST_LOCATION/$SLUG-$VERSION-assets.zip" "assets/"
echo "##[endgroup]"