From 0e1281f9304f570d5f4e652bce27f8ad0d12ef54 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Mon, 18 Nov 2024 10:49:08 -0500 Subject: [PATCH 1/4] feat: add publish to wordpress svn action --- .github/workflows/publish-svn.yml | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/publish-svn.yml diff --git a/.github/workflows/publish-svn.yml b/.github/workflows/publish-svn.yml new file mode 100644 index 0000000..5801827 --- /dev/null +++ b/.github/workflows/publish-svn.yml @@ -0,0 +1,36 @@ +name: Publish to WordPress SVN + +on: + workflow_dispatch: + inputs: + message: + description: 'Commit message' + default: 'Release x' + type: string + +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: richard-muvirimi/deploy-wordpress-plugin@development + with: + plugin-repository: https://plugins.svn.wordpress.org/openedx-commerce/ + svn-username: ${{ secrets.WORDPRESS_SVN_USERNAME }} + svn-password: ${{ secrets.WORDPRESS_SVN_PASSWORD }} + commit-message: ${{ inputs.message }} + assets-directory: ../docs/source/_images/plugin-page + working-directory: openedx-commerce + plugin-zip: '' From 5216e0939eb54610308bfb84fd353dd844676361 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Mon, 18 Nov 2024 13:18:26 -0500 Subject: [PATCH 2/4] docs: update the WordPress tested version to the latest --- README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 6823550a565334ee4610a73354ca6eb8ed1185f4 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Wed, 4 Dec 2024 16:48:19 -0500 Subject: [PATCH 3/4] chore: use our version of the workflow --- .github/actions/svn-publish/action.yml | 41 +++++++ .github/actions/svn-publish/deploy.sh | 106 ++++++++++++++++++ .../actions/svn-publish/src/plugin-version.sh | 21 ++++ .../svn-publish/src/working-directory.sh | 34 ++++++ .github/workflows/publish-svn.yml | 14 +-- 5 files changed, 205 insertions(+), 11 deletions(-) create mode 100644 .github/actions/svn-publish/action.yml create mode 100644 .github/actions/svn-publish/deploy.sh create mode 100644 .github/actions/svn-publish/src/plugin-version.sh create mode 100644 .github/actions/svn-publish/src/working-directory.sh 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 index 5801827..fc95456 100644 --- a/.github/workflows/publish-svn.yml +++ b/.github/workflows/publish-svn.yml @@ -1,12 +1,6 @@ name: Publish to WordPress SVN -on: - workflow_dispatch: - inputs: - message: - description: 'Commit message' - default: 'Release x' - type: string +on: workflow_dispatch jobs: build: @@ -25,12 +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://plugins.svn.wordpress.org/openedx-commerce/ + svn-repository: https://plugins.svn.wordpress.org/openedx-commerce/ svn-username: ${{ secrets.WORDPRESS_SVN_USERNAME }} svn-password: ${{ secrets.WORDPRESS_SVN_PASSWORD }} - commit-message: ${{ inputs.message }} assets-directory: ../docs/source/_images/plugin-page working-directory: openedx-commerce - plugin-zip: '' From f5c3775971823a08b958d69fbb9adb51ed315161 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Wed, 8 Jan 2025 16:45:43 -0500 Subject: [PATCH 4/4] fix: unify the publish actions --- .../{publish-svn.yml => publish.yml} | 26 ++++++++++-- .github/workflows/upload-release-zip.yml | 40 ------------------- 2 files changed, 22 insertions(+), 44 deletions(-) rename .github/workflows/{publish-svn.yml => publish.yml} (52%) delete mode 100644 .github/workflows/upload-release-zip.yml diff --git a/.github/workflows/publish-svn.yml b/.github/workflows/publish.yml similarity index 52% rename from .github/workflows/publish-svn.yml rename to .github/workflows/publish.yml index fc95456..215f864 100644 --- a/.github/workflows/publish-svn.yml +++ b/.github/workflows/publish.yml @@ -1,6 +1,9 @@ -name: Publish to WordPress SVN +name: Publish to WordPress and upload zip to the latest release -on: workflow_dispatch +on: + release: + types: [published] + workflow_dispatch: jobs: build: @@ -17,8 +20,23 @@ jobs: run: | make release - - name: WordPress Plugin Deploy - id: deploy + - name: Create a zip file + uses: thedoctor0/zip-release@0.7.6 + with: + type: 'zip' + command: 'cd ./openedx-commerce' + filename: '../openedx-commerce.zip' + + - name: Upload zip to the latest GitHub release + uses: xresloader/upload-to-github-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.WC_PAT }} + with: + file: "openedx-commerce.zip" + update_latest_release: true + draft: false + + - name: Publish to WordPress SVN uses: ./.github/actions/svn-publish with: svn-repository: https://plugins.svn.wordpress.org/openedx-commerce/ diff --git a/.github/workflows/upload-release-zip.yml b/.github/workflows/upload-release-zip.yml deleted file mode 100644 index 6ab6212..0000000 --- a/.github/workflows/upload-release-zip.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Upload zip to latest release - -on: - release: - types: [published] - workflow_dispatch: - -jobs: - upload_zip: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - token: ${{ secrets.WC_PAT }} - - - 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: Archive Release - uses: thedoctor0/zip-release@0.7.6 - with: - type: 'zip' - command: 'cd ./openedx-commerce' - filename: '../openedx-commerce.zip' - - - name: Upload zip to latest release - uses: xresloader/upload-to-github-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.WC_PAT }} - with: - file: "openedx-commerce.zip" - update_latest_release: true - draft: false