Skip to content

Commit

Permalink
Merge pull request #41 from jakzal/composer-install-stable
Browse files Browse the repository at this point in the history
Install tagged versions with box and composer install (if available)
  • Loading branch information
jakzal authored Mar 15, 2018
2 parents 2df3602 + 5d49e78 commit 4336c37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
"box-build": {
"repository": "https://github.com/mmoreram/php-formatter.git",
"phar": "build/php-formatter.phar",
"bin": "/usr/local/bin/php-formatter"
"bin": "/usr/local/bin/php-formatter",
"version": "1fa3d9a3e1c67654f3fe2511bd28fa7c33b59d7e"
}
},
"test": "php-formatter list"
Expand Down
20 changes: 13 additions & 7 deletions tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,30 @@ final class BoxBuildCommand implements Command
private $repository;
private $phar;
private $bin;
private $version;

private function __construct(string $repository, string $phar, string $bin)
private function __construct(string $repository, string $phar, string $bin, ?string $version = null)
{
$this->repository = $repository;
$this->phar = $phar;
$this->bin = $bin;
$this->version = $version;
}

public static function import(array $command): Command
{
\Assert\requireFields(['repository', 'phar', 'bin'], $command, 'BoxBuildCommand');

return new self($command['repository'], $command['phar'], $command['bin']);
return new self($command['repository'], $command['phar'], $command['bin'], $command['version'] ?? null);
}

public function __toString(): string
{
return sprintf(
'cd $HOME && git clone %s && cd $HOME/%s && composer install --no-dev --no-suggest --prefer-dist -n && box build && mv %s %s && chmod +x %s && cd && rm -rf $HOME/%s',
'cd $HOME && git clone %s && cd $HOME/%s && git checkout %s && composer install --no-dev --no-suggest --prefer-dist -n && box build && mv %s %s && chmod +x %s && cd && rm -rf $HOME/%s',
$this->repository,
$this->getTargetDir(),
$this->version ?? '$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)',
$this->phar,
$this->bin,
$this->bin,
Expand All @@ -188,25 +191,28 @@ private function getTargetDir(): string
final class ComposerInstallCommand implements Command
{
private $repository;
private $version;

public function __construct(string $repository)
public function __construct(string $repository, ?string $version = null)
{
$this->repository = $repository;
$this->version = $version;
}

public static function import(array $command): Command
{
\Assert\requireFields(['repository'], $command, 'ComposerInstallCommand');

return new self($command['repository']);
return new self($command['repository'], $command['version'] ?? null);
}

public function __toString(): string
{
return sprintf(
'cd $HOME && git clone %s && cd $HOME/%s && composer install --no-dev --no-suggest --prefer-dist -n',
'cd $HOME && git clone %s && cd $HOME/%s && git checkout %s && composer install --no-dev --no-suggest --prefer-dist -n',
$this->repository,
$this->getTargetDir()
$this->getTargetDir(),
$this->version ?? '$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)'
);
}

Expand Down

0 comments on commit 4336c37

Please sign in to comment.