diff --git a/src/Enum/ArtifactType.php b/src/Enum/ArtifactType.php index 347bf41..f9651b5 100644 --- a/src/Enum/ArtifactType.php +++ b/src/Enum/ArtifactType.php @@ -7,6 +7,7 @@ enum ArtifactType: string { case Download = 'download'; + case Clone = 'clone'; case Upload = 'upload'; case Write = 'write'; case Read = 'read'; diff --git a/src/Model/Artifact/CloneArtifact.php b/src/Model/Artifact/CloneArtifact.php new file mode 100644 index 0000000..0acf203 --- /dev/null +++ b/src/Model/Artifact/CloneArtifact.php @@ -0,0 +1,67 @@ + $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; + } +} diff --git a/tests/JobsTest.php b/tests/JobsTest.php index 953fb2c..74f6bf2 100644 --- a/tests/JobsTest.php +++ b/tests/JobsTest.php @@ -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; @@ -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'), @@ -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],