Artefact now is aware about its Task; TaskmanArtefact.isSourcesAffected(..) must be used instead of obsolete isSourcesNewer(..); Adding file changes convenience routines;
Publish PHP Package / docker (push) Successful in 5s
Details
Publish PHP Package / docker (push) Successful in 5s
Details
This commit is contained in:
parent
e68ad37770
commit
abe8d938cb
|
@ -4,20 +4,27 @@ use Exception;
|
|||
|
||||
class TaskmanArtefact
|
||||
{
|
||||
private \taskman\TaskmanTask $task;
|
||||
private string $path;
|
||||
private array $sources_fn = array();
|
||||
private array $sources_spec = array();
|
||||
private iterable $sources = array();
|
||||
private array $sources_changed = array();
|
||||
private array $sources_changed_fn = array();
|
||||
private array $sources_newer = array();
|
||||
private array $sources_affected = array();
|
||||
|
||||
function __construct(string $path, array $sources_spec)
|
||||
function __construct(\taskman\TaskmanTask $task, string $path, array $sources_spec)
|
||||
{
|
||||
$this->task = $task;
|
||||
$this->path = $path;
|
||||
$this->sources_spec = $sources_spec;
|
||||
}
|
||||
|
||||
function getTask() : \taskman\TaskmanTask
|
||||
{
|
||||
return $this->task;
|
||||
}
|
||||
|
||||
function getPath() : string
|
||||
{
|
||||
return $this->path;
|
||||
|
@ -70,23 +77,31 @@ class TaskmanArtefact
|
|||
return array();
|
||||
}
|
||||
|
||||
//obsolete
|
||||
function isSourcesNewer(int $idx) : bool
|
||||
{
|
||||
return isset($this->sources_newer[$idx]) && $this->sources_newer[$idx];
|
||||
return $this->isSourcesAffected($idx);
|
||||
}
|
||||
|
||||
function getNewerSourcesIndices() : array
|
||||
function isSourcesAffected(int $idx) : bool
|
||||
{
|
||||
return array_keys($this->sources_newer);
|
||||
return isset($this->sources_affected[$idx]) && $this->sources_affected[$idx];
|
||||
}
|
||||
|
||||
function getAffectedSourcesIndices() : array
|
||||
{
|
||||
return array_keys($this->sources_affected);
|
||||
}
|
||||
|
||||
function isStale() : bool
|
||||
{
|
||||
return count($this->sources_newer) > 0;
|
||||
return count($this->sources_affected) > 0;
|
||||
}
|
||||
|
||||
function initSources(?\taskman\TaskmanFileChanges $file_changes)
|
||||
function initSources()
|
||||
{
|
||||
$file_changes = $this->task->getFileChanges();
|
||||
|
||||
$all_src_specs = $this->getSourcesSpec();
|
||||
//let's process a convenience special case
|
||||
if(count($all_src_specs) > 0 && !is_array($all_src_specs[0]))
|
||||
|
@ -134,14 +149,16 @@ class TaskmanArtefact
|
|||
}
|
||||
}
|
||||
|
||||
function checkNewerSources(?\taskman\TaskmanFileChanges $file_changes) : bool
|
||||
function checkAffectedSources() : bool
|
||||
{
|
||||
$file_changes = $this->task->getFileChanges();
|
||||
|
||||
foreach($this->getSourcesSpec() as $src_idx => $src_spec)
|
||||
{
|
||||
$sources = $file_changes != null ? $this->getChangedSources($src_idx) : $this->getSources($src_idx);
|
||||
if(is_stale($this->getPath(), $sources))
|
||||
{
|
||||
$this->sources_newer[$src_idx] = true;
|
||||
$this->sources_affected[$src_idx] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ class TaskmanTask
|
|||
if(is_array($specs))
|
||||
{
|
||||
foreach($specs as $dst => $src_spec)
|
||||
$artefacts[] = new artefact\TaskmanArtefact($dst, $src_spec);
|
||||
$artefacts[] = new artefact\TaskmanArtefact($this, $dst, $src_spec);
|
||||
}
|
||||
|
||||
return $artefacts;
|
||||
|
@ -266,20 +266,18 @@ class TaskmanTask
|
|||
|
||||
private function _checkIfArtefactsStale() : bool
|
||||
{
|
||||
$file_changes = $this->getFileChanges();
|
||||
|
||||
$stale_found = false;
|
||||
|
||||
foreach($this->getArtefacts() as $artefact)
|
||||
{
|
||||
$artefact->initSources($file_changes);
|
||||
$artefact->initSources();
|
||||
|
||||
if(!$stale_found && $artefact->checkNewerSources($file_changes))
|
||||
if(!$stale_found && $artefact->checkAffectedSources())
|
||||
$stale_found = true;
|
||||
|
||||
if($artefact->isStale())
|
||||
{
|
||||
log(0, "Task '{$this->name}' artefact '{$artefact->getPath()}' (sources at ".implode(',', $artefact->getNewerSourcesIndices()).") is stale\n");
|
||||
log(0, "Task '{$this->name}' artefact '{$artefact->getPath()}' (sources at ".implode(',', $artefact->getAffectedSourcesIndices()).") is stale\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,6 +363,31 @@ class TaskmanFileChanges
|
|||
$this->changed = $changed;
|
||||
}
|
||||
|
||||
function getStatus(string $file) : ?int
|
||||
{
|
||||
return isset($this->changed[$file]) ? $this->changed[$file] : null;
|
||||
}
|
||||
|
||||
function isChanged(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Changed;
|
||||
}
|
||||
|
||||
function isCreated(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Created;
|
||||
}
|
||||
|
||||
function isDeleted(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Deleted;
|
||||
}
|
||||
|
||||
function isRenamed(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Renamed;
|
||||
}
|
||||
|
||||
function isEmpty() : bool
|
||||
{
|
||||
return count($this->changed) == 0;
|
||||
|
|
Loading…
Reference in New Issue