-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/skip asset update #278
Conversation
What is the goal of update with does not update? |
@schmunk42 Thank you for this PR. Regarding the implementation, it is necessary to use the new configuration system, which allows to configure the plugin globally, by project or by overriding the options with env variables (see Define the config for all projects and Define the config in a environment variable). As for the option name, since this option is reserved for Github and works with As for location, it is probably best to place it in the Given that this option can be set globally etc, you must also add a check ( Last point, the unit tests and the doc when it will finalized! :-) @samdark To update the PHP dependencies, and avoid the asset update search when you only want to add /remove/update PHP dependencies. This can save you a lot of time. |
This can waste a lot of your time of one of PHP dependencies depends on clientside dependency. |
@francoispluchino Thanks for the feedback, will update that. @samdark First of all, if you do not use this option the plugin behaves the same. If you do not have data of a repo, it will download it - always. If you turn on the option, it will not skip the update of asset itself, but only the synchronization of the repositories already in the cache, if their modification time is within your threshold. Otherwise they'll be synced and the plugin would behave as always. Sure there might be edge cases, but for day-to-day development I'd say a value of I think it's worth a try - my largest testing application with ~350 extensions (>50 bower asset repos) updates in <25 secs. |
Then I'd make this "no-refetch" thing affect both clientside and PHP packages so there's no partial out of sync situation. |
Information for PHP packages is usually downloaded via Packagist. |
@samdark In Composer, you can only update a specific package using the Currently, if you run the command But I may not have understood your problem. |
@schmunk42 Normally this only applies only to the Git Vcs Drivers of the assets. Each VCS repository use a new instance of an VCS driver. And for assets, they are specific drivers. So, the php packages are not affected. |
@schmunk42 Can your pull request be fixed quickly so that we can release the |
I renamed it, and it's already in ´GitDriver`. Can I check the ENV or do I need to use an internal API?
Added check.
Hope you can help me out a bit with the unit tests, docs should be no big deal. [edit] |
You have an example in the ConfigTest class. But you should use the |
@francoispluchino Could you give me a hint with the test in 7a62259 |
I will inject the config into the In your test, you will just have to add the mock of the |
Added by 68fc247. I was wrong, the Given that I had to inject the config into the AssetRepositoryManager class, And that it is injected into all VCS Repositories, it's best to avoid adding another key to /* @var AssetRepositoryManager $arm */
$arm = $this->repoConfig['asset-repository-manager'];
if (null !== ($skip = $arm->getConfig()->get('git-skip-update'))) {
// your code ... > strtotime($skip)
} |
@schmunk42 see my previous comment to use the Fxp Asset Config and not the Composer config. |
:( I don't get it?! First thing I noticed is a little typo in the variable name, btw: asse
Where would I have to add your code-snippet? The code is basically running fine, also the mocking of the test config works, it just not reaches the two red lines in the test, I thought because of missing cache files, no? I'd not mind if you can fix this ;) btw: I'd mark the feature as experimental in 1.3 |
I do that tomorrow. |
Repository/Vcs/GitDriver.php
Outdated
{ | ||
if (isset($this->config->get('fxp-asset')['git-driver']['skip-update'])) { | ||
$skip = $this->config->get('fxp-asset')['git-driver']['skip-update']; | ||
if ($skip != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be just if ($skip)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this test after the changes of the if
condition.
Repository/Vcs/GitDriver.php
Outdated
if (isset($this->config->get('fxp-asset')['git-driver']['skip-update'])) { | ||
$skip = $this->config->get('fxp-asset')['git-driver']['skip-update']; | ||
if ($skip != 0) { | ||
$localUrl = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about -
and _
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the -
and _
in your regex expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is taken from https://github.com/composer/composer/blob/master/src/Composer/Repository/Vcs/GitDriver.php#L45
Why should we treat _
differently and why change -
at all?
'skip-update' => '1 week', | ||
], | ||
], | ||
// TODO: bring code-coverage to 100% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed. I just marked this, because I thought this would bring the coverage back to 100%.
My snippet must be added in the |
@francoispluchino That would be great! |
Thanks to clean your code and your commits :-) |
Would be as clean as I can make it right now. I started with this feature before your changes for 1.3, so I had to merge against master two times, I'd like to avoid rebasing on this setup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schmunk42 It only lacks your feature, so the master branch will not change. Your last 4 commits (2589a2c, d68a154, 753eae6, d8ccfe7) are not suitable (see my code reviews).
Regarding the cleaning, you have 3 files, therefore in the worst case, you copy your changes, you rebase, and you edit your Pull Request (without taking into account your last 4 commits above).
If you wish it, remove your tests, I'll take care of it. But clean your PR so I can merge it and make the necessary changes. Thanks!
Repository/Vcs/GitDriver.php
Outdated
*/ | ||
public function initialize() | ||
{ | ||
if (isset($this->config->get('fxp-asset')['git-driver']['skip-update'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot use a hierarchy in the config to use environment variables (FXP_ASSET__GIT_SKIP_UPDATE
env variable is mapped with the config.fxp-asset.git-skip-update
package configuration).
You use the Composer config and not the Fxp Asset Config (I cannot extend the Composer config).
To access the Fxp asset config from the GitDriver::initialize()
method, you must get the instance of AssetRepositoryManager
stored in the repoConfig
property and call the getConfig()
method:
/* @var AssetRepositoryManager $arm */
$arm = $this->repoConfig['asset-repository-manager'];
if (null !== ($skip = $arm->getConfig()->get('git-skip-update'))) {
// your code ... > strtotime($skip)
}
So, replace this if
condition by this snippet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I dump (print_r) repoConfig
in initialize()
I get:
Array
(
[url] => https://github.com/twbs/bootstrap.git
[asset-type] => bower
[filename] => bower.json
)
There's no asset-repository-manager
key?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I see, the using of the Git driver from the Github driver doesn't include this variable. I add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added by 1ca5831.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed. I tested it locally.
I am trying to fix the tests also, but I am currently stuck with this error message Error: Call to undefined method Mock_AssetRepositoryManager_aa5355bb::getConfig()
Repository/Vcs/GitDriver.php
Outdated
{ | ||
if (isset($this->config->get('fxp-asset')['git-driver']['skip-update'])) { | ||
$skip = $this->config->get('fxp-asset')['git-driver']['skip-update']; | ||
if ($skip != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this test after the changes of the if
condition.
Repository/Vcs/GitDriver.php
Outdated
if (isset($this->config->get('fxp-asset')['git-driver']['skip-update'])) { | ||
$skip = $this->config->get('fxp-asset')['git-driver']['skip-update']; | ||
if ($skip != 0) { | ||
$localUrl = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the -
and _
in your regex expression.
$repoUrl = 'https://github.com/fxpio/composer-asset-plugin.git'; | ||
$identifier = '92bebbfdcde75ef2368317830e54b605bc938123'; | ||
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add:
$assetConfig = new \Fxp\Composer\AssetPlugin\Config\Config(array(
'git-skip-update' => true,
));
/* @var AssetRepositoryManager|\PHPUnit_Framework_MockObject_MockObject $arm */
$arm = $this->getMockBuilder(AssetRepositoryManager::class)->disableOriginalConstructor()->getMock();
$arm->expects($this->any())
->method('getConfig')
->willReturn($config);
$this->config->merge([ | ||
'config' => [ | ||
'fxp-asset' => [ | ||
'git-driver' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the fxp-asset
key.
$repoConfig = array( | ||
'url' => $repoUrl, | ||
'asset-type' => $type, | ||
'filename' => $filename, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add:
'asset-repository-manager' => $arm,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I do this in setUp()
in the test for all tests?
When using the RepositoryManager in GitDriver
, most of the tests fail with...
6) Fxp\Composer\AssetPlugin\Tests\Repository\Vcs\GitDriverTest::testPublicRepositoryWithFilesystemCache with data set #1 ('bower', 'bower.json')
Undefined index: asset-repository-manager
/app/Repository/Vcs/GitDriver.php:46
/app/Tests/Repository/Vcs/GitDriverTest.php:249
7) Fxp\Composer\AssetPlugin\Tests\Repository\Vcs\GitHubDriverTest::testPrivateRepositoryNoInteraction with data set #0 ('npm', 'package.json')
Error: Call to a member function get() on null
But the actual code work, this is just an issue during testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes of course, you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at: e676a76
I am getting...
8) Fxp\Composer\AssetPlugin\Tests\Repository\Vcs\GitDriverTest::testPublicRepositoryWithFilesystemCache with data set #1 ('bower', 'bower.json')
Trying to configure method "getConfig" which cannot be configured because it does not exist, has not been specified, is final, or is static
I thought we'd avoid that by extending from AssetRepositoryManager
- I am getting confused :)
Also the GitHubDriver
test now complains about
18) Fxp\Composer\AssetPlugin\Tests\Repository\Vcs\GitHubDriverTest::testNoApi with data set #5 ('bower', 'bower.json', array('0123456789abcdef0123456789abc...234567'), array('master 0123456789abcdef012345...omment'))
Error: Call to a member function get() on null
I am unsure if I'd need to mock the config or add actual checks to the GitDriver.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You must add the asset-repository-manager
key in each repoConfig of failed tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For GithubDriverTest, you must create a asset config in the setUp() method, and mock the AssetRepositoryManager::getConfig()
method returning the instance of asset config.
Resources/doc/schema.md
Outdated
@@ -49,6 +49,10 @@ The plugin can override the main file definitions of the Bower packages. To over | |||
definitions specify the packages and their main file array as name/value pairs. For an example | |||
see the [usage informations](index.md#override-the-main-files-for-bower). | |||
|
|||
##### config.fxp-asset.git-driver.skip-update (root-only) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore the config key config.fxp-asset.git-skip-update
, and add an example of package config and explain this feature and its benefits.
{
"config": {
"fxp-asset": {
"git-skip-update": "3 days"
}
}
}
It's green 💚 🍏 📗 💚 |
Hm, so it's red again. Can I even mock this? The underlying issue is, that it composer just empties the cache-directory, instead of removing it. |
Perhaps it is better to dynamically create a local GIT repository for the test, to add a commit, and delete the folder of repository at the end of the test, and not an existing Github repository. |
I don't need to add a commit, the issue is that the repo in the tests is completely empty. |
@francoispluchino Still any help welcome. I tried several times to get coverage back to 100% but without luck. |
@francoispluchino Please see https://coveralls.io/jobs/24161140/source_files/766890807 - looks to me like my changes are covered 100% now. |
@schmunk42 Clean your commits and it's ok for me, thanks. |
76eceaf
to
c913369
Compare
Done. |
c913369
to
1da0bc0
Compare
@francoispluchino I am sorry to report that this causes some issues in the I am thinking about a solution. Are there tests for On the other hand, it would be great if you could at least pull this onto a branch in your repo, since it'd greatly simplify testing of the current features. |
Please see #289 |
@schmunk42 Have I to close the PR #287 and this PR, in favor of the PR #289? |
Yes. I'll close this, please have a look at the other PR. |
Testing:
Note:
github-no-api
must be set totrue
Result:
🚀 4x faster (eg. with yii2-app-advanced ~10 seconds); after the first run
Currently creates an additional clone in the cache, I am open for discussion about the implementation. But in this way it should not affect existing installations at all.
CC: @cebe @samdark @motin @mikehaertl @tonydspaniard