Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
name: Tests
on: [push]

on:
- push

jobs:
run:
runs-on: ubuntu-latest

strategy:
matrix:
php: ['8.1', '8.2']
laravel: [10.*]
laravel: ['10.*', '11.*']
dependency-version: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 11.*
php: '8.1'

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@2.24.0
uses: shivammathur/setup-php@2.27.0
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl, json, zip
Expand Down
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ that needs some updating mechanism without [Composer](https://getcomposer.org/).
To install the latest version from the master using [Composer](https://getcomposer.org/):

```sh
$ composer require codedge/laravel-selfupdater
composer require codedge/laravel-selfupdater
```

## Configuration

After installing the package you need to publish the configuration file via

```sh
$ php artisan vendor:publish --provider="Codedge\Updater\UpdaterServiceProvider"
php artisan vendor:publish --provider="Codedge\Updater\UpdaterServiceProvider"
```

**Note:** Please enter correct value for vendor and repository name in your `config/self-updater.php` if you want to use Github as source for your updates.
Expand Down Expand Up @@ -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).
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
"ext-json": "*",
"ext-zip": "*",
"guzzlehttp/guzzle": "^7.5.0",
"illuminate/support": "^10",
"league/uri": "~6.7 || ~6.8",
"illuminate/support": "^10 || ^11.0",
"league/uri": "~6.7 || ~6.8 || ^7.4",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-phpunit": "^1.2"
},
"require-dev": {
"dg/bypass-finals": "^1.4",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.5",
"orchestra/testbench": "^8.1",
"phpunit/phpunit": "^9.5.26"
"orchestra/testbench": "^8.1 || ^9.0",
"phpunit/phpunit": "^9.5.26 || ^10.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down Expand Up @@ -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"
}
Expand Down
13 changes: 13 additions & 0 deletions config/self-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down Expand Up @@ -97,6 +98,18 @@
'vendor',
],

/*
|--------------------------------------------------------------------------
| Download Timeout
|--------------------------------------------------------------------------
|
| Specifies the duration (in seconds) for how long downloads can take
| until they timeout.
|
*/

'download_timeout' => env('SELF_UPDATER_DOWNLOAD_TIMEOUT', 400),

/*
|--------------------------------------------------------------------------
| Event Logging
Expand Down
1 change: 1 addition & 0 deletions src/Models/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public function download(): Response
->withOptions([
'sink' => $this->getStoragePath(),
])
->timeout(config('self-update.download_timeout') ?? 400)
->get($this->getDownloadUrl());
}

Expand Down
25 changes: 23 additions & 2 deletions src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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->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();
Expand Down
Loading