refactor: migrate plugin updates from GitHub to Mahgit
Build plugin release / release (push) Failing after 5s

This commit is contained in:
2026-08-24 10:06:49 +03:30
parent 322f484144
commit 79564cfaa2
6 changed files with 74 additions and 58 deletions
+54
View File
@@ -0,0 +1,54 @@
name: Build plugin release
on:
push:
tags:
- 'v*'
permissions:
code: read
releases: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate version and build ZIP
env:
RELEASE_TAG: ${{ gitea.ref_name }}
run: |
VERSION="${RELEASE_TAG#v}"
grep -q "Version: ${VERSION}$" dabestaniha-authenticate-bridge.php
mkdir -p build/mahak-authenticate-bridge dist
rsync -a \
--exclude='.git/' \
--exclude='.gitea/' \
--exclude='build/' \
--exclude='dist/' \
--exclude='test/' \
./ build/mahak-authenticate-bridge/
cd build
zip -qr ../dist/mahak-authenticate-bridge.zip mahak-authenticate-bridge
- name: Publish Gitea release
env:
GITEA_API_URL: ${{ gitea.api_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
RELEASE_TAG: ${{ gitea.ref_name }}
run: |
RELEASE_JSON="$(curl --fail-with-body --silent --show-error \
--request POST \
--header "Authorization: token ${GITEA_TOKEN}" \
--header 'Content-Type: application/json' \
--data "{\"tag_name\":\"${RELEASE_TAG}\",\"name\":\"${RELEASE_TAG}\",\"draft\":false,\"prerelease\":false}" \
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/releases")"
RELEASE_ID="$(printf '%s' "$RELEASE_JSON" | grep -o '"id":[0-9]*' | head -n 1 | cut -d: -f2)"
test -n "$RELEASE_ID"
curl --fail-with-body --silent --show-error \
--request POST \
--header "Authorization: token ${GITEA_TOKEN}" \
--form 'attachment=@dist/mahak-authenticate-bridge.zip' \
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/releases/${RELEASE_ID}/assets?name=mahak-authenticate-bridge.zip"
-38
View File
@@ -1,38 +0,0 @@
name: Build plugin release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate version and build ZIP
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
VERSION="${RELEASE_TAG#v}"
grep -q "Version: ${VERSION}$" dabestaniha-authenticate-bridge.php
mkdir -p build/mahak-authenticate-bridge dist
rsync -a \
--exclude='.git/' \
--exclude='.github/' \
--exclude='build/' \
--exclude='dist/' \
--exclude='test/' \
./ build/mahak-authenticate-bridge/
cd build
zip -qr ../dist/mahak-authenticate-bridge.zip mahak-authenticate-bridge
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.ref_name }}
run: gh release create "$RELEASE_TAG" dist/mahak-authenticate-bridge.zip --generate-notes --title "$RELEASE_TAG"
+1 -1
View File
@@ -16,7 +16,7 @@ Debug mode is disabled by default. An administrator can enable it from **Setting
Administrators can check for and install published releases from **Settings > Mahak Authentication**. Updates also appear in WordPress's standard **Plugins** and **Updates** screens.
To publish an update, change the plugin `Version` header and `MAHAK_AUTHENTICATE_BRIDGE_VERSION` constant to the same version, commit the change, and push a matching tag such as `v2.3.0` to GitHub. The release workflow builds and attaches the ZIP required by the WordPress updater.
To publish an update, change the plugin `Version` header and `MAHAK_AUTHENTICATE_BRIDGE_VERSION` constant to the same version, commit the change, and push a matching tag such as `v2.3.0` to Mahgit. The Gitea Actions workflow builds and attaches the ZIP required by the WordPress updater.
## Usage
+4 -4
View File
@@ -2,11 +2,11 @@
/**
* Plugin Name: Mahak Authenticate Bridge
* Plugin URI: https://github.com/dabestaniha/mahak-authenticate-bridge
* Plugin URI: https://mahgit.ir/dabestaniha/mahak-authenticate-bridge
* Description: Authenticate WordPress user via json web token from Mahakiha Application.
* Version: 2.2.1
* Version: 2.2.2
* Requires PHP: 7.4
* Update URI: https://github.com/dabestaniha/mahak-authenticate-bridge
* Update URI: https://mahgit.ir/dabestaniha/mahak-authenticate-bridge
* Author: Dabestaniha
*
* Example: https://wordpress.test/mahak/login/?token=eyJ0...
@@ -18,7 +18,7 @@ use Dabestaniha\AuthenticateBridge\App\Http\Controllers\SettingsPageMenuControll
use Dabestaniha\AuthenticateBridge\App\Http\Controllers\SettingsPageFormController;
use Dabestaniha\AuthenticateBridge\App\Support\PluginUpdater;
define('MAHAK_AUTHENTICATE_BRIDGE_VERSION', '2.2.1');
define('MAHAK_AUTHENTICATE_BRIDGE_VERSION', '2.2.2');
define('MAHAK_AUTHENTICATE_BRIDGE_FILE', __FILE__);
require_once __DIR__.'/src/Autoloader.php';
+9 -9
View File
@@ -4,9 +4,9 @@ namespace Dabestaniha\AuthenticateBridge\App\Support;
final class PluginUpdater
{
private const API_URL = 'https://api.github.com/repos/dabestaniha/mahak-authenticate-bridge/releases/latest';
private const API_URL = 'https://mahgit.ir/api/v1/repos/dabestaniha/mahak-authenticate-bridge/releases/latest';
private const RELEASE_ASSET = 'mahak-authenticate-bridge.zip';
private const RELEASE_CACHE = 'mahak_authenticate_bridge_release';
private const RELEASE_CACHE = 'mahak_authenticate_bridge_gitea_release';
private const CHECK_ACTION = 'mahak_authenticate_check_updates';
private static ?self $instance = null;
@@ -74,7 +74,7 @@ final class PluginUpdater
'slug' => $this->slug,
'version' => $this->releaseVersion($release),
'author' => 'Dabestaniha',
'homepage' => $release['html_url'] ?? 'https://github.com/dabestaniha/mahak-authenticate-bridge',
'homepage' => $release['html_url'] ?? 'https://mahgit.ir/dabestaniha/mahak-authenticate-bridge',
'download_link' => $package,
'requires_php' => '7.4',
'sections' => [
@@ -177,30 +177,30 @@ final class PluginUpdater
$response = wp_remote_get(self::API_URL, [
'headers' => [
'Accept' => 'application/vnd.github+json',
'Accept' => 'application/json',
'User-Agent' => 'Mahak-Authenticate-Bridge/'.MAHAK_AUTHENTICATE_BRIDGE_VERSION,
],
'timeout' => 10,
]);
if (is_wp_error($response)) {
return new \WP_Error('mahak_update_request_failed', 'Could not contact GitHub to check for plugin updates.');
return new \WP_Error('mahak_update_request_failed', 'Could not contact Mahgit to check for plugin updates.');
}
if (wp_remote_retrieve_response_code($response) !== 200) {
return new \WP_Error('mahak_update_response_invalid', 'No published plugin release is currently available on GitHub.');
return new \WP_Error('mahak_update_response_invalid', 'No published plugin release is currently available on Mahgit.');
}
$release = json_decode(wp_remote_retrieve_body($response), true);
if (!is_array($release) || !empty($release['draft']) || !empty($release['prerelease'])) {
return new \WP_Error('mahak_update_release_invalid', 'GitHub returned invalid plugin release information.');
return new \WP_Error('mahak_update_release_invalid', 'Mahgit returned invalid plugin release information.');
}
if ($this->releaseVersion($release) === '' || $this->releasePackage($release) === null) {
return new \WP_Error(
'mahak_update_asset_missing',
'The latest GitHub release does not contain a valid mahak-authenticate-bridge.zip package.'
'The latest Mahgit release does not contain a valid mahak-authenticate-bridge.zip package.'
);
}
@@ -228,7 +228,7 @@ final class PluginUpdater
if (
$url !== ''
&& wp_parse_url($url, PHP_URL_SCHEME) === 'https'
&& wp_parse_url($url, PHP_URL_HOST) === 'github.com'
&& wp_parse_url($url, PHP_URL_HOST) === 'mahgit.ir'
&& strpos($path, '/dabestaniha/mahak-authenticate-bridge/releases/download/') === 0
) {
return $url;
+6 -6
View File
@@ -310,9 +310,9 @@ function test_debug_error_details(): void
function test_plugin_update_discovery(): void
{
$packageUrl = 'https://github.com/dabestaniha/mahak-authenticate-bridge/releases/download/v2.3.0/mahak-authenticate-bridge.zip';
$packageUrl = 'https://mahgit.ir/dabestaniha/mahak-authenticate-bridge/releases/download/v2.3.0/mahak-authenticate-bridge.zip';
$mockRelease = function ($response, array $request, string $url) use ($packageUrl) {
if ($url !== 'https://api.github.com/repos/dabestaniha/mahak-authenticate-bridge/releases/latest') {
if ($url !== 'https://mahgit.ir/api/v1/repos/dabestaniha/mahak-authenticate-bridge/releases/latest') {
return $response;
}
@@ -320,7 +320,7 @@ function test_plugin_update_discovery(): void
'headers' => [],
'body' => json_encode([
'tag_name' => 'v2.3.0',
'html_url' => 'https://github.com/dabestaniha/mahak-authenticate-bridge/releases/tag/v2.3.0',
'html_url' => 'https://mahgit.ir/dabestaniha/mahak-authenticate-bridge/releases/tag/v2.3.0',
'body' => 'Test release',
'draft' => false,
'prerelease' => false,
@@ -335,7 +335,7 @@ function test_plugin_update_discovery(): void
];
};
delete_site_transient('mahak_authenticate_bridge_release');
delete_site_transient('mahak_authenticate_bridge_gitea_release');
add_filter('pre_http_request', $mockRelease, 10, 3);
$updates = apply_filters('pre_set_site_transient_update_plugins', (object) [
@@ -345,11 +345,11 @@ function test_plugin_update_discovery(): void
remove_filter('pre_http_request', $mockRelease, 10);
assert_true(isset($updates->response[TEST_PLUGIN]), 'A newer GitHub release was not offered as a WordPress update.');
assert_true(isset($updates->response[TEST_PLUGIN]), 'A newer Mahgit release was not offered as a WordPress update.');
assert_true($updates->response[TEST_PLUGIN]->new_version === '2.3.0', 'The offered plugin version was incorrect.');
assert_true($updates->response[TEST_PLUGIN]->package === $packageUrl, 'The release package URL was incorrect.');
pass('Published GitHub releases are discovered by the WordPress updater');
pass('Published Mahgit releases are discovered by the WordPress updater');
}
boot_wordpress();