Issue/327 versioning (#345)

* Switch to semver format

* Rewrite new version check to use Github Releases and cron

* Styling

* Remove v from in front of version

* New version check test fix

* Uncomment test case
This commit is contained in:
Nabeel S
2019-08-06 17:48:00 -04:00
committed by GitHub
parent 092b9fc9dc
commit e12188b7d3
16 changed files with 1195 additions and 298 deletions

View File

@@ -1,6 +1,11 @@
<?php
use App\Repositories\SettingRepository;
use App\Services\DatabaseService;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Tests\TestData;
/**
@@ -103,6 +108,60 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
}
}
/**
* Read a file from the data directory
*
* @param $filename
*
* @return false|string
*/
public function readDataFile($filename)
{
$paths = [
'data/'.$filename,
'tests/data/'.$filename,
];
foreach ($paths as $p) {
if (file_exists($p)) {
return file_get_contents($p);
}
}
}
/**
* Return a mock Guzzle Client with a response loaded from $mockFile
*
* @param $mockFile
*/
public function mockGuzzleClient($mockFile): void
{
$mock = new MockHandler([
new Response(200,
[
'Content-Type' => 'application/json; charset=utf-8',
],
$this->readDataFile($mockFile)
),
]);
$handler = HandlerStack::create($mock);
$guzzleClient = new Client(['handler' => $handler]);
app()->instance(Client::class, $guzzleClient);
}
/**
* Update a setting
*
* @param $key
* @param $value
*/
public function updateSetting($key, $value)
{
$settingsRepo = app(SettingRepository::class);
$settingsRepo->store($key, $value);
}
/**
* So we can test private/protected methods
* http://bit.ly/1mr5hMq

78
tests/VersionTest.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
use App\Repositories\KvpRepository;
use App\Services\VersionService;
class VersionTest extends TestCase
{
private $kvpRepo;
public function setUp(): void
{
parent::setUp();
$this->kvpRepo = app(KvpRepository::class);
}
public function testGetLatestVersion()
{
setting('general.check_prerelease_version', false);
$this->mockGuzzleClient('releases.json');
$versionSvc = app(VersionService::class);
$str = $versionSvc->getLatestVersion();
$this->assertEquals('7.0.0-alpha2', $str);
$this->assertEquals('7.0.0-alpha2', $this->kvpRepo->get('latest_version_tag'));
}
public function testGetLatestPrereleaseVersion()
{
$this->updateSetting('general.check_prerelease_version', true);
$this->mockGuzzleClient('releases.json');
$versionSvc = app(VersionService::class);
$str = $versionSvc->getLatestVersion();
$this->assertEquals('7.0.0-beta', $str);
$this->assertEquals('7.0.0-beta', $this->kvpRepo->get('latest_version_tag'));
}
public function testNewVersionNotAvailable()
{
$this->updateSetting('general.check_prerelease_version', false);
$versions = [
'v7.0.0',
'7.0.0',
'8.0.0',
'7.0.0-beta',
'7.0.0+buildid',
];
foreach ($versions as $v) {
$this->mockGuzzleClient('releases.json');
$versionSvc = app(VersionService::class);
$this->assertFalse($versionSvc->isNewVersionAvailable($v));
}
}
public function testNewVersionIsAvailable()
{
$this->updateSetting('general.check_prerelease_version', true);
$versions = [
'v6.0.1',
'6.0.0',
'7.0.0-alpha',
];
foreach ($versions as $v) {
$this->mockGuzzleClient('releases.json');
$versionSvc = app(VersionService::class);
$this->assertTrue($versionSvc->isNewVersionAvailable($v));
}
}
}

360
tests/data/releases.json Normal file
View File

@@ -0,0 +1,360 @@
[
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/13667336",
"assets_url": "https://api.github.com/repos/nabeelio/phpvms/releases/13667336/assets",
"upload_url": "https://uploads.github.com/repos/nabeelio/phpvms/releases/13667336/assets{?name,label}",
"html_url": "https://github.com/nabeelio/phpvms/releases/tag/v7.0.0-beta",
"id": 13667336,
"node_id": "MDc6UmVsZWFzZTEzNjY3MzM2",
"tag_name": "v7.0.0-beta",
"target_commitish": "master",
"name": "",
"draft": false,
"author": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"prerelease": true,
"created_at": "2018-10-25T23:12:08Z",
"published_at": "2018-10-25T23:21:26Z",
"assets": [
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/assets/9415556",
"id": 9415556,
"node_id": "MDEyOlJlbGVhc2VBc3NldDk0MTU1NTY=",
"name": "phpvms-v7.0.0-beta.tar.gz",
"label": "",
"uploader": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/gzip",
"state": "uploaded",
"size": 15567950,
"download_count": 1503,
"created_at": "2018-10-25T23:21:25Z",
"updated_at": "2018-10-25T23:21:26Z",
"browser_download_url": "https://github.com/nabeelio/phpvms/releases/download/v7.0.0-beta/phpvms-v7.0.0-beta.tar.gz"
},
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/assets/9415555",
"id": 9415555,
"node_id": "MDEyOlJlbGVhc2VBc3NldDk0MTU1NTU=",
"name": "phpvms-v7.0.0-beta.tar.gz.sha256",
"label": "",
"uploader": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/octet-stream",
"state": "uploaded",
"size": 92,
"download_count": 174,
"created_at": "2018-10-25T23:21:24Z",
"updated_at": "2018-10-25T23:21:24Z",
"browser_download_url": "https://github.com/nabeelio/phpvms/releases/download/v7.0.0-beta/phpvms-v7.0.0-beta.tar.gz.sha256"
},
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/assets/9415554",
"id": 9415554,
"node_id": "MDEyOlJlbGVhc2VBc3NldDk0MTU1NTQ=",
"name": "release_version",
"label": "",
"uploader": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/octet-stream",
"state": "uploaded",
"size": 21,
"download_count": 630,
"created_at": "2018-10-25T23:21:23Z",
"updated_at": "2018-10-25T23:21:23Z",
"browser_download_url": "https://github.com/nabeelio/phpvms/releases/download/v7.0.0-beta/release_version"
}
],
"tarball_url": "https://api.github.com/repos/nabeelio/phpvms/tarball/v7.0.0-beta",
"zipball_url": "https://api.github.com/repos/nabeelio/phpvms/zipball/v7.0.0-beta",
"body": ""
},
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/9810818",
"assets_url": "https://api.github.com/repos/nabeelio/phpvms/releases/9810818/assets",
"upload_url": "https://uploads.github.com/repos/nabeelio/phpvms/releases/9810818/assets{?name,label}",
"html_url": "https://github.com/nabeelio/phpvms/releases/tag/v7.0.0-alpha2",
"id": 9810818,
"node_id": "MDc6UmVsZWFzZTk4MTA4MTg=",
"tag_name": "v7.0.0-alpha2",
"target_commitish": "master",
"name": null,
"draft": false,
"author": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"prerelease": false,
"created_at": "2018-02-23T17:48:28Z",
"published_at": "2018-02-23T17:57:13Z",
"assets": [
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/assets/6307893",
"id": 6307893,
"node_id": "MDEyOlJlbGVhc2VBc3NldDYzMDc4OTM=",
"name": "phpvms-v7.0.0-alpha2.tar.gz",
"label": "",
"uploader": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/gzip",
"state": "uploaded",
"size": 13122744,
"download_count": 1522,
"created_at": "2018-02-23T17:57:12Z",
"updated_at": "2018-02-23T17:57:13Z",
"browser_download_url": "https://github.com/nabeelio/phpvms/releases/download/v7.0.0-alpha2/phpvms-v7.0.0-alpha2.tar.gz"
},
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/assets/6307896",
"id": 6307896,
"node_id": "MDEyOlJlbGVhc2VBc3NldDYzMDc4OTY=",
"name": "phpvms-v7.0.0-alpha2.tar.gz.sha256",
"label": "",
"uploader": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/octet-stream",
"state": "uploaded",
"size": 94,
"download_count": 209,
"created_at": "2018-02-23T17:57:13Z",
"updated_at": "2018-02-23T17:57:13Z",
"browser_download_url": "https://github.com/nabeelio/phpvms/releases/download/v7.0.0-alpha2/phpvms-v7.0.0-alpha2.tar.gz.sha256"
}
],
"tarball_url": "https://api.github.com/repos/nabeelio/phpvms/tarball/v7.0.0-alpha2",
"zipball_url": "https://api.github.com/repos/nabeelio/phpvms/zipball/v7.0.0-alpha2",
"body": null
},
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/9526184",
"assets_url": "https://api.github.com/repos/nabeelio/phpvms/releases/9526184/assets",
"upload_url": "https://uploads.github.com/repos/nabeelio/phpvms/releases/9526184/assets{?name,label}",
"html_url": "https://github.com/nabeelio/phpvms/releases/tag/v7.0.0-alpha1",
"id": 9526184,
"node_id": "MDc6UmVsZWFzZTk1MjYxODQ=",
"tag_name": "v7.0.0-alpha1",
"target_commitish": "master",
"name": null,
"draft": false,
"author": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"prerelease": false,
"created_at": "2018-02-04T18:49:50Z",
"published_at": "2018-02-04T18:55:52Z",
"assets": [
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/assets/6096096",
"id": 6096096,
"node_id": "MDEyOlJlbGVhc2VBc3NldDYwOTYwOTY=",
"name": "phpvms-v7.0.0-alpha1.tar.gz",
"label": "",
"uploader": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/gzip",
"state": "uploaded",
"size": 13926978,
"download_count": 289,
"created_at": "2018-02-04T18:55:50Z",
"updated_at": "2018-02-04T18:55:51Z",
"browser_download_url": "https://github.com/nabeelio/phpvms/releases/download/v7.0.0-alpha1/phpvms-v7.0.0-alpha1.tar.gz"
},
{
"url": "https://api.github.com/repos/nabeelio/phpvms/releases/assets/6096097",
"id": 6096097,
"node_id": "MDEyOlJlbGVhc2VBc3NldDYwOTYwOTc=",
"name": "phpvms-v7.0.0-alpha1.tar.gz.sha256",
"label": "",
"uploader": {
"login": "nabeelio",
"id": 99736,
"node_id": "MDQ6VXNlcjk5NzM2",
"avatar_url": "https://avatars2.githubusercontent.com/u/99736?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nabeelio",
"html_url": "https://github.com/nabeelio",
"followers_url": "https://api.github.com/users/nabeelio/followers",
"following_url": "https://api.github.com/users/nabeelio/following{/other_user}",
"gists_url": "https://api.github.com/users/nabeelio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nabeelio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nabeelio/subscriptions",
"organizations_url": "https://api.github.com/users/nabeelio/orgs",
"repos_url": "https://api.github.com/users/nabeelio/repos",
"events_url": "https://api.github.com/users/nabeelio/events{/privacy}",
"received_events_url": "https://api.github.com/users/nabeelio/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/octet-stream",
"state": "uploaded",
"size": 94,
"download_count": 44,
"created_at": "2018-02-04T18:55:52Z",
"updated_at": "2018-02-04T18:55:52Z",
"browser_download_url": "https://github.com/nabeelio/phpvms/releases/download/v7.0.0-alpha1/phpvms-v7.0.0-alpha1.tar.gz.sha256"
}
],
"tarball_url": "https://api.github.com/repos/nabeelio/phpvms/tarball/v7.0.0-alpha1",
"zipball_url": "https://api.github.com/repos/nabeelio/phpvms/zipball/v7.0.0-alpha1",
"body": null
}
]