Skip to content

Commit

Permalink
Updated generated code dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Nov 21, 2023
1 parent d32a31d commit d8f8820
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
42 changes: 38 additions & 4 deletions src/Builder/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,34 @@ public function __construct(
private readonly Node\Expr $runtime
) {}

public function addPipeline(
string $pipelineFilename,
): self {
public function addPipeline(string $code, string $pipelineFilename): self {
$this->jobs[] = fn (Node\Expr $runtime) => new Node\Expr\MethodCall(
var: $runtime,
name: new Node\Identifier('job'),
args: [
new Node\Arg(
new Node\Expr\StaticCall(
new Node\Name\FullyQualified(\Kiboko\Component\Workflow\JobCode::class),

Check failure on line 25 in src/Builder/Workflow.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Workflow\JobCode not found.
new Node\Identifier('fromString'),
[
new Node\Arg(new Node\Scalar\String_($code)),
],
),
),
new Node\Arg(
new Node\Expr\MethodCall(
var: new Node\Expr\Variable('runtime'),
name: 'loadPipeline',
args: [
new Node\Arg(
new Node\Expr\StaticCall(
new Node\Name\FullyQualified(\Kiboko\Component\Workflow\JobCode::class),

Check failure on line 39 in src/Builder/Workflow.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Workflow\JobCode not found.
new Node\Identifier('fromString'),
[
new Node\Arg(new Node\Scalar\String_($code)),
],
),
),
new Node\Arg(
value: new Node\Expr\BinaryOp\Concat(
left: new Node\Scalar\MagicConst\Dir(),
Expand All @@ -47,17 +63,35 @@ public function addPipeline(
return $this;
}

public function addAction(string $pipelineFilename): self
public function addAction(string $code, string $pipelineFilename): self
{
$this->jobs[] = fn (Node\Expr $runtime) => new Node\Expr\MethodCall(
var: $runtime,
name: new Node\Identifier('job'),
args: [
new Node\Arg(
new Node\Expr\StaticCall(
new Node\Name\FullyQualified(\Kiboko\Component\Workflow\JobCode::class),
new Node\Identifier('fromString'),
[
new Node\Arg(new Node\Scalar\String_($code)),
],
),
),
new Node\Arg(
new Node\Expr\MethodCall(
var: new Node\Expr\Variable('runtime'),
name: 'loadAction',
args: [
new Node\Arg(
new Node\Expr\StaticCall(
new Node\Name\FullyQualified(\Kiboko\Component\Workflow\JobCode::class),
new Node\Identifier('fromString'),
[
new Node\Arg(new Node\Scalar\String_($code)),
],
),
),
new Node\Arg(
value: new Node\Expr\BinaryOp\Concat(
left: new Node\Scalar\MagicConst\Dir(),
Expand Down
6 changes: 3 additions & 3 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo
)
);

foreach ($config['workflow']['jobs'] as $job) {
foreach ($config['workflow']['jobs'] as $code => $job) {
if (\array_key_exists('pipeline', $job)) {
$pipeline = $this->compilePipelineJob($job);
$pipelineFilename = sprintf('%s.php', uniqid('pipeline'));
Expand All @@ -293,7 +293,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo
)
);

$workflow->addPipeline($pipelineFilename);
$workflow->addPipeline($code, $pipelineFilename);
} elseif (\array_key_exists('action', $job)) {
$action = $this->compileActionJob($job);
$actionFilename = sprintf('%s.php', uniqid('action'));
Expand All @@ -310,7 +310,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo
)
);

$workflow->addAction($actionFilename);
$workflow->addAction($code, $actionFilename);
} else {
throw new \LogicException('Not implemented');
}
Expand Down

0 comments on commit d8f8820

Please sign in to comment.