From dc6fdc04f628f998acd32a5fd749127b6ee73972 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 8 Jul 2026 18:57:28 +0100 Subject: [PATCH] Resolve template version ranges via vcs 4.4.0 listTags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Templates can pin a version range (e.g. providerVersion "0.3.*"); codeload only accepts a concrete ref, so the jobs template path 404'd on ranges while the executor resolved them with `git ls-remote --tags | tail -1`. Bump utopia-php/vcs to 4.4.0 and use listTags(owner, repo, glob) to resolve the range to the highest matching tag before building the codeload URL. Guarded so a lookup failure degrades to the raw ref rather than failing the request. Known upstream gap: listTags interpolates the access token straight into the Authorization header, so it fatals on an uninitialized adapter — and public templates have no installation/token. GitHub's matching-refs endpoint serves public repos unauthenticated (verified 200), but an empty `Bearer ` is 401, so the adapter must OMIT the header when there is no token. Needs a vcs follow-up; until then range resolution no-ops for public templates (guarded). Co-Authored-By: Claude Opus 4.8 (1M context) --- composer.json | 2 +- .../Http/Deployments/Template/Create.php | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ccf4196614..c623199aeb 100644 --- a/composer.json +++ b/composer.json @@ -94,7 +94,7 @@ "utopia-php/storage": "2.*", "utopia-php/system": "0.10.*", "utopia-php/telemetry": "^0.4", - "utopia-php/vcs": "^4.3.0", + "utopia-php/vcs": "^4.4.0", "utopia-php/websocket": "1.0.*", "matomo/device-detector": "6.4.*", "dragonmantank/cron-expression": "3.4.*", diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index 74e6fbee0f..b0afeceaac 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -207,10 +207,23 @@ class Create extends Base $this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform, $authorization); if ($useJobs) { + // Templates can pin a version range (e.g. "0.3.*"); codeload only + // takes a concrete ref, so resolve the range to the highest matching + // tag (mirrors the executor's `git ls-remote --tags | tail -1`). + $ref = $reference; + if ($type === GitHub::CLONE_TYPE_TAG && \str_contains($reference, '*')) { + try { + $tags = $github->listTags($owner, $repository, $reference); + $ref = \end($tags) ?: $reference; + } catch (\Throwable) { + // Fall back to the raw reference; the build surfaces a bad ref. + } + } + // Public template: pull the source straight from GitHub's codeload // tarball; unarchive strips the "{repo}-{ref}/" wrapper + the rootDirectory. $source = [ - 'url' => "https://codeload.github.com/{$owner}/{$repository}/tar.gz/{$reference}", + 'url' => "https://codeload.github.com/{$owner}/{$repository}/tar.gz/{$ref}", 'subdir' => $rootDirectory, ]; $jobs->create(...Job::build($project, $function, $deployment, $platform, $source));