Skip to content

Commit

Permalink
chore: use our version of the workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
MaferMazu committed Dec 4, 2024
1 parent 12c0714 commit 61f9e54
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 13 deletions.
44 changes: 44 additions & 0 deletions .github/actions/svn-publish/action.yml
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.plugin-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 }}



107 changes: 107 additions & 0 deletions .github/actions/svn-publish/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/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

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
22 changes: 22 additions & 0 deletions .github/actions/svn-publish/src/plugin-slug.sh
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"
}
21 changes: 21 additions & 0 deletions .github/actions/svn-publish/src/plugin-version.sh
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"
}
34 changes: 34 additions & 0 deletions .github/actions/svn-publish/src/working-directory.sh
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"
}
20 changes: 7 additions & 13 deletions .github/workflows/publish-svn.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Publish to WordPress SVN

on:
workflow_dispatch:
inputs:
version:
description: 'Example: 2.0.7'
type: string
on: workflow_dispatch

jobs:
build:
Expand All @@ -24,11 +19,10 @@ jobs:
- name: WordPress Plugin Deploy
id: deploy
uses: richard-muvirimi/deploy-wordpress-plugin@development
uses: ./.github/actions/svn-publish
with:
plugin-repository: https://svn.riouxsvn.com/openedx-commerc/
svn-username: ${{ secrets.SVN_USERNAME }}
svn-password: ${{ secrets.SVN_PASSWORD }}
plugin-zip-folder: openedx-commerce
commit-message: Release ${{ inputs.version }}
assets-directory: docs/source/_images/plugin-page
svn-repository: https://svn.riouxsvn.com/openedx-commerc
svn-username: ${{ secrets.WORDPRESS_SVN_USERNAME }}
svn-password: ${{ secrets.WORDPRESS_SVN_PASSWORD }}
assets-directory: ../docs/source/_images/plugin-page
working-directory: openedx-commerce

0 comments on commit 61f9e54

Please sign in to comment.