diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/blade.xml b/.idea/blade.xml new file mode 100644 index 0000000..0ef13f1 --- /dev/null +++ b/.idea/blade.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/laravel-idea-personal.xml b/.idea/laravel-idea-personal.xml new file mode 100644 index 0000000..101257b --- /dev/null +++ b/.idea/laravel-idea-personal.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/laravel-idea.xml b/.idea/laravel-idea.xml new file mode 100644 index 0000000..793d126 --- /dev/null +++ b/.idea/laravel-idea.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/laravel-selfupdater.iml b/.idea/laravel-selfupdater.iml new file mode 100644 index 0000000..5cb1268 --- /dev/null +++ b/.idea/laravel-selfupdater.iml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d9822aa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..e9efe11 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/config/self-update.php b/config/self-update.php index eef1702..eb12d73 100644 --- a/config/self-update.php +++ b/config/self-update.php @@ -21,6 +21,7 @@ |-------------------------------------------------------------------------- | | Set this to the version of your software installed on your system. + | By version we mean the "commit hash" of your git repository. | */ diff --git a/src/Models/Release.php b/src/Models/Release.php index a924ca4..e781c1d 100644 --- a/src/Models/Release.php +++ b/src/Models/Release.php @@ -80,7 +80,7 @@ public function setStoragePath(string $storagePath): self public function updateStoragePath(): self { if (!empty($this->getRelease())) { - $this->storagePath = Str::finish($this->storagePath, DIRECTORY_SEPARATOR).$this->getRelease(); + $this->storagePath = Str::finish($this->storagePath, urlSeparator()).$this->getRelease(); return $this; } diff --git a/src/Models/UpdateExecutor.php b/src/Models/UpdateExecutor.php index 07e0088..b782cd0 100644 --- a/src/Models/UpdateExecutor.php +++ b/src/Models/UpdateExecutor.php @@ -36,7 +36,7 @@ public function __construct() */ public function setBasePath(string $path): self { - $this->basePath = Str::finish($path, DIRECTORY_SEPARATOR); + $this->basePath = Str::finish($path, urlSeparator()); return $this; } @@ -88,7 +88,7 @@ private function moveFiles(string $folder): void if ($file->getRealPath()) { File::copy( $file->getRealPath(), - Str::finish($this->basePath, DIRECTORY_SEPARATOR).$file->getFilename() + Str::finish($this->basePath, urlSeparator()).$file->getFilename() ); } }); @@ -106,7 +106,7 @@ private function moveFolders(string $folder): void if (!dirsIntersect(File::directories($directory->getRealPath()), config('self-update.exclude_folders'))) { File::copyDirectory( $directory->getRealPath(), - Str::finish($this->basePath, DIRECTORY_SEPARATOR).Str::finish($directory->getRelativePath(), DIRECTORY_SEPARATOR).$directory->getBasename() + Str::finish($this->basePath, urlSeparator()).Str::finish($directory->getRelativePath(), DIRECTORY_SEPARATOR).$directory->getBasename() ); } diff --git a/src/SourceRepositoryTypes/GiteaRepositoryType.php b/src/SourceRepositoryTypes/GiteaRepositoryType.php index 93a3c5a..70c40fa 100644 --- a/src/SourceRepositoryTypes/GiteaRepositoryType.php +++ b/src/SourceRepositoryTypes/GiteaRepositoryType.php @@ -35,7 +35,7 @@ public function __construct(UpdateExecutor $updateExecutor) $this->config = config('self-update.repository_types.gitea'); $this->release = resolve(Release::class); - $this->release->setStoragePath(Str::finish($this->config['download_path'], DIRECTORY_SEPARATOR)) + $this->release->setStoragePath(Str::finish($this->config['download_path'], urlSeparator())) ->setUpdatePath(base_path(), config('self-update.exclude_folders')) ->setAccessToken($this->config['private_access_token']); $this->release->setAccessTokenPrefix('token '); diff --git a/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubBranchType.php b/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubBranchType.php index eeafe03..f4906ac 100644 --- a/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubBranchType.php +++ b/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubBranchType.php @@ -26,9 +26,8 @@ final class GithubBranchType extends GithubRepositoryType implements SourceRepos public function __construct(UpdateExecutor $updateExecutor) { parent::__construct(config('self-update.repository_types.github'), $updateExecutor); - $this->release = resolve(Release::class); - $this->release->setStoragePath(Str::finish($this->config['download_path'], DIRECTORY_SEPARATOR)) + $this->release->setStoragePath(Str::finish($this->config['download_path'], urlSeparator())) ->setUpdatePath(base_path(), config('self-update.exclude_folders')) ->setAccessToken($this->config['private_access_token']); } @@ -92,10 +91,10 @@ public function getVersionAvailable(string $prepend = '', string $append = ''): final public function getReleases(): Response { - $url = DIRECTORY_SEPARATOR.'repos' - .DIRECTORY_SEPARATOR.$this->config['repository_vendor'] - .DIRECTORY_SEPARATOR.$this->config['repository_name'] - .DIRECTORY_SEPARATOR.'commits' + $url = urlSeparator().'repos' + .urlSeparator().$this->config['repository_vendor'] + .urlSeparator().$this->config['repository_name'] + .urlSeparator().'commits' .'?sha='.$this->config['use_branch']; $headers = []; @@ -111,10 +110,10 @@ final public function getReleases(): Response private function generateArchiveUrl(string $name): string { - return DIRECTORY_SEPARATOR.'repos' - .DIRECTORY_SEPARATOR.$this->config['repository_vendor'] - .DIRECTORY_SEPARATOR.$this->config['repository_name'] - .DIRECTORY_SEPARATOR.'zipball' - .DIRECTORY_SEPARATOR.$name; + return urlSeparator().'repos' + .urlSeparator().$this->config['repository_vendor'] + .urlSeparator().$this->config['repository_name'] + .urlSeparator().'zipball' + .urlSeparator().$name; } } diff --git a/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php b/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php index 5d292df..de63303 100644 --- a/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php +++ b/src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php @@ -27,7 +27,7 @@ public function __construct(UpdateExecutor $updateExecutor) parent::__construct(config('self-update.repository_types.github'), $updateExecutor); $this->release = resolve(Release::class); - $this->release->setStoragePath(Str::finish($this->config['download_path'], DIRECTORY_SEPARATOR)) + $this->release->setStoragePath(Str::finish($this->config['download_path'], urlSeparator())) ->setUpdatePath(base_path(), config('self-update.exclude_folders')) ->setAccessToken($this->config['private_access_token']); } diff --git a/src/SourceRepositoryTypes/GitlabRepositoryType.php b/src/SourceRepositoryTypes/GitlabRepositoryType.php index 2522167..9ea9a32 100644 --- a/src/SourceRepositoryTypes/GitlabRepositoryType.php +++ b/src/SourceRepositoryTypes/GitlabRepositoryType.php @@ -35,7 +35,7 @@ public function __construct(UpdateExecutor $updateExecutor) $this->config = config('self-update.repository_types.gitlab'); $this->release = resolve(Release::class); - $this->release->setStoragePath(Str::finish($this->config['download_path'], DIRECTORY_SEPARATOR)) + $this->release->setStoragePath(Str::finish($this->config['download_path'], urlSeparator())) ->setUpdatePath(base_path(), config('self-update.exclude_folders')) ->setAccessToken($this->config['private_access_token']); diff --git a/src/SourceRepositoryTypes/HttpRepositoryType.php b/src/SourceRepositoryTypes/HttpRepositoryType.php index 03fb9c6..625c52b 100644 --- a/src/SourceRepositoryTypes/HttpRepositoryType.php +++ b/src/SourceRepositoryTypes/HttpRepositoryType.php @@ -42,7 +42,7 @@ public function __construct(UpdateExecutor $updateExecutor) $this->append = preg_replace('/^.*_VERSION_/', '', $this->config['pkg_filename_format']); $this->release = resolve(Release::class); - $this->release->setStoragePath(Str::finish($this->config['download_path'], DIRECTORY_SEPARATOR)) + $this->release->setStoragePath(Str::finish($this->config['download_path'], urlSeparator())) ->setUpdatePath(base_path(), config('self-update.exclude_folders')) ->setAccessToken($this->config['private_access_token']); diff --git a/src/helpers.php b/src/helpers.php index a68266e..bd66332 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -49,6 +49,13 @@ function createFolderFromFile(string $file): string $pathinfo = pathinfo($file); - return Str::finish($pathinfo['dirname'], DIRECTORY_SEPARATOR).$pathinfo['filename']; + return Str::finish($pathinfo['dirname'], urlSeparator()).$pathinfo['filename']; + } +} + +if (!\function_exists('urlSeparator')){ + function urlSeparator(): string + { + return '/'; } } diff --git a/tests/Models/ReleaseTest.php b/tests/Models/ReleaseTest.php index 1fcdd45..0a50c48 100644 --- a/tests/Models/ReleaseTest.php +++ b/tests/Models/ReleaseTest.php @@ -39,7 +39,7 @@ public function it_can_get_storage_path(): void { $this->assertNull($this->release->getStoragePath()); - $storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'tmp/releaseName.zip'; + $storagePath = Str::finish($this->vfs->url(), urlSeparator()).'tmp/releaseName.zip'; $this->release->setStoragePath($storagePath); $this->assertEquals($storagePath, $this->release->getStoragePath()); @@ -49,14 +49,14 @@ public function it_can_get_storage_path(): void public function it_can_update_storage_path_when_having_release_name(): void { $releaseName = 'releaseName'; - $storagePathWithoutFilename = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'tmp'; + $storagePathWithoutFilename = Str::finish($this->vfs->url(), urlSeparator()).'tmp'; $this->release->setStoragePath($storagePathWithoutFilename); $this->assertEquals($storagePathWithoutFilename, $this->release->getStoragePath()); $this->release->setRelease($releaseName)->updateStoragePath(); $this->assertEquals( - Str::finish($storagePathWithoutFilename, DIRECTORY_SEPARATOR).$releaseName, + Str::finish($storagePathWithoutFilename, urlSeparator()).$releaseName, $this->release->getStoragePath() ); } @@ -64,7 +64,7 @@ public function it_can_update_storage_path_when_having_release_name(): void /** @test */ public function it_should_not_update_storage_path_when_not_having_release_name(): void { - $storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'tmp'; + $storagePath = Str::finish($this->vfs->url(), urlSeparator()).'tmp'; $this->release->setStoragePath($storagePath); $this->assertEquals($storagePath, $this->release->getStoragePath()); @@ -86,7 +86,7 @@ public function it_can_set_update_path_without_exclude_dirs(): void $subDirectory = 'new-directory-inside'; vfsStream::newDirectory($mainDirectory.'/'.$subDirectory)->at($this->vfs); - $this->release->setUpdatePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).$mainDirectory); + $this->release->setUpdatePath(Str::finish($this->vfs->url(), urlSeparator()).$mainDirectory); foreach ($this->release->getUpdatePath()->directories() as $dir) { $this->assertEquals($dir->getPath(), $this->vfs->url().'/'.$mainDirectory); @@ -185,7 +185,7 @@ public function it_checks_source_is_not_fetched(): void public function it_checks_source_is_already_fetched_but_not_extracted(): void { $file = 'release-1.2.zip'; - $storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).$file; + $storagePath = Str::finish($this->vfs->url(), urlSeparator()).$file; vfsStream::newFile($file)->at($this->vfs); $this->release->setStoragePath($storagePath); @@ -197,7 +197,7 @@ public function it_checks_source_is_already_fetched_but_not_extracted(): void public function it_checks_source_is_already_extracted_and_directory_still_present(): void { vfsStream::newDirectory('release-1.2')->at($this->vfs); - $this->release->setStoragePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'release-1.2.zip'); + $this->release->setStoragePath(Str::finish($this->vfs->url(), urlSeparator()).'release-1.2.zip'); $this->assertTrue($this->release->isSourceAlreadyFetched()); } @@ -206,7 +206,7 @@ public function it_checks_source_is_already_extracted_and_directory_still_presen public function it_checks_source_is_already_extracted_and_directory_deleted(): void { vfsStream::newDirectory('release-1.2')->at($this->vfs); - $this->release->setStoragePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'release-1.2.zip'); + $this->release->setStoragePath(Str::finish($this->vfs->url(), urlSeparator()).'release-1.2.zip'); $this->vfs->getChild('release-1.2.zip')->rename('removed'); $this->assertTrue($this->release->isSourceAlreadyFetched());