From 91c4d5ad8e476fa65109119f9e842e098a432625 Mon Sep 17 00:00:00 2001 From: Carl Handy Date: Sun, 29 Sep 2024 00:41:54 -0400 Subject: [PATCH] 65 implement auto updater (#67) --- .github/scripts/update-version.sh | 8 +-- .github/workflows/release.yml | 86 ++++++++++++------------- .gitignore | 3 +- composer.json | 3 +- composer.lock | 52 ++++++++++++++- includes/class-mmg-checkout-payment.php | 2 +- main.php | 10 ++- updater.json | 8 +++ 8 files changed, 119 insertions(+), 53 deletions(-) create mode 100644 updater.json diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 9bfa0222..a74824fb 100644 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -11,12 +11,10 @@ sed -i "s/\([ *]*Version:[ ]*\)[0-9.]\+/\1$NEW_VERSION/" main.php sed -i "s/\(define('MMG_PLUGIN_VERSION', '\)[0-9.]\+/\1$NEW_VERSION/" main.php # Update the Stable tag in README.txt sed -i "s/\(Stable tag: \)[0-9.]\+/\1$NEW_VERSION/" README.txt +sed -i "s/\([ "]version:[ ]"\)[0-9.]\+/\1$NEW_VERSION/" updater.json +sed -i "s|/releases/download/v[0-9.]\+/mmg-checkout-payment.zip|/releases/download/v$NEW_VERSION/mmg-checkout-payment.zip|" updater.json -# Add README.txt to the commit -git add README.txt - -# Commit the change -git add main.php +git add README.txt updater.json main.php git commit -m "Bump version to $NEW_VERSION" # Push the change to the main branch diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 421105ae..fb9a0902 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Create or Update Release on: push: tags: - - 'v*' + - "v*" permissions: contents: write @@ -12,55 +12,55 @@ jobs: update-version: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - token: ${{ secrets.PAT }} - - name: Update version in main.php - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - run: | - git config --local user.email "carl@kalpa.dev" - git config --local user.name "Carl Handy" - git fetch --all - git checkout main - git pull origin main - chmod +x .github/scripts/update-version.sh - ./.github/scripts/update-version.sh - git push origin main + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.PAT }} + - name: Update version in main.php + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + run: | + git config --local user.email "carl@kalpa.dev" + git config --local user.name "Carl Handy" + git fetch --all + git checkout main + git pull origin main + chmod +x .github/scripts/update-version.sh + ./.github/scripts/update-version.sh + git push origin main build: needs: update-version runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Fetch latest changes - run: | - git fetch --all - git checkout main - git pull origin main + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Fetch latest changes + run: | + git fetch --all + git checkout main + git pull origin main - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "7.4" - - name: Install Composer dependencies - run: composer install --no-dev --optimize-autoloader + - name: Install Composer dependencies + run: composer install --no-dev --optimize-autoloader - - name: Zip project - run: zip -r mmg-checkout-payment.zip main.php LICENSE.txt uninstall.php vendor/* README.txt js/* assets/* includes/* + - name: Zip project + run: zip -r mmg-checkout-payment.zip main.php LICENSE.txt uninstall.php vendor/* README.txt js/* assets/* includes/* - - name: Setup GitHub CLI - uses: actions/setup-go@v4 - with: - go-version: '>=1.18.0' - - run: go install github.com/cli/cli/v2/cmd/gh@latest + - name: Setup GitHub CLI + uses: actions/setup-go@v4 + with: + go-version: ">=1.18.0" + - run: go install github.com/cli/cli/v2/cmd/gh@latest - - name: Upload Release Asset - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload ${{ github.ref_name }} ./mmg-checkout-payment.zip --clobber \ No newline at end of file + - name: Upload Release Asset + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ github.ref_name }} ./mmg-checkout-payment.zip --clobber diff --git a/.gitignore b/.gitignore index ecd0ec2d..8b800ca2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ wp-content/* vendor .phpunit.cache logs -devbox.d/wordpress \ No newline at end of file +devbox.d/wordpress +plugin-updater \ No newline at end of file diff --git a/composer.json b/composer.json index 64d1711e..30b81689 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "require": { - "phpseclib/phpseclib": "~3.0" + "phpseclib/phpseclib": "~3.0", + "yahnis-elsts/plugin-update-checker": "^5.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 72096825..0bad8c5e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2ec62acb1cf368b01011f10c2f2bd76b", + "content-hash": "43b21584ef6bb6203db427316e3aee22", "packages": [ { "name": "paragonie/constant_time_encoding", @@ -232,6 +232,56 @@ } ], "time": "2024-06-24T06:27:33+00:00" + }, + { + "name": "yahnis-elsts/plugin-update-checker", + "version": "v5.4", + "source": { + "type": "git", + "url": "https://github.com/YahnisElsts/plugin-update-checker.git", + "reference": "e8e53e6d98e37fa7c895c93417f52e3775494715" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/YahnisElsts/plugin-update-checker/zipball/e8e53e6d98e37fa7c895c93417f52e3775494715", + "reference": "e8e53e6d98e37fa7c895c93417f52e3775494715", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.6.20" + }, + "type": "library", + "autoload": { + "files": [ + "load-v5p4.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Yahnis Elsts", + "email": "whiteshadow@w-shadow.com", + "homepage": "https://w-shadow.com/", + "role": "Developer" + } + ], + "description": "A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.", + "homepage": "https://github.com/YahnisElsts/plugin-update-checker/", + "keywords": [ + "automatic updates", + "plugin updates", + "theme updates", + "wordpress" + ], + "support": { + "issues": "https://github.com/YahnisElsts/plugin-update-checker/issues", + "source": "https://github.com/YahnisElsts/plugin-update-checker/tree/v5.4" + }, + "time": "2024-02-24T09:56:49+00:00" } ], "packages-dev": [ diff --git a/includes/class-mmg-checkout-payment.php b/includes/class-mmg-checkout-payment.php index 370d9599..d00414ac 100644 --- a/includes/class-mmg-checkout-payment.php +++ b/includes/class-mmg-checkout-payment.php @@ -215,7 +215,7 @@ private function encrypt( $checkout_object ) { $json_bytes = mb_convert_encoding( $json_object, 'ISO-8859-1', 'UTF-8' ); } else { // Fallback method. - $json_bytes = utf8_decode( $json_object ); + $json_bytes = mb_convert_encoding( $json_object, 'ISO-8859-1', 'UTF-8' ); } // Load the public key. diff --git a/main.php b/main.php index 76faa9b1..b2ffac95 100644 --- a/main.php +++ b/main.php @@ -9,7 +9,7 @@ * * @wordpress-plugin * Plugin Name: MMG Checkout Payment - * Plugin URI: https://mmg-wp-plugin-docs.pages.dev + * Plugin URI: https://mmg-plugin.kalpa.dev * Description: Enables MMG Checkout Payment flow for registered MMG Merchants to receive E-Commerce payments from MMG customers. * Version: 2.0.6 * Requires at least: 6.0 @@ -35,6 +35,14 @@ require_once plugin_dir_path( __FILE__ ) . 'includes/class-mmg-checkout-payment-activator.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-mmg-checkout-payment-deactivator.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-mmg-checkout-payment-deactivator.php'; +// This is temporary until the plugin is uploaded to the WordPress repository. +use YahnisElsts\PluginUpdateChecker\v5\PucFactory; + +$update_checker = PucFactory::buildUpdateChecker( + 'updater.json', + __FILE__, + 'mmg-checkout-payment' +); if ( MMG_Dependency_Checker::check_dependencies() ) { /** diff --git a/updater.json b/updater.json new file mode 100644 index 00000000..a8494b73 --- /dev/null +++ b/updater.json @@ -0,0 +1,8 @@ + { + "name" : "MMG Checkout Payment", + "version" : "2.0.6", + "download_url" : "https://github.com/Kalpa-Services/mmg-wp-plugin/releases/download/v2.0.6/mmg-checkout-payment.zip", + "sections" : { + "description" : "Enables MMG Checkout Payment flow for registered MMG Merchants to receive E-Commerce payments from MMG customers." + } + } \ No newline at end of file