Skip to content
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

Prevent unnecessary downloads of library packages - just update the json/lock files #2998

Closed
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
15 changes: 3 additions & 12 deletions composer/helpers/v2/src/UpdateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Composer\Factory;
use Composer\Installer;
use Composer\Package\PackageInterface;
use Composer\Util\Filesystem;

final class UpdateChecker
{
Expand Down Expand Up @@ -48,30 +47,22 @@ public static function getLatestResolvableVersion(array $args): ?string
$io->loadConfiguration($config);
}

$installationManager = new DependabotInstallationManager($composer->getLoop(), $io);

$fs = new Filesystem(null);
$binaryInstaller = new Installer\BinaryInstaller($io, rtrim($composer->getConfig()->get('bin-dir'), '/'), $composer->getConfig()->get('bin-compat'), $fs);

$installationManager->addInstaller(new Installer\LibraryInstaller($io, $composer, null, $fs, $binaryInstaller));
$installationManager->addInstaller(new Installer\PluginInstaller($io, $composer, $fs, $binaryInstaller));
$installationManager->addInstaller(new Installer\MetapackageInstaller($io));

$install = new Installer(
$io,
$config,
$composer->getPackage(), // @phpstan-ignore-line
$composer->getDownloadManager(),
$composer->getRepositoryManager(),
$composer->getLocker(),
$installationManager,
$composer->getInstallationManager(),
$composer->getEventDispatcher(),
$composer->getAutoloadGenerator()
);

// For all potential options, see UpdateCommand in composer
$install
->setUpdate(true)
->setInstall(false)
->setDevMode(true)
->setUpdateAllowTransitiveDependencies(Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS)
->setDumpAutoloader(false)
Expand All @@ -86,7 +77,7 @@ public static function getLatestResolvableVersion(array $args): ?string

$install->run();

$installedPackages = $installationManager->getInstalledPackages();
$installedPackages = $composer->getLocker()->getLockedRepository(true)->getPackages();
Copy link
Contributor Author

@driskell driskell Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This boolean argument to getLockedRepository is "withDevReqs" to return all packages including dev requirements.


$updatedPackage = current(array_filter($installedPackages, static function (PackageInterface $package) use ($dependencyName): bool {
return $package->getName() === $dependencyName;
Expand Down
1 change: 1 addition & 0 deletions composer/helpers/v2/src/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static function update(array $args): array
$install
->setWriteLock(true)
->setUpdate(true)
->setInstall(false)
->setDevMode(true)
->setUpdateAllowList([$dependencyName])
->setUpdateAllowTransitiveDependencies(Request::UPDATE_LISTED_WITH_TRANSITIVE_DEPS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,37 +311,8 @@
let(:project_name) { "env_variable" }

context "that hasn't been provided" do
it "raises a MissingEnvironmentVariable error" do
expect { updated_lockfile_content }.to raise_error do |error|
expect(error).to be_a(Dependabot::MissingEnvironmentVariable)
expect(error.message).to eq("Missing environment variable ACF_PRO_KEY")
end
end
end

context "that has been provided" do
let(:updater) do
described_class.new(
dependency_files: files,
dependencies: [dependency],
credentials: [{
"type" => "git_source",
"host" => "github.com",
"username" => "x-access-token",
"password" => "token"
}, {
"type" => "php_environment_variable",
"env-key" => "ACF_PRO_KEY",
"env-value" => "example_key"
}]
)
end

it "runs just fine (we get a 404 here because our key is wrong)" do
expect { updated_lockfile_content }.to raise_error do |error|
expect(error).to be_a(Dependabot::DependencyFileNotResolvable)
expect(error.message).to include("404")
end
it "does not attempt to download and has details of the updated item" do
expect(updated_lockfile_content).to include("\"version\":\"5.9.2\"")
end
end
end
Expand Down Expand Up @@ -544,11 +515,8 @@
}]
end

it "raises a helpful errors" do
expect { updated_lockfile_content }.to raise_error do |error|
expect(error).to be_a Dependabot::PrivateSourceAuthenticationFailure
expect(error.source).to eq("nova.laravel.com")
end
it "does not attempt to download and has details of the updated item" do
expect(updated_lockfile_content).to include("\"version\":\"v2.0.9\"")
end
end
end
Expand Down Expand Up @@ -577,11 +545,8 @@
)
end

it "raises a helpful errors" do
expect { updated_lockfile_content }.to raise_error do |error|
expect(error).to be_a Dependabot::GitDependencyReferenceNotFound
expect(error.dependency).to eq("monolog/monolog")
end
it "does not attempt to install it and has details of the updated item" do
expect(updated_lockfile_content).to include("\"version\":\"v1.6.0\"")
end
end

Expand Down Expand Up @@ -609,12 +574,8 @@
)
end

it "raises a helpful errors" do
expect { updated_lockfile_content }.to raise_error do |error|
expect(error).to be_a Dependabot::GitDependencyReferenceNotFound
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these exceptions potentially need cleaning up? I left as is as it seems it will need a higher discussion as this looks like the scope now increases as there’s potentially areas of code handing nice errors that won’t need handling anymore because installs aren’t attempted

expect(error.dependency).
to eq("monolog/monolog")
end
it "does not attempt to install it and has details of the updated item" do
expect(updated_lockfile_content).to include("\"version\":\"v1.6.0\"")
end
end

Expand Down