Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/Enum/ArtifactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
enum ArtifactType: string
{
case Download = 'download';
case Clone = 'clone';
case Upload = 'upload';
case Write = 'write';
case Read = 'read';
Expand Down
67 changes: 67 additions & 0 deletions src/Model/Artifact/CloneArtifact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace OpenRuntimes\Orchestrator\Model\Artifact;

use OpenRuntimes\Orchestrator\Enum\ArtifactType;

/**
* Materializes the tree at a git ref — for repositories whose provider hands
* out no archive URLs. The clone is shallow, single-ref, and tagless, and the
* .git directory is removed after checkout.
*
* The URL must not carry credentials; pass an Authorization header instead,
* so the token never rides a string that errors and logs echo verbatim.
*/
final readonly class CloneArtifact implements Artifact
{
use ArtifactFields;

/**
* @param string $ref Branch name, tag name, or full commit hash; empty means the remote's default branch
* @param string $subdir Keep only this subdirectory of the tree
* @param array<string, string> $headers Sent with every git request, e.g. Authorization
*/
public function __construct(
public string $id,
public string $in,
public string $out,
public string $ref = '',
public string $subdir = '',
public ?string $depends = null,
public ?int $timeoutSeconds = null,
public array $headers = [],
) {}

public function type(): ArtifactType
{
return ArtifactType::Clone;
}

public function toArray(): array
{
$data = $this->base($this->type(), $this->id, $this->depends) + [
'in' => $this->in,
'out' => $this->out,
];

if ($this->ref !== '') {
$data['ref'] = $this->ref;
}

if ($this->subdir !== '') {
$data['subdir'] = $this->subdir;
}

if ($this->timeoutSeconds !== null) {
$data['timeoutSeconds'] = $this->timeoutSeconds;
}

if ($this->headers !== []) {
$data['headers'] = $this->headers;
}

return $data;
}
}
3 changes: 3 additions & 0 deletions tests/JobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OpenRuntimes\Orchestrator\Exception\TimeoutException;
use OpenRuntimes\Orchestrator\Jobs;
use OpenRuntimes\Orchestrator\Model\Artifact\ArchiveArtifact;
use OpenRuntimes\Orchestrator\Model\Artifact\CloneArtifact;
use OpenRuntimes\Orchestrator\Model\Artifact\DownloadArtifact;
use OpenRuntimes\Orchestrator\Model\Artifact\ListArtifact;
use OpenRuntimes\Orchestrator\Model\Artifact\MountArtifact;
Expand Down Expand Up @@ -67,6 +68,7 @@ public function test_create_serializes_artifacts_and_callback(): void
environment: ['A' => 'B'],
artifacts: [
new DownloadArtifact('source', 'https://example.com/source', 'code.tar.gz', headers: ['X-Appwrite-Project' => 'project']),
new CloneArtifact('repo', 'https://git.example.com/acme/app.git', 'src', ref: 'main', subdir: 'packages/web', headers: ['Authorization' => 'Bearer token']),
new UnarchiveArtifact('extract', 'code.tar.gz', 'source', subdir: 'functions/node', strip: true, depends: 'source'),
new ArchiveArtifact('build', 'build-output', 'build.tar', format: ArchiveFormat::Tar, compression: ArchiveCompression::Gzip, level: 6, depends: 'job'),
new ArchiveArtifact('cache', 'stores', 'stores.sqfs', format: ArchiveFormat::Squashfs, compression: ArchiveCompression::Lz4, blockSize: 1048576, depends: 'job'),
Expand Down Expand Up @@ -103,6 +105,7 @@ public function test_create_serializes_artifacts_and_callback(): void
'environment' => ['A' => 'B'],
'artifacts' => [
['id' => 'source', 'type' => 'download', 'in' => 'https://example.com/source', 'out' => 'code.tar.gz', 'headers' => ['X-Appwrite-Project' => 'project']],
['id' => 'repo', 'type' => 'clone', 'in' => 'https://git.example.com/acme/app.git', 'out' => 'src', 'ref' => 'main', 'subdir' => 'packages/web', 'headers' => ['Authorization' => 'Bearer token']],
['id' => 'extract', 'type' => 'unarchive', 'depends' => 'source', 'in' => 'code.tar.gz', 'out' => 'source', 'subdir' => 'functions/node', 'strip' => true],
['id' => 'build', 'type' => 'archive', 'depends' => 'job', 'in' => 'build-output', 'out' => 'build.tar', 'format' => 'tar', 'compression' => 'gzip', 'level' => 6],
['id' => 'cache', 'type' => 'archive', 'depends' => 'job', 'in' => 'stores', 'out' => 'stores.sqfs', 'format' => 'squashfs', 'compression' => 'lz4', 'blockSize' => 1048576],
Expand Down
Loading