forked from openedx/openedx-wordpress-ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use our version of the workflow
- Loading branch information
Showing
6 changed files
with
240 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: 'Publish to WordPress SVN repository' | ||
description: "Publish to WordPress SVN repository" | ||
inputs: | ||
svn-username: | ||
description: "SVN username for authentication" | ||
required: true | ||
svn-password: | ||
description: "SVN password for authentication" | ||
required: true | ||
svn-repository: | ||
description: "Plugin SVN repository URL" | ||
required: true | ||
plugin-version: | ||
description: "Plugin version to deploy" | ||
required: true | ||
working-directory: | ||
description: "Directory to copy files from" | ||
required: true | ||
assets-directory: | ||
description: "Directory containing assets" | ||
required: false | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- id: setup | ||
run: | | ||
sudo apt update | ||
sudo apt install -y subversion rsync zip | ||
shell: bash | ||
- id: deploy | ||
run: sh ${{ github.action_path }}/deploy.sh | ||
shell: bash | ||
env: | ||
INPUT_SVN_USERNAME: ${{ inputs.svn-username }} | ||
INPUT_SVN_PASSWORD: ${{ inputs.svn-password }} | ||
INPUT_PLUGIN_REPOSITORY: ${{ inputs.svn-repository }} | ||
INPUT_PLUGIN_VERSION: ${{ inputs.plugin-version }} | ||
INPUT_COMMIT_MESSAGE: ${{ inputs.commit-message }} | ||
INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }} | ||
INPUT_ASSETS_DIRECTORY: ${{ inputs.assets-directory }} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Environment | ||
if [[ -z "$INPUT_SVN_USERNAME" ]]; then | ||
echo "Set the svn-username secret" | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "$INPUT_SVN_PASSWORD" ]]; then | ||
echo "Set the svn-password secret" | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "$INPUT_PLUGIN_REPOSITORY" ]]; then | ||
echo "Set the svn-repository" | ||
exit 1 | ||
fi | ||
|
||
DIRECTORY_SRC="$GITHUB_ACTION_PATH/src" | ||
|
||
. "$DIRECTORY_SRC/working-directory.sh" | ||
. "$DIRECTORY_SRC/plugin-version.sh" | ||
. "$DIRECTORY_SRC/plugin-slug.sh" | ||
|
||
# Infer raw plugin slug | ||
PLUGIN_SLUG=$(pluginSlug "$INPUT_PLUGIN_REPOSITORY") | ||
|
||
export PLUGIN_SLUG | ||
|
||
# Normalize environment | ||
INPUT_PLUGIN_VERSION=$(pluginVersion "$INPUT_PLUGIN_VERSION") | ||
INPUT_WORKING_DIRECTORY=$(workingDirectory "$INPUT_WORKING_DIRECTORY") | ||
INPUT_ASSETS_DIRECTORY=$(assetsDirectory "$INPUT_ASSETS_DIRECTORY") | ||
|
||
# svn working directory | ||
SVN_DIRECTORY=$(mktemp -d -p "$GITHUB_WORKSPACE") | ||
|
||
# Check out svn repository | ||
echo "➤ Checking out $INPUT_PLUGIN_REPOSITORY" | ||
svn checkout --depth immediates "$INPUT_PLUGIN_REPOSITORY" "$SVN_DIRECTORY" | ||
|
||
# switch to svn working directory | ||
echo "➤ Switching to svn working directory" | ||
cd "$SVN_DIRECTORY" || exit | ||
|
||
# Prevent clear assets directory | ||
svn update --set-depth infinity assets | ||
|
||
# copy files from working directory | ||
svn update --set-depth infinity trunk | ||
|
||
echo "ℹ︎ Copying files from $INPUT_WORKING_DIRECTORY to trunk/" | ||
rsync -rc "$INPUT_WORKING_DIRECTORY/" trunk/ --exclude "$INPUT_ASSETS_DIRECTORY" --delete --delete-excluded | ||
|
||
# copy files from trunk to tag directory | ||
svn update --set-depth infinity tags | ||
|
||
echo "ℹ︎ Copying files from trunk/ to tags/$INPUT_PLUGIN_VERSION" | ||
|
||
mkdir -p "tags/$INPUT_PLUGIN_VERSION/" | ||
rsync -rc trunk/ "tags/$INPUT_PLUGIN_VERSION/" --delete --delete-excluded | ||
|
||
# Handle assets | ||
if [ -z "$INPUT_ASSETS_DIRECTORY" ]; then | ||
# copy files from assets directory | ||
echo "ℹ︎ Copying assets from $INPUT_ASSETS_DIRECTORY to assets/" | ||
rsync -rc "$INPUT_ASSETS_DIRECTORY/" assets/ --exclude "$INPUT_WORKING_DIRECTORY" --delete --delete-excluded | ||
|
||
echo "➤ Preparing asset files..." | ||
svn add --force "$SVN_DIRECTORY/assets/" > /dev/null | ||
|
||
# Fix asset mime type | ||
# https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#issues | ||
if [[ -n $(find "assets" -maxdepth 1 -name "*.png" -print -quit) ]]; then | ||
svn propset svn:mime-type "image/png" "assets/*.png" || true | ||
fi | ||
if [[ -n $(find "assets" -maxdepth 1 -name "*.jpg" -print -quit) ]]; then | ||
svn propset svn:mime-type "image/jpeg" "assets/*.jpg" || true | ||
fi | ||
if [[ -n $(find "assets" -maxdepth 1 -name "*.gif" -print -quit) ]]; then | ||
svn propset svn:mime-type "image/gif" "assets/*.gif" || true | ||
fi | ||
if [[ -n $(find "assets" -maxdepth 1 -name "*.svg" -print -quit) ]]; then | ||
svn propset svn:mime-type "image/svg+xml" "assets/*.svg" || true | ||
fi | ||
fi | ||
|
||
echo "➤ Preparing files..." | ||
svn add --force "$SVN_DIRECTORY/trunk/" > /dev/null | ||
svn add --force "$SVN_DIRECTORY/tags/" > /dev/null | ||
|
||
# remove missing files | ||
# https://stackoverflow.com/a/43805181 | ||
svn status | grep ^\! | cut -c9- | sed 's/ /\\ /g'| xargs -L1 svn del --force | ||
|
||
# Fix directory out of date | ||
# https://stackoverflow.com/a/3298401/5956589 | ||
svn update "$SVN_DIRECTORY/" | ||
|
||
svn status | ||
|
||
echo "➤ Committing files..." | ||
svn commit -m "Release $INPUT_PLUGIN_VERSION" --no-auth-cache --non-interactive --username "$INPUT_SVN_USERNAME" --password "$INPUT_SVN_PASSWORD" | ||
|
||
echo "✓ Plugin deployed!" | ||
|
||
echo "➤ Cleaning up working directory" | ||
rm -rf "$SVN_DIRECTORY" | ||
|
||
# Normalize | ||
echo "➤ Switching to working directory" | ||
cd "$GITHUB_WORKSPACE" || exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
pluginSlug(){ | ||
|
||
INPUT_PLUGIN_REPOSITORY="$1" | ||
|
||
case "$INPUT_PLUGIN_REPOSITORY" in | ||
http* | "") | ||
if [ -z "$INPUT_PLUGIN_REPOSITORY" ]; then | ||
#Use git repository name | ||
INPUT_PLUGIN_REPOSITORY="$GITHUB_REPOSITORY" | ||
fi | ||
|
||
INPUT_PLUGIN_REPOSITORY=$(basename "$INPUT_PLUGIN_REPOSITORY") | ||
;; | ||
*) | ||
#Use as is | ||
;; | ||
esac | ||
|
||
echo "$INPUT_PLUGIN_REPOSITORY" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
pluginVersion(){ | ||
|
||
INPUT_PLUGIN_VERSION="$1" | ||
|
||
case "$INPUT_PLUGIN_VERSION" in | ||
'tag') | ||
INPUT_PLUGIN_VERSION=${GITHUB_REF#refs/tags/} | ||
;; | ||
'readme' | '') | ||
INPUT_PLUGIN_VERSION=$(find "$INPUT_WORKING_DIRECTORY" -iname "README.TXT" -exec grep -oiP -m 1 'stable\s+tag\s*:\s\K.*' {} \;) | ||
;; | ||
|
||
*) | ||
#default to provided message | ||
;; | ||
esac | ||
|
||
echo "$INPUT_PLUGIN_VERSION" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
#resolve working directory | ||
workingDirectory(){ | ||
|
||
INPUT_WORKING_DIRECTORY="$1" | ||
|
||
case "$INPUT_WORKING_DIRECTORY" in | ||
/*) | ||
#trim path | ||
WORKING_DIRECTORY="$(readlink -fq "$INPUT_WORKING_DIRECTORY")" | ||
|
||
#use provided path | ||
INPUT_WORKING_DIRECTORY="$WORKING_DIRECTORY/" | ||
;; | ||
"") | ||
INPUT_WORKING_DIRECTORY="$GITHUB_WORKSPACE/" | ||
;; | ||
*) | ||
#Prepend workspace path | ||
INPUT_WORKING_DIRECTORY="$(readlink -fq "$GITHUB_WORKSPACE/$INPUT_WORKING_DIRECTORY")/" | ||
;; | ||
esac | ||
|
||
echo "$INPUT_WORKING_DIRECTORY" | ||
} | ||
|
||
#resolve assets directory | ||
assetsDirectory(){ | ||
|
||
INPUT_ASSETS_DIRECTORY="$1" | ||
|
||
workingDirectory "$INPUT_ASSETS_DIRECTORY" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters