diff --git a/README.md b/README.md index 796d042..37d8535 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,33 @@ file. This is the default. Updates will be fetched by using a tagged commit, aka release. +#### Tag-based updates with assets/package file + +If you have pre-packaged _tag based_ releases, you can use the `'repository_types.github.package_file_name'` key in your +`config/self-update.php` file or update the `SELF_UPDATER_PACKAGE_FILE_NAME` `.env` var to specify the asset name to +download. + +If you prefix the file name with `regex:` the package will try to find the latest asset matching the given regex. Note +however to use only the regex and not the PHP regex `/` prefix and suffixes. For example, an acceptable value would be +`regex:.releaseV*\.zip`. This will match all assets starting with `releaseV` and ending with `.zip`. + +An invalid value would be `regex:/releaseV*\.zip/`. Note the `/` prefix and suffix. + +```php +// ... +'repository_types' => [ + 'github' => [ + 'type' => 'github', + 'repository_vendor' => env('SELF_UPDATER_REPO_VENDOR', ''), + 'repository_name' => env('SELF_UPDATER_REPO_NAME', ''), + // ... + 'package_file_name' => 'release.zip', // Package file name to download + 'package_file_name' => 'regex:releaseV.*\.zip', // REGEX Package file name to download + ], + // ... +]; +``` + #### Branch-based updates Select the branch that should be used via the `use_branch` setting [inside the configuration](https://github.com/codedge/laravel-selfupdater/blob/master/config/self-update.php). diff --git a/composer.json b/composer.json index bd83882..8b6be32 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ } }, "scripts": { - "phpstan": "./vendor/bin/phpstan", + "phpstan": "./vendor/bin/phpstan --memory-limit=1G", "test": "./vendor/bin/phpunit", "test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html=build/coverage-html" } diff --git a/config/self-update.php b/config/self-update.php index e613195..95a9b7b 100644 --- a/config/self-update.php +++ b/config/self-update.php @@ -48,6 +48,7 @@ 'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'), 'private_access_token' => env('SELF_UPDATER_GITHUB_PRIVATE_ACCESS_TOKEN', ''), 'use_branch' => env('SELF_UPDATER_USE_BRANCH', ''), + 'package_file_name' => env('SELF_UPDATER_PACKAGE_FILE_NAME'), ], 'gitlab' => [ 'base_url' => '', diff --git a/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php b/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php index 5d292df..edaf1b7 100644 --- a/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php +++ b/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php @@ -13,6 +13,7 @@ use GuzzleHttp\Exception\InvalidArgumentException; use GuzzleHttp\Utils; use Illuminate\Http\Client\Response; +use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -77,10 +78,30 @@ public function fetch(string $version = ''): Release $release = $this->selectRelease($releases, $version); + $packageName = $this->config['package_file_name'] ?? null; + if ($packageName) { + $asset = Arr::first($release->assets, static function ($asset) use ($packageName) { + if (Str::startsWith($packageName, 'regex:')) { + // The package is a regex, so do a regex search + return Str::match('/'.Str::after($packageName, 'regex:').'/', $asset->name); + } + + return Str::contains($asset->name, $packageName); + }); + if (!$asset) { + throw ReleaseException::archiveFileNotFound($version); + } + $downloadUrl = $asset->browser_download_url; + $fileName = $asset->name; + } else { + $downloadUrl = $release->zipball_url; + $fileName = $release->tag_name.'.zip'; + } + $this->release->setVersion($release->tag_name) - ->setRelease($release->tag_name.'.zip') + ->setRelease($fileName) ->updateStoragePath() - ->setDownloadUrl($release->zipball_url); + ->setDownloadUrl($downloadUrl); if (!$this->release->isSourceAlreadyFetched()) { $this->release->download(); diff --git a/tests/Data/releases-tag_asset.json b/tests/Data/releases-tag_asset.json new file mode 100644 index 0000000..c763561 --- /dev/null +++ b/tests/Data/releases-tag_asset.json @@ -0,0 +1,372 @@ +[ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77612083", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77612083/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77612083/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.9", + "id": 77612083, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoEQz", + "tag_name": "v0.0.9", + "target_commitish": "master", + "name": "v0.0.9", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T04:19:32Z", + "published_at": "2022-09-20T04:21:10Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78406877", + "id": 78406877, + "node_id": "RA_kwDOIAa3RM4ErGTd", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576883, + "download_count": 0, + "created_at": "2022-09-20T04:21:11Z", + "updated_at": "2022-09-20T04:21:13Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.9/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.9", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.9", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611399", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611399/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77611399/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.8", + "id": 77611399, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoEGH", + "tag_name": "v0.0.8", + "target_commitish": "master", + "name": "v0.0.8", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T03:59:51Z", + "published_at": "2022-09-20T04:01:24Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78405569", + "id": 78405569, + "node_id": "RA_kwDOIAa3RM4ErF_B", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576930, + "download_count": 0, + "created_at": "2022-09-20T04:01:24Z", + "updated_at": "2022-09-20T04:01:25Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.8/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.8", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.8", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611121", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611121/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77611121/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.7", + "id": 77611121, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoEBx", + "tag_name": "v0.0.7", + "target_commitish": "master", + "name": "v0.0.7", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T03:51:21Z", + "published_at": "2022-09-20T03:53:07Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78405283", + "id": 78405283, + "node_id": "RA_kwDOIAa3RM4ErF6j", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576874, + "download_count": 0, + "created_at": "2022-09-20T03:53:08Z", + "updated_at": "2022-09-20T03:53:11Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.7/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.7", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.7", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77610757", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77610757/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77610757/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.6", + "id": 77610757, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoD8F", + "tag_name": "v0.0.6", + "target_commitish": "master", + "name": "v0.0.6", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T03:35:28Z", + "published_at": "2022-09-20T03:41:50Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78404772", + "id": 78404772, + "node_id": "RA_kwDOIAa3RM4ErFyk", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576880, + "download_count": 1, + "created_at": "2022-09-20T03:41:51Z", + "updated_at": "2022-09-20T03:42:10Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.6/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.6", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.6", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77496313", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77496313/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77496313/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.5", + "id": 77496313, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4Enn_5", + "tag_name": "v0.0.5", + "target_commitish": "master", + "name": "v0.0.5", + "draft": false, + "prerelease": false, + "created_at": "2022-09-19T01:15:26Z", + "published_at": "2022-09-19T01:17:00Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78288265", + "id": 78288265, + "node_id": "RA_kwDOIAa3RM4EqpWJ", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 29118229, + "download_count": 1, + "created_at": "2022-09-19T01:17:01Z", + "updated_at": "2022-09-19T01:17:04Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.5/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.5", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.5", + "body": "" + } +] diff --git a/tests/Data/releases-tag_regex_asset.json b/tests/Data/releases-tag_regex_asset.json new file mode 100644 index 0000000..99508a5 --- /dev/null +++ b/tests/Data/releases-tag_regex_asset.json @@ -0,0 +1,372 @@ +[ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77612083", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77612083/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77612083/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.9", + "id": 77612083, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoEQz", + "tag_name": "v0.0.9", + "target_commitish": "master", + "name": "v0.0.9", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T04:19:32Z", + "published_at": "2022-09-20T04:21:10Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78406877", + "id": 78406877, + "node_id": "RA_kwDOIAa3RM4ErGTd", + "name": "releaseV0.0.9.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576883, + "download_count": 0, + "created_at": "2022-09-20T04:21:11Z", + "updated_at": "2022-09-20T04:21:13Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.9/releaseV0.0.9.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.9", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.9", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611399", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611399/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77611399/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.8", + "id": 77611399, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoEGH", + "tag_name": "v0.0.8", + "target_commitish": "master", + "name": "v0.0.8", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T03:59:51Z", + "published_at": "2022-09-20T04:01:24Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78405569", + "id": 78405569, + "node_id": "RA_kwDOIAa3RM4ErF_B", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576930, + "download_count": 0, + "created_at": "2022-09-20T04:01:24Z", + "updated_at": "2022-09-20T04:01:25Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.8/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.8", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.8", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611121", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77611121/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77611121/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.7", + "id": 77611121, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoEBx", + "tag_name": "v0.0.7", + "target_commitish": "master", + "name": "v0.0.7", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T03:51:21Z", + "published_at": "2022-09-20T03:53:07Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78405283", + "id": 78405283, + "node_id": "RA_kwDOIAa3RM4ErF6j", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576874, + "download_count": 0, + "created_at": "2022-09-20T03:53:08Z", + "updated_at": "2022-09-20T03:53:11Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.7/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.7", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.7", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77610757", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77610757/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77610757/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.6", + "id": 77610757, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4EoD8F", + "tag_name": "v0.0.6", + "target_commitish": "master", + "name": "v0.0.6", + "draft": false, + "prerelease": false, + "created_at": "2022-09-20T03:35:28Z", + "published_at": "2022-09-20T03:41:50Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78404772", + "id": 78404772, + "node_id": "RA_kwDOIAa3RM4ErFyk", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 32576880, + "download_count": 1, + "created_at": "2022-09-20T03:41:51Z", + "updated_at": "2022-09-20T03:42:10Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.6/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.6", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.6", + "body": "" + }, + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77496313", + "assets_url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/77496313/assets", + "upload_url": "https://uploads.github.com/repos/pixelated-au/CartScheduler/releases/77496313/assets{?name,label}", + "html_url": "https://github.com/pixelated-au/CartScheduler/releases/tag/v0.0.5", + "id": 77496313, + "author": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "node_id": "RE_kwDOIAa3RM4Enn_5", + "tag_name": "v0.0.5", + "target_commitish": "master", + "name": "v0.0.5", + "draft": false, + "prerelease": false, + "created_at": "2022-09-19T01:15:26Z", + "published_at": "2022-09-19T01:17:00Z", + "assets": [ + { + "url": "https://api.github.com/repos/pixelated-au/CartScheduler/releases/assets/78288265", + "id": 78288265, + "node_id": "RA_kwDOIAa3RM4EqpWJ", + "name": "release.zip", + "label": "", + "uploader": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "content_type": "raw", + "state": "uploaded", + "size": 29118229, + "download_count": 1, + "created_at": "2022-09-19T01:17:01Z", + "updated_at": "2022-09-19T01:17:04Z", + "browser_download_url": "https://github.com/pixelated-au/CartScheduler/releases/download/v0.0.5/release.zip" + } + ], + "tarball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/tarball/v0.0.5", + "zipball_url": "https://api.github.com/repos/pixelated-au/CartScheduler/zipball/v0.0.5", + "body": "" + } +] diff --git a/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php b/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php index 93f33df..feca57f 100644 --- a/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php +++ b/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php @@ -224,6 +224,42 @@ public function it_can_fetch_github_tag_releases_and_takes_latest_if_version_not $this->assertEquals('2.6.1.zip', $release->getRelease()); } + /** @test */ + public function it_can_fetch_github_tag_asset_latest_release(): void + { + config(['self-update.repository_types.github.package_file_name' => 'release.zip']); + + /** @var GithubTagType $github */ + $github = (resolve(GithubRepositoryType::class))->create(); + + Http::fakeSequence() + ->pushResponse($this->getResponse200Type('tag_asset')) + ->pushResponse($this->getResponse200ZipFile()); + + $release = $github->fetch(); + $this->assertInstanceOf(Release::class, $release); + $this->assertEquals('v0.0.9', $release->getVersion()); + $this->assertEquals('release.zip', $release->getRelease()); + } + + /** @test */ + public function it_can_fetch_github_tag_regex_asset_latest_release(): void + { + config(['self-update.repository_types.github.package_file_name' => 'regex:releaseV\d+\.\d+\.\d+\.zip']); + + /** @var GithubTagType $github */ + $github = (resolve(GithubRepositoryType::class))->create(); + + Http::fakeSequence() + ->pushResponse($this->getResponse200Type('tag_regex_asset')) + ->pushResponse($this->getResponse200ZipFile()); + + $release = $github->fetch(); + $this->assertInstanceOf(Release::class, $release); + $this->assertEquals('v0.0.9', $release->getVersion()); + $this->assertEquals('releaseV0.0.9.zip', $release->getRelease()); + } + /** @test */ public function it_can_fetch_github_branch_releases_latest(): void { diff --git a/tests/TestCase.php b/tests/TestCase.php index 3b39ba0..3001398 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -19,11 +19,13 @@ abstract class TestCase extends Orchestra /** @var array */ protected array $mockedResponses = [ - 'tag' => 'releases-tag.json', - 'branch' => 'releases-branch.json', - 'http' => 'releases-http_gh.json', - 'gitlab' => 'releases-gitlab.json', - 'gitea' => 'releases-gitea.json', + 'tag' => 'releases-tag.json', + 'tag_asset' => 'releases-tag_asset.json', + 'tag_regex_asset' => 'releases-tag_regex_asset.json', + 'branch' => 'releases-branch.json', + 'http' => 'releases-http_gh.json', + 'gitlab' => 'releases-gitlab.json', + 'gitea' => 'releases-gitea.json', ]; /**