Skip to content

Commit

Permalink
65 implement auto updater (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlHandy authored Sep 29, 2024
1 parent 297ee12 commit 91c4d5a
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 53 deletions.
8 changes: 3 additions & 5 deletions .github/scripts/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 43 additions & 43 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Create or Update Release
on:
push:
tags:
- 'v*'
- "v*"

permissions:
contents: write
Expand All @@ -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
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.ref_name }} ./mmg-checkout-payment.zip --clobber
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ wp-content/*
vendor
.phpunit.cache
logs
devbox.d/wordpress
devbox.d/wordpress
plugin-updater
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"require": {
"phpseclib/phpseclib": "~3.0"
"phpseclib/phpseclib": "~3.0",
"yahnis-elsts/plugin-update-checker": "^5.4"

},
"require-dev": {
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion includes/class-mmg-checkout-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() ) {
/**
Expand Down
8 changes: 8 additions & 0 deletions updater.json
Original file line number Diff line number Diff line change
@@ -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."
}
}

0 comments on commit 91c4d5a

Please sign in to comment.