diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..f1bf460 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index f2ce16c..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -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" diff --git a/README.md b/README.md index d1eb0f2..1e0090f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dabestaniha-authenticate-bridge.php b/dabestaniha-authenticate-bridge.php index fdaf433..48ba9a3 100644 --- a/dabestaniha-authenticate-bridge.php +++ b/dabestaniha-authenticate-bridge.php @@ -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'; diff --git a/src/app/Support/PluginUpdater.php b/src/app/Support/PluginUpdater.php index f4e315b..cf6fda8 100644 --- a/src/app/Support/PluginUpdater.php +++ b/src/app/Support/PluginUpdater.php @@ -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; diff --git a/test/integration-authentication.php b/test/integration-authentication.php index f5706c1..9a7b2c4 100644 --- a/test/integration-authentication.php +++ b/test/integration-authentication.php @@ -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();