diff --git a/.github/actions/svn-publish/action.yml b/.github/actions/svn-publish/action.yml new file mode 100644 index 0000000..8eb1163 --- /dev/null +++ b/.github/actions/svn-publish/action.yml @@ -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 }} diff --git a/.github/actions/svn-publish/deploy.sh b/.github/actions/svn-publish/deploy.sh new file mode 100644 index 0000000..6ab58ec --- /dev/null +++ b/.github/actions/svn-publish/deploy.sh @@ -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 diff --git a/.github/actions/svn-publish/src/plugin-version.sh b/.github/actions/svn-publish/src/plugin-version.sh new file mode 100644 index 0000000..816df8f --- /dev/null +++ b/.github/actions/svn-publish/src/plugin-version.sh @@ -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" +} diff --git a/.github/actions/svn-publish/src/working-directory.sh b/.github/actions/svn-publish/src/working-directory.sh new file mode 100644 index 0000000..5c0da2d --- /dev/null +++ b/.github/actions/svn-publish/src/working-directory.sh @@ -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" +} diff --git a/.github/workflows/publish-svn.yml b/.github/workflows/publish-svn.yml new file mode 100644 index 0000000..fc95456 --- /dev/null +++ b/.github/workflows/publish-svn.yml @@ -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 diff --git a/README.txt b/README.txt index 86d8d56..cf08215 100644 --- a/README.txt +++ b/README.txt @@ -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