Merge branch '1.8.x' into feat-csv-export

This commit is contained in:
Darshan 2025-10-23 12:20:06 +05:30 committed by GitHub
commit 42c75c43de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 115 additions and 8 deletions

View file

@ -90,6 +90,7 @@ const APP_PLATFORM_CLIENT = 'client';
const APP_PLATFORM_CONSOLE = 'console';
const APP_VCS_GITHUB_USERNAME = 'Appwrite';
const APP_VCS_GITHUB_EMAIL = 'team@appwrite.io';
const APP_VCS_GITHUB_URL = 'https://github.com/TeamAppwrite';
const APP_BRANDED_EMAIL_BASE_TEMPLATE = 'email-base-styled';
// Database Reconnect

View file

@ -5,6 +5,8 @@ namespace Appwrite\Platform\Modules\Compute;
use Appwrite\Event\Build;
use Appwrite\Extend\Exception;
use Appwrite\Platform\Action;
use Appwrite\Platform\Modules\Compute\Validator\Specification as SpecificationValidator;
use Utopia\Config\Config;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\Duplicate;
@ -19,6 +21,37 @@ use Utopia\VCS\Exception\RepositoryNotFound;
class Base extends Action
{
/**
* Get default specification based on plan and available specifications.
*
* @param array $plan The billing plan configuration
* @return string The appropriate default specification
*/
protected function getDefaultSpecification(array $plan): string
{
$specifications = Config::getParam('specifications', []);
if (empty($specifications)) {
return APP_COMPUTE_SPECIFICATION_DEFAULT;
}
$specificationValidator = new SpecificationValidator(
$plan,
$specifications,
System::getEnv('_APP_COMPUTE_CPUS', 0),
System::getEnv('_APP_COMPUTE_MEMORY', 0)
);
$allowedSpecifications = $specificationValidator->getAllowedSpecifications();
// If there is no plan use the highest specification
if (empty($plan)) {
return end($allowedSpecifications) ?? APP_COMPUTE_SPECIFICATION_DEFAULT;
}
// Otherwise, use the lowest specification available in the plan
return $allowedSpecifications[0] ?? APP_COMPUTE_SPECIFICATION_DEFAULT;
}
public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Build $queueForBuilds, Document $template, GitHub $github, bool $activate, string $referenceType = 'branch', string $reference = ''): Document
{
$deploymentId = ID::unique();

View file

@ -93,7 +93,7 @@ class Create extends Base
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function.', true)
->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.', true)
->param('providerRootDirectory', '', new Text(128, 0), 'Path to function code in the linked repo.', true)
->param('specification', APP_COMPUTE_SPECIFICATION_DEFAULT, fn (array $plan) => new Specification(
->param('specification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
$plan,
Config::getParam('specifications', []),
System::getEnv('_APP_COMPUTE_CPUS', 0),

View file

@ -89,7 +89,7 @@ class Update extends Base
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function', true)
->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.', true)
->param('providerRootDirectory', '', new Text(128, 0), 'Path to function code in the linked repo.', true)
->param('specification', APP_COMPUTE_SPECIFICATION_DEFAULT, fn (array $plan) => new Specification(
->param('specification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
$plan,
Config::getParam('specifications', []),
System::getEnv('_APP_COMPUTE_CPUS', 0),

View file

@ -467,11 +467,10 @@ class Builds extends Action
}
$providerCommitHash = \trim($stdout);
$authorUrl = "https://github.com/$cloneOwner";
$deployment->setAttribute('providerCommitHash', $providerCommitHash ?? '');
$deployment->setAttribute('providerCommitAuthorUrl', $authorUrl);
$deployment->setAttribute('providerCommitAuthor', 'Appwrite');
$deployment->setAttribute('providerCommitAuthorUrl', APP_VCS_GITHUB_URL);
$deployment->setAttribute('providerCommitAuthor', APP_VCS_GITHUB_USERNAME);
$deployment->setAttribute('providerCommitMessage', "Create '" . $resource->getAttribute('name', '') . "' function");
$deployment->setAttribute('providerCommitUrl', "https://github.com/$cloneOwner/$cloneRepository/commit/$providerCommitHash");
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);

View file

@ -78,7 +78,7 @@ class Create extends Base
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true)
->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests.', true)
->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true)
->param('specification', APP_COMPUTE_SPECIFICATION_DEFAULT, fn (array $plan) => new Specification(
->param('specification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
$plan,
Config::getParam('specifications', []),
System::getEnv('_APP_COMPUTE_CPUS', 0),

View file

@ -82,7 +82,7 @@ class Update extends Base
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true)
->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests.', true)
->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true)
->param('specification', APP_COMPUTE_SPECIFICATION_DEFAULT, fn (array $plan) => new Specification(
->param('specification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
$plan,
Config::getParam('specifications', []),
System::getEnv('_APP_COMPUTE_CPUS', 0),

View file

@ -435,7 +435,6 @@ class StatsUsage extends Action
return $cmp;
}
unset($this->projects[$sequence]);
// Period ASC
$cmp = strcmp($a['period'], $b['period']);
if ($cmp !== 0) {

View file

@ -0,0 +1,75 @@
<?php
namespace Tests\Unit\Platform\Modules\Compute\Validator;
use Appwrite\Platform\Modules\Compute\Specification as SpecificationConstants;
use Appwrite\Platform\Modules\Compute\Validator\Specification;
use PHPUnit\Framework\TestCase;
use Utopia\Config\Config;
class SpecificationTest extends TestCase
{
private array $specifications;
protected function setUp(): void
{
parent::setUp();
$this->specifications = Config::getParam('specifications', []);
}
public function testGetAllowedSpecificationsNoLimits(): void
{
$validator = new Specification(
plan: [],
specifications: $this->specifications,
maxCpus: 0,
maxMemory: 0
);
$allowed = $validator->getAllowedSpecifications();
$this->assertCount(count($this->specifications), $allowed);
$this->assertEquals(
$this->specifications[array_key_last($this->specifications)]['slug'],
$allowed[array_key_last($allowed)]
);
}
public function testGetAllowedSpecificationsWithMaxCpusAndMemory(): void
{
$validator = new Specification(
plan: [],
specifications: $this->specifications,
maxCpus: 2,
maxMemory: 2048
);
$allowed = $validator->getAllowedSpecifications();
$this->assertCount(4, $allowed);
$this->assertEquals(
SpecificationConstants::S_2VCPU_2GB,
$allowed[array_key_last($allowed)]
);
}
public function testGetAllowedSpecificationsWithPlanLimits(): void
{
$plan = [
'runtimeSpecifications' => [
SpecificationConstants::S_05VCPU_512MB,
SpecificationConstants::S_1VCPU_512MB
]
];
$validator = new Specification(
plan: $plan,
specifications: $this->specifications,
maxCpus: 0,
maxMemory: 0
);
$allowed = $validator->getAllowedSpecifications();
$this->assertCount(2, $allowed);
$this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed);
$this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed);
}
}