Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add publish to wordpress svn action #103

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/actions/svn-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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: bash ${{ 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 }}
106 changes: 106 additions & 0 deletions .github/actions/svn-publish/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/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"

# 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 | awk '/^!/ {print $2}' | xargs -I {} 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
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"
}
28 changes: 28 additions & 0 deletions .github/workflows/publish-svn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish to WordPress SVN

on: workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
composer-options: "--no-dev"

- name: Prepare the openedx-commerce directory for the release
run: |
make release

- name: WordPress Plugin Deploy
id: deploy
uses: ./.github/actions/svn-publish
with:
svn-repository: https://plugins.svn.wordpress.org/openedx-commerce/
svn-username: ${{ secrets.WORDPRESS_SVN_USERNAME }}
svn-password: ${{ secrets.WORDPRESS_SVN_PASSWORD }}
assets-directory: ../docs/source/_images/plugin-page
working-directory: openedx-commerce
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: felipemontoya, julianrg2, mafermazu
Tags: openedx, open edx, ecommerce, lms, courses
Requires at least: 6.3
Tested up to: 6.6
Tested up to: 6.7
Requires PHP: 8.0
Stable tag: 2.0.7
License: GPLv2 or later
Expand Down
Loading