Compare commits

..

No commits in common. "master" and "3.4.0" have entirely different histories.

137 changed files with 1311 additions and 1906 deletions

View file

@ -1,32 +0,0 @@
name: Linters
on:
push:
branches:
- master
- galactica
pull_request:
release:
types:
- created
jobs:
linters:
name: Linters
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Composer install
uses: php-actions/composer@v5
with:
command: install
args: --ignore-platform-reqs --no-scripts
version: 2
php_version: 8.0
- name: PHPStan
run: ./vendor/bin/phpstan analyse
- name: PHP Code Sniffer
run: ./vendor/bin/phpcs

View file

@ -1,46 +0,0 @@
name: PHPUnit
on:
push:
branches:
- master
- galactica
pull_request:
release:
types:
- created
jobs:
unit_tests:
name: Unit tests
runs-on: ubuntu-latest
strategy:
matrix:
include:
- php: 8.0
coveralls: true
- php: 8.1
coveralls: false
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Composer install
uses: php-actions/composer@v5
with:
command: install
args: --ignore-platform-reqs --no-scripts
version: 2
php_version: ${{ matrix.php }}
- name: Run tests
env:
XDEBUG_MODE: coverage
run: |
mkdir .logs
./vendor/bin/phpunit --coverage-clover build/logs/coverage.xml
- name: Run Coveralls
if: ${{ matrix.coveralls }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./vendor/bin/php-coveralls -v --coverage_clover build/logs/coverage.xml

3
.gitignore vendored
View file

@ -2,6 +2,3 @@
/build
composer.lock
.mage.yml
.phpunit.result.cache
.phpcs-cache
.logs

View file

@ -1,7 +1,10 @@
language: php
php:
- '8.0'
- '8.1'
- '5.5'
- '5.6'
- '7.0'
- '7.1'
- '7.2'
install:
- composer install

View file

@ -1,15 +1,37 @@
CHANGELOG for 5.X
CHANGELOG for 3.X
=================
* 5.0.0 (2022-04-15)
* v5 series release.
* Refactored for Symfony 6 and PHP 8.
* Added strong types.
* Removed task `composer/self-update`.
* Allow `exec` task to interpolate `%environment%` and `%release%`.
* Added new `sleep` task to day execution [PR#414].
* Added new `symlink` option to define the name of symbolic link on the Release [PR#425].
* Improved Windows compatibility [PR#427].
* Added new `log_limit` option to limit how many logs are kept [Issue#403].
* Add new deploy option `--tag` to specify deploying a specific tag [Issue#192] [Issue#315].
* Added new `scp_flags` option for the `scp` command when SSH flags are incompatible with [Issue#439].
* 3.4.0 (2018-03-29)
* [Issue#380] Throw exception if log_dir is defined but directory doesn't exists
* [BUGFIX] [Issue#405] Malformed ssh command when defining host:port notation
* [Issue#415] Remove timeout on Deploy with Tar or Rsync tasks
* 3.3.0 (2017-07-22)
* [PR#386] Allow to define timeout (default 120s) for symfony/assetic-dump task.
* [PR#392] Allow to define Host Port in Host configuration.
* Allow to specify the binary path of tar on for create and extract
* 3.2.0 (2017-04-14)
* Allow to pre-register Custom Tasks
* [PR#365] New option "from" to define deployment start point
* Allow to define excludes in the global scope.
* Improve code quality, remove duplications on Symfony Tasks.
* Improve code quality, remove duplications on Composer Tasks.
* [PR#364] Allow to define custom timeout to Composer:Install
* 3.1.0 (2017-02-25)
* Add new Exec task to execute arbitrary shell commands
* Add new Composer task, to update phar (composer/self-update)
* [#344] Allow to flag Filesystem tasks
* [PR#346] Add new File System task, to change file's modes (fs/chmod)
* [BUGFIX] [PR#342] Ignore empty exclude lines
* [PR#330] Allow Composer task options to be overwritten at environment level
* [PR#330] Add new method Runtime::getMergedOption to merge ConfigOption and EnvOption
* [Documentation] [PR#333] Improve example config file
* 3.0.1 (2017-01-10)
* [BUGFIX] [#350] [#353] Fix escape issue when commands are sent through SSH
* 3.0.0 (2017-01-31)
* v3 series release

View file

@ -7,7 +7,7 @@ Please read the following guidelines to make your and our work easier and cleane
1. Write clean code with no mess left
2. Contribute the docs when adding configurable new feature
3. Create your pull request from `galactica` branch
3. Create your pull request from `nostromo` branch
4. Ensure your code is fully covered by tests
----------
@ -28,36 +28,39 @@ In order to have the PRs prioritized name them with the following tags.
[FEATURE] Create new PermissionsTask
[HOTFIX] Exception not caught on deployment
```
All Pull Requests must be done to the `galactica` branch, only exception are Hotfixes.
All Pull Requests must be done to the `nostromo` branch, only exception are Hotfixes.
Remember of square brackets when adding issue number. If you'd forget adding them, your whole message will be a comment!
# Developing Magallanes
## Branches
The flow is pretty simple.
In most common cases we work on the `galactica` branch. It's the branch with the main development for the current major version. All Pull Requests must merge with that branch. The `master` branch is used to move the validated code and generate the releases in an orderly fashion, also we could use it for hotfixes.
In most common cases we work on the `nostromo` branch. It's the branch with the main development for the current major version. All Pull Requests must merge with that branch. The `master` branch is used to move the validated code and generate the releases in an orderly fashion, also we could use it for hotfixes.
If you want to use developing branch in your code, simple pass `dev-galactica` to dependency version in your `composer.json` file:
If you want to use developing branch in your code, simple pass `dev-nostromo` to dependency version in your `composer.json` file:
```json
{
"require": {
"andres-montanez/magallanes": "dev-galactica"
"andres-montanez/magallanes": "dev-nostromo"
}
}
```
## Organization and code quality
We use [PSR-12](http://www.php-fig.org/psr/psr-12/) as PHP coding standard.
We use [PSR2](http://www.php-fig.org/psr/psr-2/) as PHP coding standard.
### Tools you can use to ensure your code quality
1. PHPStan `./vendor/bin/phpstan analyse`
2. PHP Code Sniffer `./vendor/bin/phpcs`
1. PHP-CodeSniffer
2. [PHP Mess Detector](https://phpmd.org/)
3. PHP Copy/Paste Detector
4. PHP Dead Code Detector
5. [PHP Coding Standards Fixer](http://cs.sensiolabs.org) with --level=psr2
## Testing and quality
We use PHPUnit to test our code. Most of the project is covered with tests, so if you want your code to be merged push it with proper testing and coverage (at least 95%). To execute the tests with code coverage report:
```bash
./vendor/bin/phpunit --coverage-clover build/logs/coverage.xml --coverage-text
./vendor/bin/php-coveralls -v --coverage_clover build/logs/coverage.xml
```
vendor/bin/phpunit --coverage-clover build/logs/coverage.xml
vendor/bin/coveralls -v --coverage_clover build/logs/coverage.xml
```
Tests structure follow almost the same structure as production code with `Test` suffix in class and file name. Follow the tests already made as guidelines.

View file

@ -1,4 +1,4 @@
Copyright (c) 2011 - 2022 Andrés Montañez
Copyright (c) 2011 - 2017 Andrés Montañez
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated

View file

@ -1,6 +1,6 @@
# Magallanes
![Linters](https://github.com/andres-montanez/Magallanes/actions/workflows/linters.yml/badge.svg?)
![Tests](https://github.com/andres-montanez/Magallanes/actions/workflows/tests.yml/badge.svg?)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/ed0de53a-a12e-459b-9464-34def5907b56/mini.png)](https://insight.sensiolabs.com/projects/ed0de53a-a12e-459b-9464-34def5907b56)
[![Build Status](https://img.shields.io/travis/andres-montanez/Magallanes/master.svg)](https://travis-ci.org/andres-montanez/Magallanes)
[![Coverage Status](https://img.shields.io/coveralls/andres-montanez/Magallanes/master.svg)](https://coveralls.io/github/andres-montanez/Magallanes?branch=master)
[![Code Quality](https://img.shields.io/scrutinizer/g/andres-montanez/Magallanes.svg)](https://scrutinizer-ci.com/g/andres-montanez/Magallanes/)
[![Latest Stable Version](https://img.shields.io/packagist/v/andres-montanez/magallanes.svg?label=stable)](https://packagist.org/packages/andres-montanez/magallanes)
@ -9,21 +9,24 @@
[![License](https://img.shields.io/packagist/l/andres-montanez/magallanes.svg)](https://packagist.org/packages/andres-montanez/magallanes)
### What's Magallanes?
**Magallanes** is a deployment tool for made with PHP for PHP applications; it's quite simple to use and manage. For more information and documentation please visit [magephp.com](https://www.magephp.com/)
**Magallanes** is a deployment tool for made with PHP for PHP applications; it's quite simple to use and manage. For more information and documentation please visit https://magephp.com
### Installing
Simply add the following dependency to your projects composer.json file:
```json
"require-dev": {
"andres-montanez/magallanes": "^5.0"
"require": {
"andres-montanez/magallanes": "^3.0"
}
```
Finally you can use **Magallanes** from the vendor's bin:
```bash
vendor/bin/mage version
$ vendor/bin/mage version
```
### Codename Galactica
Each new mayor version of **Magallanes** will have a codename (like Ubuntu), version 3 was _Nostromo_, version 4 was _Discovery One_, and in the current version it is **_Galactica_**, in homage to the space battleship from the TV series Battlestar Galactica, both the '70s and the mind blowing revision of 2005.
### What happend to version 2?
There is no version 2. I've skipped it and jumpped stright from v1 to v3. This new version of **Magallanes** is quite radical and different from it's successor. The whole application has been rewritten using **_Symfony3 Components_**, so naming it v3 makes a lot of sense.
### Codename Nostromo
Each new mayor version of **Magallanes** will have a codename (like Ubuntu), and in the current version it is **_Nostromo_**, like the spaceship from the movie *Alien (1979)*.

View file

@ -11,8 +11,7 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) {
use Mage\MageApplication;
try {
$file = sprintf('%s/.mage.yml', getcwd());
$mage = new MageApplication($file);
$mage = new MageApplication('.mage.yml');
$mage->run();
} catch (Exception $exception) {
printf('Error: %s' . PHP_EOL, $exception->getMessage());

View file

@ -1,7 +1,7 @@
{
"name": "andres-montanez/magallanes",
"description": "The Deployment Tool for PHP Applications",
"homepage": "https://magephp.com",
"homepage": "http://magephp.com",
"license": "MIT",
"type": "library",
"keywords": ["deployment"],
@ -12,23 +12,18 @@
}
],
"require": {
"php": "^8.0",
"monolog/monolog": "^2.5",
"symfony/console": "^6.0",
"symfony/filesystem": "^6.0",
"symfony/event-dispatcher": "^6.0",
"symfony/finder": "^6.0",
"symfony/yaml": "^6.0",
"symfony/process": "^6.0"
"php": ">=5.5.9",
"monolog/monolog": "^1.0",
"symfony/console": "^3.0",
"symfony/filesystem": "^3.0",
"symfony/event-dispatcher": "^3.0",
"symfony/finder": "^3.0",
"symfony/yaml": "^3.0",
"symfony/process": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.5",
"squizlabs/php_codesniffer": "^3.6",
"php-coveralls/php-coveralls": "^2.5"
},
"suggest": {
"ext-posix": "*"
"phpunit/phpunit": "4.8.*",
"satooshi/php-coveralls": "~1.0"
},
"autoload": {
"psr-4": {
@ -43,8 +38,8 @@
"bin": ["bin/mage"],
"extra": {
"branch-alias": {
"dev-master": "5.0.x-dev",
"dev-galactica": "5.x-dev"
"dev-master": "3.0.x-dev",
"dev-nostromo": "3.x-dev"
}
}
}

View file

@ -1,7 +1,19 @@
version: '2'
services:
php8.0:
container_name: mage-php8.0
build: ./php8.0
php5:
container_name: mage-php5
build: ./php5
volumes:
- ../../:/home/magephp
php7.0:
container_name: mage-php7.0
build: ./php7.0
volumes:
- ../../:/home/magephp
php7.1:
container_name: mage-php7.1
build: ./php7.1
volumes:
- ../../:/home/magephp

View file

@ -0,0 +1,9 @@
FROM ubuntu:14.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y vim curl git unzip
RUN apt-get install -y php5-cli php5-curl
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
WORKDIR /home/magephp

View file

@ -1,11 +1,8 @@
FROM ubuntu:21.10
ENV DEBIAN_FRONTEND=noninteractive \
TZ=UTC
FROM ubuntu:16.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y vim curl git unzip
RUN apt-get install -y php8.0-cli php8.0-zip php8.0-curl php8.0-xml php8.0-mbstring php8.0-xdebug
RUN apt-get install -y php7.0-cli php-zip php7.0-curl php7.0-xml
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer

View file

@ -0,0 +1,9 @@
FROM ubuntu:17.10
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y vim curl git unzip
RUN apt-get install -y php7.1-cli php-zip php7.1-curl php7.1-xml
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
WORKDIR /home/magephp

View file

@ -7,8 +7,10 @@ magephp:
host_path: /var/www/test
releases: 4
exclude:
- var/cache
- var/log
- vendor
- app/cache
- app/log
- web/app_dev.php
hosts:
- webserver1
- webserver2
@ -16,7 +18,7 @@ magephp:
pre-deploy:
- git/update
- composer/install
- composer/dump-autoload
- composer/generate-autoload
on-deploy:
- symfony/cache-warmup: { env: 'prod' }
- symfony/assets-install: { env: 'prod' }

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<rule ref="PSR12"/>
<file>src/</file>
</ruleset>

View file

@ -1,4 +0,0 @@
parameters:
level: 6
paths:
- src

View file

@ -1,28 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory>./tests/</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="intl.default_locale" value="en"/>
<ini name="intl.error_level" value="0"/>
<ini name="memory_limit" value="-1"/>
</php>
<testsuites>
<testsuite name="Magallanes Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>benchmark</group>
<group>intl-data</group>
</exclude>
</groups>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="intl.default_locale" value="en" />
<ini name="intl.error_level" value="0" />
<ini name="memory_limit" value="-1" />
</php>
<testsuites>
<testsuite name="Magallanes Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>benchmark</group>
<group>intl-data</group>
</exclude>
</groups>
<filter>
<whitelist>
<directory>./src/</directory>
<exclude>
<directory>./tests/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -24,30 +23,46 @@ use Symfony\Component\Console\Command\Command;
*/
abstract class AbstractCommand extends Command
{
protected int $statusCode = 0;
protected Runtime $runtime;
/**
* @var int
*/
protected $statusCode = 0;
/**
* @var Runtime Current Runtime instance
*/
protected $runtime;
/**
* Set the Runtime configuration
*
* @param Runtime $runtime Runtime container
* @return AbstractCommand
*/
public function setRuntime(Runtime $runtime): self
public function setRuntime(Runtime $runtime)
{
$this->runtime = $runtime;
return $this;
}
/**
* Logs a message
*
* @param string $message
* @param string $level
*/
public function log(string $message, string $level = LogLevel::DEBUG): void
public function log($message, $level = LogLevel::DEBUG)
{
$this->runtime->log($message, $level);
}
/**
* Get the Human friendly Stage name
*
* @return string
*/
protected function getStageName(): string
protected function getStageName()
{
$utils = new Utils();
return $utils->getStageName($this->runtime->getStage());
@ -56,7 +71,7 @@ abstract class AbstractCommand extends Command
/**
* Requires the configuration to be loaded
*/
protected function requireConfig(): void
protected function requireConfig()
{
$app = $this->getApplication();
if ($app instanceof MageApplication) {

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -25,17 +24,22 @@ class DumpCommand extends AbstractCommand
/**
* Configure the Command
*/
protected function configure(): void
protected function configure()
{
$this
->setName('config:dump')
->setDescription('Dumps the Magallanes configuration');
->setDescription('Dumps the Magallanes configuration')
;
}
/**
* Execute the Command
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|mixed
*/
protected function execute(InputInterface $input, OutputInterface $output): int
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
@ -47,6 +51,6 @@ class DumpCommand extends AbstractCommand
$output->writeln('');
$output->writeln('Finished <fg=blue>Magallanes</>');
return self::SUCCESS;
return 0;
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -26,17 +25,22 @@ class EnvironmentsCommand extends AbstractCommand
/**
* Configure the Command
*/
protected function configure(): void
protected function configure()
{
$this
->setName('config:environments')
->setDescription('List all Magallanes configured Environments');
->setDescription('List all Magallanes configured Environments')
;
}
/**
* Execute the Command
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|mixed
*/
protected function execute(InputInterface $input, OutputInterface $output): int
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
@ -62,6 +66,6 @@ class EnvironmentsCommand extends AbstractCommand
$output->writeln('');
$output->writeln('Finished <fg=blue>Magallanes</>');
return self::SUCCESS;
return 0;
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -32,37 +31,32 @@ use Mage\Command\AbstractCommand;
*/
class DeployCommand extends AbstractCommand
{
protected TaskFactory $taskFactory;
/**
* @var TaskFactory
*/
protected $taskFactory;
/**
* Configure the Command
*/
protected function configure(): void
protected function configure()
{
$this
->setName('deploy')
->setDescription('Deploy code to hosts')
->addArgument('environment', InputArgument::REQUIRED, 'Name of the environment to deploy to.')
->addOption(
'branch',
null,
InputOption::VALUE_REQUIRED,
'Force to switch to a branch other than the one defined.',
false
)
->addOption(
'tag',
null,
InputOption::VALUE_REQUIRED,
'Deploys a specific tag.',
false
);
->addArgument('environment', InputArgument::REQUIRED, 'Name of the environment to deploy to')
->addOption('branch', null, InputOption::VALUE_REQUIRED, 'Force to switch to a branch other than the one defined', false)
;
}
/**
* Execute the Command
*
* @param InputInterface $input
* @param OutputInterface $output
* @return integer
*/
protected function execute(InputInterface $input, OutputInterface $output): int
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
@ -90,25 +84,14 @@ class DeployCommand extends AbstractCommand
$output->writeln(sprintf(' Strategy: <fg=green>%s</>', $strategy->getName()));
if (($input->getOption('branch') !== false) && ($input->getOption('tag') !== false)) {
throw new RuntimeException('Branch and Tag options are mutually exclusive.');
}
if ($input->getOption('branch') !== false) {
$this->runtime->setEnvOption('branch', $input->getOption('branch'));
}
if ($input->getOption('tag') !== false) {
$this->runtime->setEnvOption('branch', false);
$this->runtime->setEnvOption('tag', $input->getOption('tag'));
$output->writeln(sprintf(' Tag: <fg=green>%s</>', $this->runtime->getEnvOption('tag')));
}
if ($this->runtime->getEnvOption('branch', false)) {
$output->writeln(sprintf(' Branch: <fg=green>%s</>', $this->runtime->getEnvOption('branch')));
}
$output->writeln('');
$this->runDeployment($output, $strategy);
} catch (RuntimeException $exception) {
@ -120,15 +103,17 @@ class DeployCommand extends AbstractCommand
$output->writeln('Finished <fg=blue>Magallanes</>');
return intval($this->statusCode);
return $this->statusCode;
}
/**
* Run the Deployment Process
*
* @param OutputInterface $output
* @param StrategyInterface $strategy
* @throws RuntimeException
*/
protected function runDeployment(OutputInterface $output, StrategyInterface $strategy): void
protected function runDeployment(OutputInterface $output, StrategyInterface $strategy)
{
// Run "Pre Deploy" Tasks
$this->runtime->setStage(Runtime::PRE_DEPLOY);
@ -155,20 +140,16 @@ class DeployCommand extends AbstractCommand
}
}
/**
* @param string[] $tasks
*/
protected function runOnHosts(OutputInterface $output, array $tasks): void
protected function runOnHosts(OutputInterface $output, $tasks)
{
$hosts = $this->runtime->getEnvOption('hosts');
if (!is_array($hosts) && !$hosts instanceof \Countable) {
$hosts = [];
}
if (count($hosts) === 0) {
if (count($hosts) == 0) {
$output->writeln(sprintf(' No hosts defined, skipping %s tasks', $this->getStageName()));
$output->writeln('');
return;
return true;
}
foreach ($hosts as $host) {
@ -184,27 +165,21 @@ class DeployCommand extends AbstractCommand
/**
* Runs all the tasks
*
* @param string[] $tasks
* @param OutputInterface $output
* @param $tasks
* @return bool
* @throws RuntimeException
*/
protected function runTasks(OutputInterface $output, array $tasks): bool
protected function runTasks(OutputInterface $output, $tasks)
{
if (count($tasks) == 0) {
$output->writeln(
sprintf(' No tasks defined for <fg=black;options=bold>%s</> stage', $this->getStageName())
);
$output->writeln(sprintf(' No tasks defined for <fg=black;options=bold>%s</> stage', $this->getStageName()));
$output->writeln('');
return true;
}
if ($this->runtime->getHostName() !== null) {
$output->writeln(
sprintf(
' Starting <fg=black;options=bold>%s</> tasks on host <fg=black;options=bold>%s</>:',
$this->getStageName(),
$this->runtime->getHostName()
)
);
$output->writeln(sprintf(' Starting <fg=black;options=bold>%s</> tasks on host <fg=black;options=bold>%s</>:', $this->getStageName(), $this->runtime->getHostName()));
} else {
$output->writeln(sprintf(' Starting <fg=black;options=bold>%s</> tasks:', $this->getStageName()));
}
@ -213,6 +188,7 @@ class DeployCommand extends AbstractCommand
$succeededTasks = 0;
foreach ($tasks as $taskName) {
/** @var AbstractTask $task */
$task = $this->taskFactory->get($taskName);
$output->write(sprintf(' Running <fg=magenta>%s</> ... ', $task->getDescription()));
$this->log(sprintf('Running task %s (%s)', $task->getDescription(), $task->getName()));
@ -220,48 +196,25 @@ class DeployCommand extends AbstractCommand
if ($this->runtime->inRollback() && !$task instanceof ExecuteOnRollbackInterface) {
$succeededTasks++;
$output->writeln('<fg=yellow>SKIPPED</>');
$this->log(
sprintf(
'Task %s (%s) finished with SKIPPED, it was in a Rollback',
$task->getDescription(),
$task->getName()
)
);
$this->log(sprintf('Task %s (%s) finished with SKIPPED, it was in a Rollback', $task->getDescription(), $task->getName()));
} else {
try {
if ($task->execute()) {
$succeededTasks++;
$output->writeln('<fg=green>OK</>');
$this->log(
sprintf('Task %s (%s) finished with OK', $task->getDescription(), $task->getName())
);
$this->log(sprintf('Task %s (%s) finished with OK', $task->getDescription(), $task->getName()));
} else {
$output->writeln('<fg=red>FAIL</>');
$this->statusCode = 180;
$this->log(
sprintf('Task %s (%s) finished with FAIL', $task->getDescription(), $task->getName())
);
$this->log(sprintf('Task %s (%s) finished with FAIL', $task->getDescription(), $task->getName()));
}
} catch (SkipException $exception) {
$succeededTasks++;
$output->writeln('<fg=yellow>SKIPPED</>');
$this->log(
sprintf(
'Task %s (%s) finished with SKIPPED, thrown SkipException',
$task->getDescription(),
$task->getName()
)
);
$this->log(sprintf('Task %s (%s) finished with SKIPPED, thrown SkipException', $task->getDescription(), $task->getName()));
} catch (ErrorException $exception) {
$output->writeln(sprintf('<fg=red>ERROR</> [%s]', $exception->getTrimmedMessage()));
$this->log(
sprintf(
'Task %s (%s) finished with FAIL, with Error "%s"',
$task->getDescription(),
$task->getName(),
$exception->getMessage()
)
);
$this->log(sprintf('Task %s (%s) finished with FAIL, with Error "%s"', $task->getDescription(), $task->getName(), $exception->getMessage()));
$this->statusCode = 190;
}
}
@ -276,15 +229,7 @@ class DeployCommand extends AbstractCommand
$alertColor = 'green';
}
$output->writeln(
sprintf(
' Finished <fg=%s>%d/%d</> tasks for <fg=black;options=bold>%s</>.',
$alertColor,
$succeededTasks,
$totalTasks,
$this->getStageName()
)
);
$output->writeln(sprintf(' Finished <fg=%s>%d/%d</> tasks for <fg=black;options=bold>%s</>.', $alertColor, $succeededTasks, $totalTasks, $this->getStageName()));
$output->writeln('');
return ($succeededTasks == $totalTasks);
@ -293,11 +238,8 @@ class DeployCommand extends AbstractCommand
/**
* Exception for halting the the current process
*/
protected function getException(): RuntimeException
protected function getException()
{
return new RuntimeException(
sprintf('Stage "%s" did not finished successfully, halting command.', $this->getStageName()),
50
);
return new RuntimeException(sprintf('Stage "%s" did not finished successfully, halting command.', $this->getStageName()), 50);
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -26,21 +25,31 @@ use Mage\Command\AbstractCommand;
*/
class ListCommand extends AbstractCommand
{
/**
* @var int
*/
protected $statusCode = 0;
/**
* Configure the Command
*/
protected function configure(): void
protected function configure()
{
$this
->setName('releases:list')
->setDescription('List the releases on an environment')
->addArgument('environment', InputArgument::REQUIRED, 'Name of the environment to deploy to');
->addArgument('environment', InputArgument::REQUIRED, 'Name of the environment to deploy to')
;
}
/**
* Execute the Command
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|mixed
*/
protected function execute(InputInterface $input, OutputInterface $output): int
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
@ -88,14 +97,12 @@ class ListCommand extends AbstractCommand
$releases = [];
if (trim($process->getOutput()) != '') {
$releases = explode("\n", trim($process->getOutput()));
$releases = explode(PHP_EOL, trim($process->getOutput()));
rsort($releases);
}
if (count($releases) == 0) {
$output->writeln(
sprintf(' No releases available on host <fg=black;options=bold>%s</>:', $host)
);
$output->writeln(sprintf(' No releases available on host <fg=black;options=bold>%s</>:', $host));
} else {
// Get Current Release
$cmdCurrentRelease = sprintf('readlink -f %s/current', $hostPath);
@ -103,10 +110,7 @@ class ListCommand extends AbstractCommand
/** @var Process $process */
$process = $this->runtime->runRemoteCommand($cmdCurrentRelease, false);
if (!$process->isSuccessful()) {
throw new RuntimeException(
sprintf('Unable to retrieve current release from host "%s"', $host),
85
);
throw new RuntimeException(sprintf('Unable to retrieve current release from host "%s"', $host), 85);
}
$currentReleaseId = explode('/', trim($process->getOutput()));
@ -117,8 +121,7 @@ class ListCommand extends AbstractCommand
foreach ($releases as $releaseId) {
$releaseDate = $utils->getReleaseDate($releaseId);
$output->write(sprintf(
' Release ID: <fg=magenta>%s</> - Date: <fg=black;options=bold>%s</> [%s]',
$output->write(sprintf(' Release ID: <fg=magenta>%s</> - Date: <fg=black;options=bold>%s</> [%s]',
$releaseId,
$releaseDate->format('Y-m-d H:i:s'),
$utils->getTimeDiff($releaseDate)
@ -143,6 +146,6 @@ class ListCommand extends AbstractCommand
$output->writeln('Finished <fg=blue>Magallanes</>');
return intval($this->statusCode);
return $this->statusCode;
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -26,22 +25,32 @@ use Mage\Command\BuiltIn\DeployCommand;
*/
class RollbackCommand extends DeployCommand
{
/**
* @var int
*/
protected $statusCode = 0;
/**
* Configure the Command
*/
protected function configure(): void
protected function configure()
{
$this
->setName('releases:rollback')
->setDescription('Rollback to a release on an environment')
->addArgument('environment', InputArgument::REQUIRED, 'Name of the environment to deploy to')
->addArgument('release', InputArgument::REQUIRED, 'The ID or the Index of the release to rollback to');
->addArgument('release', InputArgument::REQUIRED, 'The ID or the Index of the release to rollback to')
;
}
/**
* Execute the Command
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|mixed
*/
protected function execute(InputInterface $input, OutputInterface $output): int
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
@ -59,14 +68,11 @@ class RollbackCommand extends DeployCommand
}
$releaseToRollback = $input->getArgument('release');
if ($this->checkReleaseAvailability($releaseToRollback) === false) {
throw new RuntimeException(
sprintf('Release "%s" is not available on all hosts', $releaseToRollback),
72
);
if (($releaseId = $this->checkReleaseAvailability($releaseToRollback)) === false) {
throw new RuntimeException(sprintf('Release "%s" is not available on all hosts', $releaseToRollback), 72);
}
$this->runtime->setReleaseId($releaseToRollback)->setRollback(true);
$this->runtime->setReleaseId($releaseId)->setRollback(true);
$output->writeln(sprintf(' Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
$this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));
@ -89,13 +95,16 @@ class RollbackCommand extends DeployCommand
$output->writeln('Finished <fg=blue>Magallanes</>');
return intval($this->statusCode);
return $this->statusCode;
}
/**
* Check if the provided Release ID is available in all hosts
*
* @param string $releaseToRollback Release ID
* @return bool
*/
protected function checkReleaseAvailability(string $releaseToRollback): bool
protected function checkReleaseAvailability($releaseToRollback)
{
$hosts = $this->runtime->getEnvOption('hosts');
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
@ -111,7 +120,7 @@ class RollbackCommand extends DeployCommand
/** @var Process $process */
$process = $this->runtime->runRemoteCommand($cmdListReleases, false);
if ($process->isSuccessful()) {
$releases = explode("\n", trim($process->getOutput()));
$releases = explode(PHP_EOL, trim($process->getOutput()));
rsort($releases);
}
@ -123,7 +132,7 @@ class RollbackCommand extends DeployCommand
}
if ($availableInHosts === count($hosts)) {
return (bool) $releaseToRollback;
return $releaseToRollback;
}
return false;

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -26,20 +25,25 @@ class VersionCommand extends AbstractCommand
/**
* Configure the Command
*/
protected function configure(): void
protected function configure()
{
$this
->setName('version')
->setDescription('Get the version of Magallanes');
->setDescription('Get the version of Magallanes')
;
}
/**
* Executes the Command
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('Magallanes v%s [%s]', Mage::VERSION, Mage::CODENAME));
return self::SUCCESS;
return 0;
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -21,28 +20,27 @@ use Mage\Runtime\Runtime;
*/
class ReleasesStrategy implements StrategyInterface
{
protected Runtime $runtime;
/**
* @var Runtime
*/
protected $runtime;
public function getName(): string
public function getName()
{
return 'Releases';
}
public function setRuntime(Runtime $runtime): void
public function setRuntime(Runtime $runtime)
{
$this->runtime = $runtime;
}
public function getPreDeployTasks(): array
public function getPreDeployTasks()
{
$this->checkStage(Runtime::PRE_DEPLOY);
$tasks = $this->runtime->getTasks();
if (
($this->runtime->getBranch() || $this->runtime->getTag()) &&
!$this->runtime->inRollback() &&
!in_array('git/change-branch', $tasks)
) {
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
array_unshift($tasks, 'git/change-branch');
}
@ -53,7 +51,7 @@ class ReleasesStrategy implements StrategyInterface
return $tasks;
}
public function getOnDeployTasks(): array
public function getOnDeployTasks()
{
$this->checkStage(Runtime::ON_DEPLOY);
$tasks = $this->runtime->getTasks();
@ -69,7 +67,7 @@ class ReleasesStrategy implements StrategyInterface
return $tasks;
}
public function getOnReleaseTasks(): array
public function getOnReleaseTasks()
{
$this->checkStage(Runtime::ON_RELEASE);
$tasks = $this->runtime->getTasks();
@ -81,7 +79,7 @@ class ReleasesStrategy implements StrategyInterface
return $tasks;
}
public function getPostReleaseTasks(): array
public function getPostReleaseTasks()
{
$this->checkStage(Runtime::POST_RELEASE);
$tasks = $this->runtime->getTasks();
@ -93,37 +91,32 @@ class ReleasesStrategy implements StrategyInterface
return $tasks;
}
public function getPostDeployTasks(): array
public function getPostDeployTasks()
{
$this->checkStage(Runtime::POST_DEPLOY);
$tasks = $this->runtime->getTasks();
if (
($this->runtime->getBranch() || $this->runtime->getTag()) &&
!$this->runtime->inRollback() &&
!in_array('git/change-branch', $tasks)
) {
array_unshift($tasks, 'git/change-branch');
}
if (!$this->runtime->inRollback() && !in_array('deploy/tar/cleanup', $tasks)) {
array_unshift($tasks, 'deploy/tar/cleanup');
}
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
array_push($tasks, 'git/change-branch');
}
return $tasks;
}
/**
* Check the runtime stage is correct
*
* @param $stage
* @throws RuntimeException
*/
private function checkStage(string $stage): void
private function checkStage($stage)
{
if ($this->runtime->getStage() !== $stage) {
throw new RuntimeException(
sprintf('Invalid stage, got "%s" but expected "%s"', $this->runtime->getStage(), $stage)
);
throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage));
}
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -21,35 +20,34 @@ use Mage\Runtime\Runtime;
*/
class RsyncStrategy implements StrategyInterface
{
protected Runtime $runtime;
/**
* @var Runtime
*/
protected $runtime;
public function getName(): string
public function getName()
{
return 'Rsync';
}
public function setRuntime(Runtime $runtime): void
public function setRuntime(Runtime $runtime)
{
$this->runtime = $runtime;
}
public function getPreDeployTasks(): array
public function getPreDeployTasks()
{
$this->checkStage(Runtime::PRE_DEPLOY);
$tasks = $this->runtime->getTasks();
if (
($this->runtime->getBranch() || $this->runtime->getTag()) &&
!$this->runtime->inRollback() &&
!in_array('git/change-branch', $tasks)
) {
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
array_unshift($tasks, 'git/change-branch');
}
return $tasks;
}
public function getOnDeployTasks(): array
public function getOnDeployTasks()
{
$this->checkStage(Runtime::ON_DEPLOY);
$tasks = $this->runtime->getTasks();
@ -61,27 +59,22 @@ class RsyncStrategy implements StrategyInterface
return $tasks;
}
public function getOnReleaseTasks(): array
public function getOnReleaseTasks()
{
return [];
}
public function getPostReleaseTasks(): array
public function getPostReleaseTasks()
{
return [];
}
public function getPostDeployTasks(): array
public function getPostDeployTasks()
{
$this->checkStage(Runtime::POST_DEPLOY);
$tasks = $this->runtime->getTasks();
if (
($this->runtime->getBranch() ||
$this->runtime->getTag()) &&
!$this->runtime->inRollback() &&
!in_array('git/change-branch', $tasks)
) {
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
array_push($tasks, 'git/change-branch');
}
@ -91,14 +84,13 @@ class RsyncStrategy implements StrategyInterface
/**
* Check the runtime stage is correct
*
* @param $stage
* @throws RuntimeException
*/
private function checkStage(string $stage): void
private function checkStage($stage)
{
if ($this->runtime->getStage() !== $stage) {
throw new RuntimeException(
sprintf('Invalid stage, got "%s" but expected "%s"', $this->runtime->getStage(), $stage)
);
throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage));
}
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,32 +19,17 @@ use Mage\Runtime\Runtime;
*/
interface StrategyInterface
{
public function getName(): string;
public function getName();
public function setRuntime(Runtime $runtime): void;
public function setRuntime(Runtime $runtime);
/**
* @return string[]
*/
public function getPreDeployTasks(): array;
public function getPreDeployTasks();
/**
* @return string[]
*/
public function getOnDeployTasks(): array;
public function getOnDeployTasks();
/**
* @return string[]
*/
public function getOnReleaseTasks(): array;
public function getOnReleaseTasks();
/**
* @return string[]
*/
public function getPostReleaseTasks(): array;
public function getPostReleaseTasks();
/**
* @return string[]
*/
public function getPostDeployTasks(): array;
public function getPostDeployTasks();
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -18,6 +17,6 @@ namespace Mage;
*/
class Mage
{
public const VERSION = '5.0.0';
public const CODENAME = 'Galactica';
const VERSION = '3.4.0';
const CODENAME = 'Nostromo';
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -18,13 +17,13 @@ use Symfony\Component\Finder\SplFileInfo;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Application;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Exception\ParseException;
use ReflectionClass;
use Mage\Runtime\Exception\RuntimeException;
use Symfony\Component\Filesystem\Filesystem;
/**
* The Console Application for launching the Mage command in a standalone instance
@ -33,13 +32,13 @@ use Symfony\Component\Filesystem\Filesystem;
*/
class MageApplication extends Application
{
protected Runtime $runtime;
protected string $file;
protected $runtime;
protected $file;
/**
* @param string $file The YAML file from which to read the configuration
*/
public function __construct(string $file)
public function __construct($file)
{
parent::__construct('Magallanes', Mage::VERSION);
@ -47,14 +46,12 @@ class MageApplication extends Application
$dispatcher = new EventDispatcher();
$this->setDispatcher($dispatcher);
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) {
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
$output = $event->getOutput();
$command = $event->getCommand();
$output->writeln(
sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName())
);
$output->writeln(sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName()));
$exitCode = $event->getExitCode();
$event->setError(new \LogicException('Caught exception', $exitCode, $event->getError()));
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
});
$this->runtime = $this->instantiateRuntime();
@ -66,7 +63,7 @@ class MageApplication extends Application
*
* @throws RuntimeException
*/
public function configure(): void
public function configure()
{
if (!file_exists($this->file) || !is_readable($this->file)) {
throw new RuntimeException(sprintf('The file "%s" does not exists or is not readable.', $this->file));
@ -81,25 +78,15 @@ class MageApplication extends Application
if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
$logger = null;
if (
array_key_exists('log_dir', $config['magephp']) &&
file_exists($config['magephp']['log_dir']) && is_dir($config['magephp']['log_dir'])
) {
if (array_key_exists('log_dir', $config['magephp']) && file_exists($config['magephp']['log_dir']) && is_dir($config['magephp']['log_dir'])) {
$logfile = sprintf('%s/%s.log', $config['magephp']['log_dir'], date('Ymd_His'));
$config['magephp']['log_file'] = $logfile;
$logger = new Logger('magephp');
$logger->pushHandler(new StreamHandler($logfile));
$logLimit = isset($config['magephp']['log_limit']) ? intval($config['magephp']['log_limit']) : 30;
$this->clearOldLogs($config['magephp']['log_dir'], $logLimit);
} elseif (array_key_exists('log_dir', $config['magephp']) && !is_dir($config['magephp']['log_dir'])) {
throw new RuntimeException(
sprintf(
'The configured log_dir "%s" does not exists or is not a directory.',
$config['magephp']['log_dir']
)
);
throw new RuntimeException(sprintf('The configured log_dir "%s" does not exists or is not a directory.', $config['magephp']['log_dir']));
}
$this->runtime->setConfiguration($config['magephp']);
@ -107,33 +94,13 @@ class MageApplication extends Application
return;
}
throw new RuntimeException(
sprintf('The file "%s" does not have a valid Magallanes configuration.', $this->file)
);
}
protected function clearOldLogs(string $logDir, int $logLimit): void
{
$filesystem = new Filesystem();
$finder = new Finder();
$finder
->files()
->followLinks()
->in($logDir)
->name('*.log')
->sortByModifiedTime()
->reverseSorting();
$logs = iterator_to_array($finder);
$logsToRemove = array_slice($logs, $logLimit - 1);
$filesystem->remove($logsToRemove);
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $this->file));
}
/**
* Loads the BuiltIn Commands
*/
protected function loadBuiltInCommands(): void
protected function loadBuiltInCommands()
{
$finder = new Finder();
$finder->files()->in(__DIR__ . '/Command/BuiltIn')->name('*Command.php');
@ -142,7 +109,7 @@ class MageApplication extends Application
foreach ($finder as $file) {
$class = substr('\\Mage\\Command\\BuiltIn\\' . str_replace('/', '\\', $file->getRelativePathname()), 0, -4);
if (class_exists($class)) {
$reflex = new \ReflectionClass($class);
$reflex = new ReflectionClass($class);
if ($reflex->isInstantiable()) {
$command = new $class();
if ($command instanceof AbstractCommand) {
@ -156,16 +123,20 @@ class MageApplication extends Application
/**
* Gets the Runtime instance to use
*
* @return Runtime
*/
protected function instantiateRuntime(): Runtime
protected function instantiateRuntime()
{
return new Runtime();
}
/**
* Get the Runtime instance
*
* @return Runtime
*/
public function getRuntime(): Runtime
public function getRuntime()
{
return $this->runtime;
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -11,11 +10,13 @@
namespace Mage\Runtime\Exception;
use Exception;
/**
* An Error occurred while running
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class RuntimeException extends \Exception
class RuntimeException extends Exception
{
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -18,7 +17,6 @@ use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\Process\Process;
use Mage\Runtime\Exception\RuntimeException;
use Mage\Task\AbstractTask;
/**
* Runtime is a container of all run in time configuration, stages of progress, hosts being deployed, etc.
@ -27,63 +25,58 @@ use Mage\Task\AbstractTask;
*/
class Runtime
{
public const PRE_DEPLOY = 'pre-deploy';
public const ON_DEPLOY = 'on-deploy';
public const POST_DEPLOY = 'post-deploy';
public const ON_RELEASE = 'on-release';
public const POST_RELEASE = 'post-release';
const PRE_DEPLOY = 'pre-deploy';
const ON_DEPLOY = 'on-deploy';
const POST_DEPLOY = 'post-deploy';
const ON_RELEASE = 'on-release';
const POST_RELEASE = 'post-release';
/**
* @var array<string, mixed> Magallanes configuration
* @var array Magallanes configuration
*/
protected array $configuration = [];
protected $configuration = [];
/**
* @var string|null Environment being deployed
*/
protected ?string $environment = null;
protected $environment;
/**
* @var string|null Stage of Deployment
* @var string Stage of Deployment
*/
protected ?string $stage = null;
protected $stage;
/**
* @var string|null The host being deployed to
*/
protected ?string $workingHost = null;
protected $workingHost = null;
/**
* @var string|null The Release ID
*/
protected ?string $releaseId = null;
protected $releaseId = null;
/**
* @var array<string, string> Hold a bag of variables for sharing information between tasks, if needed
* @var array Hold a bag of variables for sharing information between tasks, if needed
*/
protected $vars = [];
protected ?LoggerInterface $logger = null;
/**
* @var LoggerInterface|null The logger instance
*/
protected $logger;
/**
* @var bool Indicates if a Rollback operation is in progress
*/
protected bool $rollback = false;
public function isWindows(): bool
{
return stripos(PHP_OS, 'WIN') === 0;
}
public function hasPosix(): bool
{
return function_exists('posix_getpwuid');
}
protected $rollback = false;
/**
* Generate the Release ID
*
* @return Runtime
*/
public function generateReleaseId(): self
public function generateReleaseId()
{
$this->setReleaseId(date('YmdHis'));
return $this;
@ -91,8 +84,11 @@ class Runtime
/**
* Sets the Release ID
*
* @param string $releaseId Release ID
* @return Runtime
*/
public function setReleaseId(string $releaseId): self
public function setReleaseId($releaseId)
{
$this->releaseId = $releaseId;
return $this;
@ -100,16 +96,21 @@ class Runtime
/**
* Retrieve the current Release ID
*
* @return null|string Release ID
*/
public function getReleaseId(): ?string
public function getReleaseId()
{
return $this->releaseId;
}
/**
* Sets the Runtime in Rollback mode On or Off
*
* @param bool $inRollback
* @return Runtime
*/
public function setRollback(bool $inRollback): self
public function setRollback($inRollback)
{
$this->rollback = $inRollback;
return $this;
@ -117,25 +118,35 @@ class Runtime
/**
* Indicates if Runtime is in rollback
*
* @return bool
*/
public function inRollback(): bool
public function inRollback()
{
return $this->rollback;
}
/**
* Sets a value in the Vars bag
*
* @param string $key Variable name
* @param string $value Variable value
* @return Runtime
*/
public function setVar(string $key, string $value): self
public function setVar($key, $value)
{
$this->vars[$key] = $value;
return $this;
}
/**
* Retrieve a value from the Vars bag, or a default (null) if not set
* Retrieve a value from the Vars bag
*
* @param string $key Variable name
* @param mixed $default Variable default value, returned if not found
* @return string
*/
public function getVar(string $key, mixed $default = null): ?string
public function getVar($key, $default = null)
{
if (array_key_exists($key, $this->vars)) {
return $this->vars[$key];
@ -146,8 +157,11 @@ class Runtime
/**
* Sets the Logger instance
*
* @param LoggerInterface $logger Logger instance
* @return Runtime
*/
public function setLogger(?LoggerInterface $logger = null): self
public function setLogger(LoggerInterface $logger = null)
{
$this->logger = $logger;
return $this;
@ -156,9 +170,10 @@ class Runtime
/**
* Sets the Magallanes Configuration to the Runtime
*
* @param array<string, mixed> $configuration
* @param array $configuration Configuration
* @return Runtime
*/
public function setConfiguration(array $configuration): self
public function setConfiguration($configuration)
{
$this->configuration = $configuration;
return $this;
@ -167,17 +182,21 @@ class Runtime
/**
* Retrieve the Configuration
*
* @return array<string, mixed> $configuration
* @return array
*/
public function getConfiguration(): array
public function getConfiguration()
{
return $this->configuration;
}
/**
* Retrieves the Configuration Option for a specific section in the configuration
*
* @param string $key Section name
* @param mixed $default Default value
* @return mixed
*/
public function getConfigOption(string $key, mixed $default = null): mixed
public function getConfigOption($key, $default = null)
{
if (array_key_exists($key, $this->configuration)) {
return $this->configuration[$key];
@ -188,13 +207,14 @@ class Runtime
/**
* Returns the Configuration Option for a specific section the current Environment
*
* @param string $key Section/Parameter name
* @param mixed $default Default value
* @return mixed
*/
public function getEnvOption(string $key, mixed $default = null): mixed
public function getEnvOption($key, $default = null)
{
if (
!array_key_exists('environments', $this->configuration) ||
!is_array($this->configuration['environments'])
) {
if (!array_key_exists('environments', $this->configuration) || !is_array($this->configuration['environments'])) {
return $default;
}
@ -213,10 +233,12 @@ class Runtime
* Shortcut to get the the configuration option for a specific environment and merge it with
* the global one (environment specific overrides the global one if present).
*
* @param array<string, mixed> $defaultEnv
* @return array<string, mixed>
* @param $key
* @param array $defaultEnv
*
* @return array
*/
public function getMergedOption(string $key, array $defaultEnv = []): array
public function getMergedOption($key, $defaultEnv = [])
{
$userGlobalOptions = $this->getConfigOption($key, $defaultEnv);
$userEnvOptions = $this->getEnvOption($key, $defaultEnv);
@ -229,8 +251,12 @@ class Runtime
/**
* Overwrites an Environment Configuration Option
*
* @param string $key
* @param mixed $value
* @return Runtime
*/
public function setEnvOption(string $key, mixed $value): self
public function setEnvOption($key, $value)
{
if (array_key_exists('environments', $this->configuration) && is_array($this->configuration['environments'])) {
if (array_key_exists($this->environment, $this->configuration['environments'])) {
@ -244,14 +270,13 @@ class Runtime
/**
* Sets the working Environment
*
* @param string $environment Environment name
* @return Runtime
* @throws RuntimeException
*/
public function setEnvironment(string $environment): self
public function setEnvironment($environment)
{
if (
array_key_exists('environments', $this->configuration) &&
array_key_exists($environment, $this->configuration['environments'])
) {
if (array_key_exists('environments', $this->configuration) && array_key_exists($environment, $this->configuration['environments'])) {
$this->environment = $environment;
return $this;
}
@ -261,16 +286,21 @@ class Runtime
/**
* Returns the current working Environment
*
* @return null|string
*/
public function getEnvironment(): ?string
public function getEnvironment()
{
return $this->environment;
}
/**
* Sets the working stage
*
* @param string $stage Stage code
* @return Runtime
*/
public function setStage(string $stage): self
public function setStage($stage)
{
$this->stage = $stage;
return $this;
@ -278,8 +308,10 @@ class Runtime
/**
* Retrieve the current working Stage
*
* @return string
*/
public function getStage(): ?string
public function getStage()
{
return $this->stage;
}
@ -287,14 +319,11 @@ class Runtime
/**
* Retrieve the defined Tasks for the current Environment and Stage
*
* @return string[]
* @return array
*/
public function getTasks(): array
public function getTasks()
{
if (
!array_key_exists('environments', $this->configuration) ||
!is_array($this->configuration['environments'])
) {
if (!array_key_exists('environments', $this->configuration) || !is_array($this->configuration['environments'])) {
return [];
}
@ -313,8 +342,11 @@ class Runtime
/**
* Sets the working Host
*
* @param string $host Host name
* @return Runtime
*/
public function setWorkingHost(?string $host): self
public function setWorkingHost($host)
{
$this->workingHost = $host;
return $this;
@ -322,16 +354,21 @@ class Runtime
/**
* Retrieve the working Host
*
* @return null|string
*/
public function getWorkingHost(): ?string
public function getWorkingHost()
{
return $this->workingHost;
}
/**
* Logs a Message into the Logger
*
* @param string $message Log message
* @param string $level Log Level
*/
public function log(string $message, string $level = LogLevel::DEBUG): void
public function log($message, $level = LogLevel::DEBUG)
{
if ($this->logger instanceof LoggerInterface) {
$this->logger->log($level, $message);
@ -340,8 +377,12 @@ class Runtime
/**
* Executes a command, it will be run Locally or Remotely based on the working Stage
*
* @param string $cmd Command to execute
* @param int $timeout Seconds to wait
* @return Process
*/
public function runCommand(string $cmd, int $timeout = 120): Process
public function runCommand($cmd, $timeout = 120)
{
switch ($this->getStage()) {
case self::ON_DEPLOY:
@ -355,12 +396,16 @@ class Runtime
/**
* Execute a command locally
*
* @param string $cmd Command to execute
* @param int $timeout Seconds to wait
* @return Process
*/
public function runLocalCommand(string $cmd, int $timeout = 120): Process
public function runLocalCommand($cmd, $timeout = 120)
{
$this->log($cmd, LogLevel::INFO);
$process = Process::fromShellCommandline($cmd);
$process = new Process($cmd);
$process->setTimeout($timeout);
$process->run();
@ -374,8 +419,13 @@ class Runtime
/**
* Executes a command remotely, if jail is true, it will run inside the Host Path and the Release (if available)
*
* @param string $cmd Command to execute
* @param bool $jail Jail the command
* @param int $timeout Seconds to wait
* @return Process
*/
public function runRemoteCommand(string $cmd, bool $jail, int $timeout = 120): Process
public function runRemoteCommand($cmd, $jail, $timeout = 120)
{
$user = $this->getEnvOption('user', $this->getCurrentUser());
$sudo = $this->getEnvOption('sudo', false);
@ -395,14 +445,7 @@ class Runtime
}
$cmdRemote = str_replace('"', '\"', $cmdDelegate);
$cmdLocal = sprintf(
'ssh -p %d %s %s@%s "%s"',
$sshConfig['port'],
$sshConfig['flags'],
$user,
$host,
$cmdRemote
);
$cmdLocal = sprintf('ssh -p %d %s %s@%s "%s"', $sshConfig['port'], $sshConfig['flags'], $user, $host, $cmdRemote);
return $this->runLocalCommand($cmdLocal, $timeout);
}
@ -410,17 +453,11 @@ class Runtime
/**
* Get the SSH configuration based on the environment
*
* @return array<string, string>
* @return array
*/
public function getSSHConfig(): array
public function getSSHConfig()
{
$sshConfig = $this->getEnvOption(
'ssh',
[
'port' => 22,
'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
]
);
$sshConfig = $this->getEnvOption('ssh', ['port' => 22, 'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']);
if ($this->getHostPort() !== null) {
$sshConfig['port'] = $this->getHostPort();
@ -434,81 +471,72 @@ class Runtime
$sshConfig['flags'] = '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no';
}
if (!array_key_exists('timeout', $sshConfig)) {
$sshConfig['timeout'] = 300;
}
return $sshConfig;
}
/**
* Get the current Host Port or default ssh port
*
* @return integer
*/
public function getHostPort(): ?int
public function getHostPort()
{
$info = explode(':', strval($this->getWorkingHost()));
return isset($info[1]) ? intval($info[1]) : null;
$info = explode(':', $this->getWorkingHost());
return isset($info[1]) ? $info[1] : null;
}
/**
* Get the current Host Name
*
* @return string
*/
public function getHostName(): ?string
public function getHostName()
{
if (strpos(strval($this->getWorkingHost()), ':') === false) {
if (strpos($this->getWorkingHost(), ':') === false) {
return $this->getWorkingHost();
}
$info = explode(':', $this->getWorkingHost());
return strval($info[0]);
return $info[0];
}
/**
* Gets a Temporal File name
*
* @return string
*/
public function getTempFile(): string
public function getTempFile()
{
return tempnam(sys_get_temp_dir(), 'mage');
}
/**
* Get the current user
*
* @return string
*/
public function getCurrentUser(): string
public function getCurrentUser()
{
if ($this->hasPosix()) {
$userData = posix_getpwuid(posix_geteuid());
return $userData['name'];
}
// Windows fallback
return strval(getenv('USERNAME'));
$userData = posix_getpwuid(posix_geteuid());
return $userData['name'];
}
/**
* Shortcut for getting Branch information
*
* @return bool|string
* @return boolean|string
*/
public function getBranch(): mixed
public function getBranch()
{
return $this->getEnvOption('branch', false);
}
/**
* Shortcut for getting Tag information
*
* @return bool|string
*/
public function getTag(): mixed
{
return $this->getEnvOption('tag', false);
}
/**
* Guesses the Deploy Strategy to use
*
* @return StrategyInterface
*/
public function guessStrategy(): StrategyInterface
public function guessStrategy()
{
$strategy = new RsyncStrategy();

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,41 +19,60 @@ use Mage\Runtime\Runtime;
*/
abstract class AbstractTask
{
/** @var array<string, string|int|null> */
protected array $options = [];
/**
* @var array Task custom options
*/
protected $options = [];
protected Runtime $runtime;
/**
* @var Runtime
*/
protected $runtime;
/**
* Get the Name/Code of the Task
*
* @return string
*/
abstract public function getName(): string;
abstract public function getName();
/**
* Get a short Description of the Task
*
* @return string
*/
abstract public function getDescription(): string;
abstract public function getDescription();
/**
* Executes the Command
*
* @return bool
*/
abstract public function execute(): bool;
abstract public function execute();
/**
* Set additional Options for the Task
*
* @param array<string, string|int|null> $options
* @param array $options Options
* @return AbstractTask
*/
public function setOptions(array $options = []): self
public function setOptions($options = [])
{
if (!is_array($options)) {
$options = [];
}
$this->options = array_merge($this->getDefaults(), $options);
return $this;
}
/**
* Set the Runtime instance
*
* @param Runtime $runtime
* @return AbstractTask
*/
public function setRuntime(Runtime $runtime): self
public function setRuntime(Runtime $runtime)
{
$this->runtime = $runtime;
return $this;
@ -62,10 +80,9 @@ abstract class AbstractTask
/**
* Return Default options
*
* @return array<string, string|int|null>
* @return array
*/
public function getDefaults(): array
public function getDefaults()
{
return [];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,10 +19,7 @@ use Mage\Task\AbstractTask;
*/
abstract class AbstractComposerTask extends AbstractTask
{
/**
* @return string[]
*/
protected function getOptions(): array
protected function getOptions()
{
$options = array_merge(
['path' => 'composer'],
@ -35,10 +31,7 @@ abstract class AbstractComposerTask extends AbstractTask
return $options;
}
/**
* @return array<string, string|int>
*/
protected function getComposerOptions(): array
protected function getComposerOptions()
{
return [];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,17 +19,17 @@ use Symfony\Component\Process\Process;
*/
class DumpAutoloadTask extends AbstractComposerTask
{
public function getName(): string
public function getName()
{
return 'composer/dump-autoload';
}
public function getDescription(): string
public function getDescription()
{
return '[Composer] Dump Autoload';
}
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
$cmd = sprintf('%s dump-autoload %s', $options['path'], $options['flags']);
@ -41,7 +40,7 @@ class DumpAutoloadTask extends AbstractComposerTask
return $process->isSuccessful();
}
protected function getComposerOptions(): array
protected function getComposerOptions()
{
return ['flags' => '--optimize'];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,28 +19,28 @@ use Symfony\Component\Process\Process;
*/
class InstallTask extends AbstractComposerTask
{
public function getName(): string
public function getName()
{
return 'composer/install';
}
public function getDescription(): string
public function getDescription()
{
return '[Composer] Install';
}
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
$cmd = sprintf('%s install %s', $options['path'], $options['flags']);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($cmd), intval($options['timeout']));
$process = $this->runtime->runCommand(trim($cmd), $options['timeout']);
return $process->isSuccessful();
}
protected function getComposerOptions(): array
protected function getComposerOptions()
{
return ['flags' => '--optimize-autoloader', 'timeout' => 120];
}

View file

@ -0,0 +1,86 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Composer;
use Mage\Task\Exception\SkipException;
use Symfony\Component\Process\Process;
use DateTime;
/**
* Composer Task - Self update
*
* @author Yanick Witschi <https://github.com/Toflar>
*/
class SelfUpdateTask extends AbstractComposerTask
{
public function getName()
{
return 'composer/self-update';
}
public function getDescription()
{
return '[Composer] Self Update';
}
public function execute()
{
$options = $this->getOptions();
$cmdVersion = sprintf('%s --version', $options['path']);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($cmdVersion));
if (!$process->isSuccessful()) {
return false;
}
$buildDate = $this->getBuildDate($process->getOutput());
if (!$buildDate instanceof DateTime) {
return false;
}
$compareDate = $this->getCompareDate();
if ($buildDate >= $compareDate) {
throw new SkipException();
}
$cmdUpdate = sprintf('%s self-update', $options['path']);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($cmdUpdate));
return $process->isSuccessful();
}
protected function getBuildDate($output)
{
$buildDate = null;
$output = explode(PHP_EOL, $output);
foreach ($output as $row) {
if (strpos($row, 'Composer version ') === 0) {
$buildDate = DateTime::createFromFormat('Y-m-d H:i:s', substr(trim($row), -19));
}
}
return $buildDate;
}
protected function getCompareDate()
{
$options = $this->getOptions();
$compareDate = new DateTime();
$compareDate->modify(sprintf('now -%d days', $options['days']));
return $compareDate;
}
protected function getComposerOptions()
{
return ['days' => 60];
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -21,17 +20,17 @@ use Mage\Task\AbstractTask;
*/
class CleanupTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'deploy/release/cleanup';
}
public function getDescription(): string
public function getDescription()
{
return '[Release] Cleaning up old Releases';
}
public function execute(): bool
public function execute()
{
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
$currentReleaseId = $this->runtime->getReleaseId();
@ -43,13 +42,13 @@ class CleanupTask extends AbstractTask
$process = $this->runtime->runRemoteCommand($cmdListReleases, false);
if ($process->isSuccessful()) {
$releases = $process->getOutput();
$releases = explode("\n", trim($releases));
$releases = explode(PHP_EOL, trim($releases));
if (count($releases) > $maxReleases) {
sort($releases);
$releasesToDelete = array_slice($releases, 0, count($releases) - $maxReleases);
foreach ($releasesToDelete as $releaseId) {
if ($releaseId !== $currentReleaseId) {
if ($releaseId != $currentReleaseId) {
$cmdDeleteRelease = sprintf('rm -rf %s/releases/%s', $hostPath, $releaseId);
/** @var Process $process */
$process = $this->runtime->runRemoteCommand($cmdDeleteRelease, false);

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -21,17 +20,17 @@ use Mage\Task\AbstractTask;
*/
class PrepareTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'deploy/release/prepare';
}
public function getDescription(): string
public function getDescription()
{
return '[Release] Preparing Release';
}
public function execute(): bool
public function execute()
{
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -23,17 +22,17 @@ use Mage\Task\AbstractTask;
*/
class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
{
public function getName(): string
public function getName()
{
return 'deploy/release';
}
public function getDescription(): string
public function getDescription()
{
return '[Release] Creating Symlink';
}
public function execute(): bool
public function execute()
{
if (!$this->runtime->getEnvOption('releases', false)) {
throw new ErrorException('This task is only available with releases enabled', 40);
@ -42,12 +41,10 @@ class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
$releaseId = $this->runtime->getReleaseId();
$symlink = $this->runtime->getEnvOption('symlink', 'current');
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s %s', $hostPath, $releaseId, $symlink);
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s current', $hostPath, $releaseId);
/** @var Process $process */
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false, 0);
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false, null);
return $process->isSuccessful();
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -22,17 +21,17 @@ use Mage\Task\AbstractTask;
*/
class RsyncTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'deploy/rsync';
}
public function getDescription(): string
public function getDescription()
{
return '[Deploy] Copying files with Rsync';
}
public function execute(): bool
public function execute()
{
$flags = $this->runtime->getEnvOption('rsync', '-avz');
$sshConfig = $this->runtime->getSSHConfig();
@ -47,24 +46,14 @@ class RsyncTask extends AbstractTask
$excludes = $this->getExcludes();
$from = $this->runtime->getEnvOption('from', './');
$cmdRsync = sprintf(
'rsync -e "ssh -p %d %s" %s %s %s %s@%s:%s',
$sshConfig['port'],
$sshConfig['flags'],
$flags,
$excludes,
$from,
$user,
$host,
$targetDir
);
$cmdRsync = sprintf('rsync -e "ssh -p %d %s" %s %s %s %s@%s:%s', $sshConfig['port'], $sshConfig['flags'], $flags, $excludes, $from, $user, $host, $targetDir);
/** @var Process $process */
$process = $this->runtime->runLocalCommand($cmdRsync, 0);
$process = $this->runtime->runLocalCommand($cmdRsync, null);
return $process->isSuccessful();
}
protected function getExcludes(): string
protected function getExcludes()
{
$excludes = $this->runtime->getMergedOption('exclude', []);
$excludes = array_merge(['.git'], array_filter($excludes));

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -22,17 +21,17 @@ use Mage\Task\AbstractTask;
*/
class CleanupTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'deploy/tar/cleanup';
}
public function getDescription(): string
public function getDescription()
{
return '[Deploy] Cleanup Tar file';
}
public function execute(): bool
public function execute()
{
if (!$this->runtime->getEnvOption('releases', false)) {
throw new ErrorException('This task is only available with releases enabled', 40);

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -22,17 +21,17 @@ use Mage\Task\AbstractTask;
*/
class CopyTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'deploy/tar/copy';
}
public function getDescription(): string
public function getDescription()
{
return '[Deploy] Copying files with Tar';
}
public function execute(): bool
public function execute()
{
if (!$this->runtime->getEnvOption('releases', false)) {
throw new ErrorException('This task is only available with releases enabled', 40);
@ -51,19 +50,10 @@ class CopyTask extends AbstractTask
$tarLocal = $this->runtime->getVar('tar_local');
$tarRemote = basename($tarLocal);
$cmdCopy = sprintf(
'scp -P %d %s %s %s@%s:%s/%s',
$sshConfig['port'],
isset($sshConfig['scp_flags']) ? $sshConfig['scp_flags'] : $sshConfig['flags'],
$tarLocal,
$user,
$host,
$targetDir,
$tarRemote
);
$cmdCopy = sprintf('scp -P %d %s %s %s@%s:%s/%s', $sshConfig['port'], $sshConfig['flags'], $tarLocal, $user, $host, $targetDir, $tarRemote);
/** @var Process $process */
$process = $this->runtime->runLocalCommand($cmdCopy, intval($sshConfig['timeout']));
$process = $this->runtime->runLocalCommand($cmdCopy, 300);
if ($process->isSuccessful()) {
$cmdUnTar = sprintf('cd %s && %s %s %s', $targetDir, $tarPath, $flags, $tarRemote);
$process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600);

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -22,17 +21,17 @@ use Mage\Task\AbstractTask;
*/
class PrepareTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'deploy/tar/prepare';
}
public function getDescription(): string
public function getDescription()
{
return '[Deploy] Preparing Tar file';
}
public function execute(): bool
public function execute()
{
if (!$this->runtime->getEnvOption('releases', false)) {
throw new ErrorException('This task is only available with releases enabled', 40);
@ -43,16 +42,8 @@ class PrepareTask extends AbstractTask
$excludes = $this->getExcludes();
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
$flags = $this->runtime->getEnvOption(
'tar_create',
$this->runtime->isWindows() ? '--force-local -c -z -p -f' : 'cfzp'
);
$flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
$from = $this->runtime->getEnvOption('from', './');
if ($this->runtime->getEnvOption('copyDirectory', false)) {
$from = sprintf('-C %s ./', $from);
}
$cmdTar = sprintf('%s %s %s %s %s', $tarPath, $flags, $tarLocal, $excludes, $from);
/** @var Process $process */
@ -60,7 +51,7 @@ class PrepareTask extends AbstractTask
return $process->isSuccessful();
}
protected function getExcludes(): string
protected function getExcludes()
{
$excludes = $this->runtime->getMergedOption('exclude', []);
$excludes = array_merge(['.git'], array_filter($excludes));

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -25,7 +24,7 @@ class ExecTask extends AbstractTask
/**
* @return string
*/
public function getName(): string
public function getName()
{
return 'exec';
}
@ -33,7 +32,7 @@ class ExecTask extends AbstractTask
/**
* @return string
*/
public function getDescription(): string
public function getDescription()
{
$options = $this->getOptions();
@ -49,7 +48,7 @@ class ExecTask extends AbstractTask
*
* @throws ErrorException
*/
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
@ -57,29 +56,15 @@ class ExecTask extends AbstractTask
throw new ErrorException('Parameter "cmd" is not defined');
}
$mapping = [
'%environment%' => $this->runtime->getEnvironment(),
];
if ($this->runtime->getReleaseId() !== null) {
$mapping['%release%'] = $this->runtime->getReleaseId();
}
$cmd = str_replace(
array_keys($mapping),
array_values($mapping),
strval($options['cmd'])
);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd, intval($options['timeout']));
$process = $this->runtime->runCommand($options['cmd'], $options['timeout']);
return $process->isSuccessful();
}
/**
* @return array<string, string|int>
* @return array
*/
protected function getOptions(): array
protected function getOptions()
{
$options = array_merge(
['cmd' => '', 'desc' => '', 'timeout' => 120],

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -24,10 +23,10 @@ abstract class AbstractFileTask extends AbstractTask
/**
* Returns the Task options
*
* @return array<string, string|int|null>
* @return array
* @throws ErrorException
*/
protected function getOptions(): array
protected function getOptions()
{
$mandatory = $this->getParameters();
$defaults = array_keys($this->getDefaults());
@ -45,16 +44,18 @@ abstract class AbstractFileTask extends AbstractTask
/**
* Returns the mandatory parameters
*
* @return string[]
* @return array
*/
abstract protected function getParameters(): array;
abstract protected function getParameters();
/**
* Returns a file with the placeholders replaced
*
* @param string $file
* @return string
* @throws ErrorException
*/
protected function getFile(string $file): string
protected function getFile($file)
{
$mapping = [
'%environment%' => $this->runtime->getEnvironment(),
@ -72,7 +73,7 @@ abstract class AbstractFileTask extends AbstractTask
return str_replace(
array_keys($mapping),
array_values($mapping),
strval($options[$file])
$options[$file]
);
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -12,6 +11,7 @@
namespace Mage\Task\BuiltIn\FS;
use Symfony\Component\Process\Process;
use Exception;
/**
* File System Task - Copy a File
@ -20,21 +20,21 @@ use Symfony\Component\Process\Process;
*/
class ChangeModeTask extends AbstractFileTask
{
public function getName(): string
public function getName()
{
return 'fs/chmod';
}
public function getDescription(): string
public function getDescription()
{
try {
return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
} catch (\Exception $exception) {
} catch (Exception $exception) {
return '[FS] Chmod [missing parameters]';
}
}
public function execute(): bool
public function execute()
{
$file = $this->getFile('file');
$mode = $this->options['mode'];
@ -48,12 +48,12 @@ class ChangeModeTask extends AbstractFileTask
return $process->isSuccessful();
}
protected function getParameters(): array
protected function getParameters()
{
return ['file', 'mode', 'flags'];
}
public function getDefaults(): array
public function getDefaults()
{
return ['flags' => null];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -12,6 +11,7 @@
namespace Mage\Task\BuiltIn\FS;
use Symfony\Component\Process\Process;
use Exception;
/**
* File System Task - Copy a File
@ -20,21 +20,21 @@ use Symfony\Component\Process\Process;
*/
class CopyTask extends AbstractFileTask
{
public function getName(): string
public function getName()
{
return 'fs/copy';
}
public function getDescription(): string
public function getDescription()
{
try {
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
} catch (\Exception $exception) {
} catch (Exception $exception) {
return '[FS] Copy [missing parameters]';
}
}
public function execute(): bool
public function execute()
{
$copyFrom = $this->getFile('from');
$copyTo = $this->getFile('to');
@ -48,12 +48,12 @@ class CopyTask extends AbstractFileTask
return $process->isSuccessful();
}
protected function getParameters(): array
protected function getParameters()
{
return ['from', 'to', 'flags'];
}
public function getDefaults(): array
public function getDefaults()
{
return ['flags' => '-p'];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -12,6 +11,7 @@
namespace Mage\Task\BuiltIn\FS;
use Symfony\Component\Process\Process;
use Exception;
/**
* File System Task - Symlink a File
@ -20,21 +20,21 @@ use Symfony\Component\Process\Process;
*/
class LinkTask extends AbstractFileTask
{
public function getName(): string
public function getName()
{
return 'fs/link';
}
public function getDescription(): string
public function getDescription()
{
try {
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
} catch (\Exception $exception) {
} catch (Exception $exception) {
return '[FS] Link [missing parameters]';
}
}
public function execute(): bool
public function execute()
{
$linkFrom = $this->getFile('from');
$linkTo = $this->getFile('to');
@ -48,12 +48,12 @@ class LinkTask extends AbstractFileTask
return $process->isSuccessful();
}
protected function getParameters(): array
protected function getParameters()
{
return ['from', 'to', 'flags'];
}
public function getDefaults(): array
public function getDefaults()
{
return ['flags' => '-snf'];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -21,12 +20,12 @@ use Exception;
*/
class MoveTask extends AbstractFileTask
{
public function getName(): string
public function getName()
{
return 'fs/move';
}
public function getDescription(): string
public function getDescription()
{
try {
return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
@ -35,7 +34,7 @@ class MoveTask extends AbstractFileTask
}
}
public function execute(): bool
public function execute()
{
$moveFrom = $this->getFile('from');
$moveTo = $this->getFile('to');
@ -49,12 +48,12 @@ class MoveTask extends AbstractFileTask
return $process->isSuccessful();
}
protected function getParameters(): array
protected function getParameters()
{
return ['from', 'to', 'flags'];
}
public function getDefaults(): array
public function getDefaults()
{
return ['flags' => null];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -12,6 +11,7 @@
namespace Mage\Task\BuiltIn\FS;
use Symfony\Component\Process\Process;
use Exception;
/**
* File System Task - Remove a File
@ -20,21 +20,21 @@ use Symfony\Component\Process\Process;
*/
class RemoveTask extends AbstractFileTask
{
public function getName(): string
public function getName()
{
return 'fs/remove';
}
public function getDescription(): string
public function getDescription()
{
try {
return sprintf('[FS] Remove "%s"', $this->getFile('file'));
} catch (\Exception $exception) {
} catch (Exception $exception) {
return '[FS] Remove [missing parameters]';
}
}
public function execute(): bool
public function execute()
{
$file = $this->getFile('file');
$flags = $this->options['flags'];
@ -47,12 +47,12 @@ class RemoveTask extends AbstractFileTask
return $process->isSuccessful();
}
protected function getParameters(): array
protected function getParameters()
{
return ['file', 'flags'];
}
public function getDefaults(): array
public function getDefaults()
{
return ['flags' => null];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -22,35 +21,29 @@ use Mage\Task\AbstractTask;
*/
class ChangeBranchTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'git/change-branch';
}
public function getDescription(): string
public function getDescription()
{
$options = $this->getOptions();
$tag = $options['tag'];
$branch = $options['branch'];
if ($this->runtime->getVar('git_revert_branch', null)) {
if ($this->runtime->getVar('git_revert_branch', false)) {
$branch = $this->runtime->getVar('git_revert_branch');
}
if ($tag) {
return sprintf('[Git] Checkout Tag (%s)', $tag);
}
return sprintf('[Git] Change Branch (%s)', $branch);
}
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
/** @var string|bool */
$branch = $this->runtime->getVar('git_revert_branch', null);
$branch = $this->runtime->getVar('git_revert_branch', false);
if (!$branch) {
if ($branch === false) {
$cmdGetCurrent = sprintf('%s branch | grep "*"', $options['path']);
/** @var Process $process */
@ -60,11 +53,11 @@ class ChangeBranchTask extends AbstractTask
}
$currentBranch = str_replace('* ', '', trim($process->getOutput()));
if ($currentBranch === $options['branch']) {
if ($currentBranch == $options['branch']) {
throw new SkipException();
}
$branch = $options['tag'] ? $options['tag'] : $options['branch'];
$branch = $options['branch'];
$this->runtime->setVar('git_revert_branch', $currentBranch);
}
@ -75,15 +68,11 @@ class ChangeBranchTask extends AbstractTask
return $process->isSuccessful();
}
/**
* @return array<string, string>
*/
protected function getOptions(): array
protected function getOptions()
{
$tag = $this->runtime->getEnvOption('tag', false);
$branch = $this->runtime->getEnvOption('branch', 'master');
$options = array_merge(
['path' => 'git', 'branch' => $branch, 'tag' => $tag],
['path' => 'git', 'branch' => $branch],
$this->options
);

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -13,7 +12,6 @@ namespace Mage\Task\BuiltIn\Git;
use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;
use Mage\Task\Exception\SkipException;
/**
* Git Task - Pull
@ -22,40 +20,32 @@ use Mage\Task\Exception\SkipException;
*/
class UpdateTask extends AbstractTask
{
public function getName(): string
public function getName()
{
return 'git/update';
}
public function getDescription(): string
public function getDescription()
{
return '[Git] Update';
}
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
if ($options['tag']) {
throw new SkipException();
}
$command = $options['path'] . ' pull';
/** @var Process $process */
$process = $this->runtime->runLocalCommand($command);
return $process->isSuccessful();
}
/**
* @return array<string, string>
*/
protected function getOptions(): array
protected function getOptions()
{
$branch = $this->runtime->getEnvOption('branch', 'master');
$tag = $this->runtime->getEnvOption('tag', false);
$options = array_merge(
['path' => 'git', 'branch' => $branch, 'tag' => $tag],
['path' => 'git', 'branch' => $branch],
$this->options
);

View file

@ -1,61 +0,0 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn;
use Mage\Task\Exception\ErrorException;
use Mage\Task\AbstractTask;
/**
* Sleep task. Sleeps for a given number of seconds so you can delay task
* execution.
*
* @author Yanick Witschi <https://github.com/Toflar>
*/
class SleepTask extends AbstractTask
{
public function getName(): string
{
return 'sleep';
}
public function getDescription(): string
{
$options = $this->getOptions();
return sprintf('[Sleep] Sleeping for %d second(s)', $options['seconds']);
}
/**
* @throws ErrorException
*/
public function execute(): bool
{
$options = $this->getOptions();
sleep(intval($options['seconds']));
return true;
}
/**
* @return array<string, string|int>
*/
protected function getOptions(): array
{
$options = array_merge(
['seconds' => 1],
$this->options
);
return $options;
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,10 +19,7 @@ use Mage\Task\AbstractTask;
*/
abstract class AbstractSymfonyTask extends AbstractTask
{
/**
* @return array<string, string>
*/
protected function getOptions(): array
protected function getOptions()
{
$options = array_merge(
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
@ -35,10 +31,7 @@ abstract class AbstractSymfonyTask extends AbstractTask
return $options;
}
/**
* @return array<string, string|null>
*/
protected function getSymfonyOptions(): array
protected function getSymfonyOptions()
{
return [];
}

View file

@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Symfony;
use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;
/**
* Symfony Task - Dump Assetics
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class AsseticDumpTask extends AbstractTask
{
public function getName()
{
return 'symfony/assetic-dump';
}
public function getDescription()
{
return '[Symfony] Assetic Dump';
}
public function execute()
{
$options = $this->getOptions();
$command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($command), $options['timeout']);
return $process->isSuccessful();
}
protected function getOptions()
{
$options = array_merge(
['console' => 'bin/console', 'env' => 'dev', 'flags' => '', 'timeout' => 120],
$this->runtime->getMergedOption('symfony'),
$this->options
);
return $options;
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,33 +19,28 @@ use Symfony\Component\Process\Process;
*/
class AssetsInstallTask extends AbstractSymfonyTask
{
public function getName(): string
public function getName()
{
return 'symfony/assets-install';
}
public function getDescription(): string
public function getDescription()
{
return '[Symfony] Assets Install';
}
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
$command = sprintf(
'%s assets:install %s --env=%s %s',
$options['console'],
$options['target'],
$options['env'],
$options['flags']
);
$command = sprintf('%s assets:install %s --env=%s %s', $options['console'], $options['target'], $options['env'], $options['flags']);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($command));
return $process->isSuccessful();
}
protected function getSymfonyOptions(): array
protected function getSymfonyOptions()
{
return ['target' => 'web', 'flags' => '--symlink --relative'];
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,17 +19,17 @@ use Symfony\Component\Process\Process;
*/
class CacheClearTask extends AbstractSymfonyTask
{
public function getName(): string
public function getName()
{
return 'symfony/cache-clear';
}
public function getDescription(): string
public function getDescription()
{
return '[Symfony] Cache Clear';
}
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
$command = $options['console'] . ' cache:clear --env=' . $options['env'] . ' ' . $options['flags'];

View file

@ -1,60 +0,0 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Symfony;
use Mage\Task\Exception\ErrorException;
use Symfony\Component\Process\Process;
/**
* Symfony Task - Cache Pool Clear
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class CachePoolClearTask extends AbstractSymfonyTask
{
public function getName(): string
{
return 'symfony/cache-pool-clear';
}
public function getDescription(): string
{
return '[Symfony] Cache Pool Clear';
}
public function execute(): bool
{
$options = $this->getOptions();
if (!$options['pools']) {
throw new ErrorException('Parameter "pools" is not defined');
}
$command = sprintf(
'%s cache:pool:clear %s --env=%s %s',
$options['console'],
$options['pools'],
$options['env'],
$options['flags']
);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($command));
return $process->isSuccessful();
}
protected function getSymfonyOptions(): array
{
return ['pools' => null];
}
}

View file

@ -1,43 +0,0 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Symfony;
use Symfony\Component\Process\Process;
/**
* Symfony Task - Cache Pool Prune
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class CachePoolPruneTask extends AbstractSymfonyTask
{
public function getName(): string
{
return 'symfony/cache-pool-prune';
}
public function getDescription(): string
{
return '[Symfony] Cache Pool Prune';
}
public function execute(): bool
{
$options = $this->getOptions();
$command = $options['console'] . ' cache:pool:prune --env=' . $options['env'] . ' ' . $options['flags'];
/** @var Process $process */
$process = $this->runtime->runCommand(trim($command));
return $process->isSuccessful();
}
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -20,17 +19,17 @@ use Symfony\Component\Process\Process;
*/
class CacheWarmupTask extends AbstractSymfonyTask
{
public function getName(): string
public function getName()
{
return 'symfony/cache-warmup';
}
public function getDescription(): string
public function getDescription()
{
return '[Symfony] Cache Warmup';
}
public function execute(): bool
public function execute()
{
$options = $this->getOptions();
$command = $options['console'] . ' cache:warmup --env=' . $options['env'] . ' ' . $options['flags'];

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -11,14 +10,16 @@
namespace Mage\Task\Exception;
use Exception;
/**
* The Task Failed, and it has a Custom Message
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class ErrorException extends \Exception
class ErrorException extends Exception
{
public function getTrimmedMessage(int $maxLength = 60): string
public function getTrimmedMessage($maxLength = 60)
{
$message = $this->getMessage();

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -11,11 +10,13 @@
namespace Mage\Task\Exception;
use Exception;
/**
* The Task will be Skipped
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class SkipException extends \Exception
class SkipException extends Exception
{
}

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -24,15 +23,20 @@ use ReflectionClass;
*/
class TaskFactory
{
protected Runtime $runtime;
/**
* @var Runtime
*/
protected $runtime;
/**
* @var AbstractTask[] Registered Tasks
* @var array Registered Tasks
*/
protected array $registeredTasks = [];
protected $registeredTasks = [];
/**
* Constructor
*
* @param Runtime $runtime
*/
public function __construct(Runtime $runtime)
{
@ -43,8 +47,10 @@ class TaskFactory
/**
* Add a Task
*
* @param AbstractTask $task
*/
public function add(AbstractTask $task): void
public function add(AbstractTask $task)
{
$task->setRuntime($this->runtime);
$this->registeredTasks[$task->getName()] = $task;
@ -54,10 +60,11 @@ class TaskFactory
* Get a Task by it's registered Name/Code, or it can be a Class Name,
* in that case the class will be instantiated
*
* @param string|mixed[] $name
* @param string $name Name/Code or Class of the Task
* @return AbstractTask
* @throws RuntimeException
*/
public function get(mixed $name): AbstractTask
public function get($name)
{
$options = [];
if (is_array($name)) {
@ -89,22 +96,14 @@ class TaskFactory
/**
* Load BuiltIn Tasks
*/
protected function loadBuiltInTasks(): void
protected function loadBuiltInTasks()
{
$finder = new Finder();
$finder->files()->in(__DIR__ . '/BuiltIn')->name('*Task.php');
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$taskClass = substr(
'\\Mage\\Task\\BuiltIn\\' . str_replace(
'/',
'\\',
$file->getRelativePathname()
),
0,
-4
);
$taskClass = substr('\\Mage\\Task\\BuiltIn\\' . str_replace('/', '\\', $file->getRelativePathname()), 0, -4);
if (class_exists($taskClass)) {
$reflex = new ReflectionClass($taskClass);
if ($reflex->isInstantiable()) {
@ -119,11 +118,10 @@ class TaskFactory
/**
* Load Custom Tasks
*
* @param string[] $tasksToLoad
* @param array $tasksToLoad PreRegistered Tasks
* @throws RuntimeException
*/
protected function loadCustomTasks(array $tasksToLoad): void
protected function loadCustomTasks($tasksToLoad)
{
foreach ($tasksToLoad as $taskClass) {
if (!class_exists($taskClass)) {
@ -137,9 +135,7 @@ class TaskFactory
$task = new $taskClass();
if (!$task instanceof AbstractTask) {
throw new RuntimeException(
sprintf('Custom Task "%s" must inherit "Mage\\Task\\AbstractTask".', $taskClass)
);
throw new RuntimeException(sprintf('Custom Task "%s" must inherit "Mage\\Task\\AbstractTask".', $taskClass));
}
// Add Task

View file

@ -1,5 +1,4 @@
<?php
/*
* This file is part of the Magallanes package.
*
@ -12,6 +11,8 @@
namespace Mage;
use Mage\Runtime\Runtime;
use DateTime;
use DateInterval;
/**
* Utility class for resolving trivial operations
@ -22,8 +23,11 @@ class Utils
{
/**
* Given a stage code it will resolve a human friendly name
*
* @param string $stage
* @return string
*/
public function getStageName(string $stage): string
public function getStageName($stage)
{
switch ($stage) {
case Runtime::PRE_DEPLOY:
@ -47,36 +51,35 @@ class Utils
/**
* Given a Release ID, convert it to a DateTime instance
*
* @param string $releaseId The Release ID
* @return DateTime
*/
public function getReleaseDate(string $releaseId): \DateTime
public function getReleaseDate($releaseId)
{
$formatted = sprintf(
'%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d',
$releaseId[0],
$releaseId[1],
$releaseId[2],
$releaseId[3],
$releaseId[4],
$releaseId[5],
$releaseId[6],
$releaseId[7],
$releaseId[8],
$releaseId[9],
$releaseId[10],
$releaseId[11],
$releaseId[12],
$releaseId[13]
$formatted = sprintf('%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d',
$releaseId[0], $releaseId[1], $releaseId[2], $releaseId[3],
$releaseId[4], $releaseId[5],
$releaseId[6], $releaseId[7],
$releaseId[8], $releaseId[9],
$releaseId[10], $releaseId[11],
$releaseId[12], $releaseId[13]
);
return new \DateTime($formatted);
return new DateTime($formatted);
}
/**
* Given a Date, calculate friendly how much time has passed
*
* @param DateTime $releaseDate
* @return string
*/
public function getTimeDiff(\DateTime $releaseDate): string
public function getTimeDiff(DateTime $releaseDate)
{
$now = new \DateTime();
$now = new DateTime();
/** @var DateInterval $diff */
$diff = $now->diff($releaseDate);
if ($diff->days > 7) {

View file

@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Config\DumpCommand;
use Mage\Command\AbstractCommand;
use Mage\Tests\MageApplicationMockup;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class DumpCommandTest extends TestCase
{

View file

@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Config\EnvironmentsCommand;
use Mage\Command\AbstractCommand;
use Mage\Tests\MageApplicationMockup;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class EnvironmentsCommandTest extends TestCase
{

16
tests/Command/BuiltIn/DeployCommandMiscTasksTest.php Executable file → Normal file
View file

@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\DeployCommand;
use Mage\Tests\MageApplicationMockup;
use Mage\Command\AbstractCommand;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class DeployCommandMiscTasksTest extends TestCase
{
@ -35,10 +35,8 @@ class DeployCommandMiscTasksTest extends TestCase
0 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
1 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=testenv"',
2 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=testenv --symlink --relative"',
3 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=testenv"',
4 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=prod"',
5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:clear main --env=testenv"',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:clear main --env=prod"',
3 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=testenv"',
4 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=prod"',
);
// Check total of Executed Commands
@ -154,7 +152,7 @@ class DeployCommandMiscTasksTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertEquals(7, $tester->getStatusCode());
$this->assertStringContainsString('Invalid task name "invalid/task"', $tester->getDisplay());
$this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay());
}
public function testBrokenGitBranch()
@ -171,7 +169,7 @@ class DeployCommandMiscTasksTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -189,7 +187,7 @@ class DeployCommandMiscTasksTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -207,7 +205,7 @@ class DeployCommandMiscTasksTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('Running [Git] Update ... FAIL', $tester->getDisplay());
$this->assertContains('Running [Git] Update ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
}

34
tests/Command/BuiltIn/DeployCommandMiscTest.php Executable file → Normal file
View file

@ -15,7 +15,7 @@ use Mage\Runtime\Exception\RuntimeException;
use Mage\Tests\MageApplicationMockup;
use Mage\Command\AbstractCommand;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class DeployCommandMiscTest extends TestCase
{
@ -30,33 +30,13 @@ class DeployCommandMiscTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('No hosts defined, skipping On Deploy tasks', $tester->getDisplay());
$this->assertStringContainsString('No hosts defined, skipping On Release tasks', $tester->getDisplay());
$this->assertStringContainsString('No hosts defined, skipping Post Release tasks', $tester->getDisplay());
$this->assertContains('No hosts defined, skipping On Deploy tasks', $tester->getDisplay());
$this->assertContains('No hosts defined, skipping On Release tasks', $tester->getDisplay());
$this->assertContains('No hosts defined, skipping Post Release tasks', $tester->getDisplay());
$this->assertEquals(0, $tester->getStatusCode());
}
public function testTagAndBranch()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/no-hosts.yml');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute([
'command' => $command->getName(),
'environment' => 'test',
'--branch' => 'branch',
'--tag' => 'tag'
]);
$this->assertTrue(strpos($tester->getDisplay(), 'Branch and Tag options are mutually exclusive.') !== false);
$this->assertGreaterThan(0, $tester->getStatusCode());
}
public function testInvalidLog()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-log.yml');
@ -98,7 +78,7 @@ class DeployCommandMiscTest extends TestCase
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console cache:clear --env=dev"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console cache:warmup --env=dev"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console assets:install web --env=dev --symlink --relative"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console cache:pool:prune --env=dev"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console assetic:dump --env=dev"',
10 => 'git checkout master',
);
@ -135,7 +115,7 @@ class DeployCommandMiscTest extends TestCase
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
9 => 'git checkout master',
);
@ -279,7 +259,7 @@ class DeployCommandMiscTest extends TestCase
4 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
8 => 'git branch | grep "*"',
);

387
tests/Command/BuiltIn/DeployCommandWithReleasesTest.php Executable file → Normal file
View file

@ -13,9 +13,8 @@ namespace Mage\Tests\Command\BuiltIn;
use Mage\Command\BuiltIn\DeployCommand;
use Mage\Command\AbstractCommand;
use Mage\Tests\MageApplicationMockup;
use Mage\Tests\MageApplicationWindowsMockup;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class DeployCommandWithReleasesTest extends TestCase
{
@ -47,7 +46,7 @@ class DeployCommandWithReleasesTest extends TestCase
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
@ -69,105 +68,6 @@ class DeployCommandWithReleasesTest extends TestCase
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithReleasesCommandsWithTag()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost.yml');
$application->getRuntime()->setReleaseId('20170101015120');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test', '--tag' => 'v1.0.0']);
$ranCommands = $application->getRuntime()->getRanCommands();
$testCase = array(
0 => 'git branch | grep "*"',
1 => 'git checkout v1.0.0',
2 => 'composer install --optimize-autoloader',
3 => 'composer dump-autoload --optimize',
4 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
6 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
18 => 'rm /tmp/mageXYZ',
19 => 'git checkout master',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithReleasesCommandsCustomSymlink()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-custom-symlink.yml');
$application->getRuntime()->setReleaseId('20170101015120');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$ranCommands = $application->getRuntime()->getRanCommands();
$testCase = array(
0 => 'git branch | grep "*"',
1 => 'git checkout test',
2 => 'git pull',
3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize',
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 prod"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
19 => 'rm /tmp/mageXYZ',
20 => 'git checkout master',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithReleasesWithPortCommands()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-port.yml');
@ -196,7 +96,7 @@ class DeployCommandWithReleasesTest extends TestCase
9 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=prod"',
11 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=prod --symlink --relative"',
12 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=prod"',
12 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=prod"',
13 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
@ -246,207 +146,7 @@ class DeployCommandWithReleasesTest extends TestCase
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
19 => 'rm /tmp/mageXYZ',
20 => 'git checkout master',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithReleasesWithFromCommandsOnWindows()
{
$application = new MageApplicationWindowsMockup(__DIR__ . '/../../Resources/testhost-with-from.yml');
$application->getRuntime()->setReleaseId('20170101015120');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$ranCommands = $application->getRuntime()->getRanCommands();
$testCase = array(
0 => 'git branch | grep "*"',
1 => 'git checkout test',
2 => 'git pull',
3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize',
5 => 'tar --force-local -c -z -p -f /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./dist',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
19 => 'rm /tmp/mageXYZ',
20 => 'git checkout master',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithReleasesWithFromCommandsWithDirectoryCopy()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-from-copy-directory.yml');
$application->getRuntime()->setReleaseId('20170101015120');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$ranCommands = $application->getRuntime()->getRanCommands();
$testCase = array(
0 => 'git branch | grep "*"',
1 => 'git checkout test',
2 => 'git pull',
3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize',
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" -C ./dist ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
19 => 'rm /tmp/mageXYZ',
20 => 'git checkout master',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithReleasesWithTimeout()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-release-timeout.yml');
$application->getRuntime()->setReleaseId('20170101015120');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$ranCommands = $application->getRuntime()->getRanCommands();
$testCase = array(
0 => 'git branch | grep "*"',
1 => 'git checkout test',
2 => 'git pull',
3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize',
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
19 => 'rm /tmp/mageXYZ',
20 => 'git checkout master',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithReleasesWithSCPFlags()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-release-scp-flags.yml');
$application->getRuntime()->setReleaseId('20170101015120');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$ranCommands = $application->getRuntime()->getRanCommands();
$testCase = array(
0 => 'git branch | grep "*"',
1 => 'git checkout test',
2 => 'git pull',
3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize',
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
7 => 'scp -P 22 -p -l 1000 /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
@ -479,7 +179,7 @@ class DeployCommandWithReleasesTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -494,7 +194,7 @@ class DeployCommandWithReleasesTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -509,7 +209,7 @@ class DeployCommandWithReleasesTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -524,7 +224,7 @@ class DeployCommandWithReleasesTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('Copying files with Tar ... FAIL', $tester->getDisplay());
$this->assertContains('Copying files with Tar ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -539,7 +239,7 @@ class DeployCommandWithReleasesTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -580,8 +280,8 @@ class DeployCommandWithReleasesTest extends TestCase
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertStringContainsString('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
$this->assertStringContainsString('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertContains('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -621,8 +321,8 @@ class DeployCommandWithReleasesTest extends TestCase
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertStringContainsString('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
$this->assertStringContainsString('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertContains('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -656,7 +356,7 @@ class DeployCommandWithReleasesTest extends TestCase
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
@ -674,57 +374,8 @@ class DeployCommandWithReleasesTest extends TestCase
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertStringContainsString('Running [Deploy] Cleanup Tar file ... FAIL', $tester->getDisplay());
$this->assertStringContainsString('Stage "Post Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
public function testDeploymentFailCleanupReleases()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost.yml');
$application->getRuntime()->setReleaseId('20170101015120');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$application->getRuntime()->forceFail('ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"');
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$ranCommands = $application->getRuntime()->getRanCommands();
$testCase = array(
0 => 'git branch | grep "*"',
1 => 'git checkout test',
2 => 'git pull',
3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize',
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertStringContainsString('Running [Release] Cleaning up old Releases ... FAIL', $tester->getDisplay());
$this->assertStringContainsString('Stage "Post Release" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertContains('Running [Deploy] Cleanup Tar file ... FAIL', $tester->getDisplay());
$this->assertContains('Stage "Post Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
@ -758,7 +409,7 @@ class DeployCommandWithReleasesTest extends TestCase
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=dev"',
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
);
@ -771,8 +422,8 @@ class DeployCommandWithReleasesTest extends TestCase
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertStringContainsString('Running [Release] Cleaning up old Releases ... FAIL', $tester->getDisplay());
$this->assertStringContainsString('Stage "Post Release" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertContains('Running [Release] Cleaning up old Releases ... FAIL', $tester->getDisplay());
$this->assertContains('Stage "Post Release" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
}

View file

@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\DeployCommand;
use Mage\Command\AbstractCommand;
use Mage\Tests\MageApplicationMockup;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class DeployCommandWithoutReleasesTest extends TestCase
{
@ -40,7 +40,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
9 => 'git checkout master',
);
@ -77,7 +77,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
5 => 'rsync -e "ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
6 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
7 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
8 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
8 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
9 => 'git checkout master',
);
@ -114,7 +114,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./dist tester@testhost:/var/www/test',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
9 => 'git checkout master',
);
@ -161,7 +161,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
$this->assertEquals($command, $ranCommands[$index]);
}
$this->assertStringContainsString('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
}

14
tests/Command/BuiltIn/Releases/ListCommandTest.php Executable file → Normal file
View file

@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Releases\ListCommand;
use Mage\Command\AbstractCommand;
use Mage\Tests\MageApplicationMockup;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class ListCommandTest extends TestCase
{
@ -57,7 +57,7 @@ class ListCommandTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'developers']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertStringContainsString('The environment "developers" does not exists.', $tester->getDisplay());
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
}
public function testListReleasesWithoutReleases()
@ -72,7 +72,7 @@ class ListCommandTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertStringContainsString('Releases are not enabled', $tester->getDisplay());
$this->assertContains('Releases are not enabled', $tester->getDisplay());
}
public function testFailToGetCurrentRelease()
@ -87,7 +87,7 @@ class ListCommandTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertStringContainsString('Unable to retrieve current release from host "host1"', $tester->getDisplay());
$this->assertContains('Unable to retrieve current release from host "host1"', $tester->getDisplay());
}
public function testNoReleasesAvailable()
@ -101,7 +101,7 @@ class ListCommandTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('No releases available on host host2', $tester->getDisplay());
$this->assertContains('No releases available on host host2', $tester->getDisplay());
}
public function testFailGetReleases()
@ -116,7 +116,7 @@ class ListCommandTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertStringContainsString('Unable to retrieve releases from host "host3"', $tester->getDisplay());
$this->assertContains('Unable to retrieve releases from host "host3"', $tester->getDisplay());
}
public function testNoHosts()
@ -130,6 +130,6 @@ class ListCommandTest extends TestCase
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertStringContainsString('No hosts defined', $tester->getDisplay());
$this->assertContains('No hosts defined', $tester->getDisplay());
}
}

8
tests/Command/BuiltIn/Releases/RollbackCommandTest.php Executable file → Normal file
View file

@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Releases\RollbackCommand;
use Mage\Command\AbstractCommand;
use Mage\Tests\MageApplicationMockup;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class RollbackCommandTest extends TestCase
{
@ -57,7 +57,7 @@ class RollbackCommandTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'developers', 'release' => '20170101015115']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertStringContainsString('The environment "developers" does not exists.', $tester->getDisplay());
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
}
public function testRollbackReleaseWithoutReleases()
@ -72,7 +72,7 @@ class RollbackCommandTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertStringContainsString('Releases are not enabled', $tester->getDisplay());
$this->assertContains('Releases are not enabled', $tester->getDisplay());
}
public function testRollbackReleaseNotAvailable()
@ -87,6 +87,6 @@ class RollbackCommandTest extends TestCase
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertStringContainsString('Release "20170101015115" is not available on all hosts', $tester->getDisplay());
$this->assertContains('Release "20170101015115" is not available on all hosts', $tester->getDisplay());
}
}

View file

@ -15,7 +15,7 @@ use Mage\Command\BuiltIn\VersionCommand;
use Mage\Tests\MageApplicationMockup;
use Mage\Mage;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class VersionCommandTest extends TestCase
{

23
tests/Deploy/StrategyTest.php Executable file → Normal file
View file

@ -15,7 +15,7 @@ use Mage\Deploy\Strategy\RsyncStrategy;
use Mage\Runtime\Exception\RuntimeException;
use Mage\Runtime\Runtime;
use Exception;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class StrategyTest extends TestCase
{
@ -31,7 +31,7 @@ class StrategyTest extends TestCase
$rsync->getPreDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
}
try {
@ -39,7 +39,7 @@ class StrategyTest extends TestCase
$rsync->getOnDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
}
try {
@ -47,7 +47,7 @@ class StrategyTest extends TestCase
$rsync->getOnReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
}
try {
@ -55,7 +55,7 @@ class StrategyTest extends TestCase
$rsync->getPostReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
}
try {
@ -63,7 +63,7 @@ class StrategyTest extends TestCase
$rsync->getPostDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
}
}
@ -79,7 +79,7 @@ class StrategyTest extends TestCase
$releases->getPreDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
}
try {
@ -87,7 +87,7 @@ class StrategyTest extends TestCase
$releases->getOnDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
}
try {
@ -95,7 +95,7 @@ class StrategyTest extends TestCase
$releases->getOnReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
}
try {
@ -103,7 +103,7 @@ class StrategyTest extends TestCase
$releases->getPostReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
}
try {
@ -111,7 +111,8 @@ class StrategyTest extends TestCase
$releases->getPostDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
}
}
}

View file

@ -20,7 +20,7 @@ class MageApplicationMockup extends MageApplication
*
* @return RuntimeMockup
*/
protected function instantiateRuntime(): RuntimeMockup
protected function instantiateRuntime()
{
return new RuntimeMockup();
}

4
tests/MageApplicationTest.php Executable file → Normal file
View file

@ -14,7 +14,7 @@ use Mage\MageApplication;
use Mage\Runtime\Exception\RuntimeException;
use Symfony\Component\Console\Tester\ApplicationTester;
use Exception;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class MageApplicationTest extends TestCase
{
@ -73,6 +73,6 @@ class MageApplicationTest extends TestCase
$tester = new ApplicationTester($application);
$tester->run(['command' => 'foo']);
$this->assertStringContainsString('Oops, exception thrown while running command foo', $tester->getDisplay());
$this->assertContains('Oops, exception thrown while running command foo', $tester->getDisplay());
}
}

View file

@ -1,28 +0,0 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Tests;
use Mage\Tests\Runtime\RuntimeWindowsMockup;
use Mage\MageApplication;
use Mage\Runtime\Runtime;
class MageApplicationWindowsMockup extends MageApplication
{
/**
* Gets the Runtime instance to use
*
* @return RuntimeWindowsMockup
*/
protected function instantiateRuntime(): Runtime
{
return new RuntimeWindowsMockup();
}
}

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
production:
user: app
@ -21,7 +21,7 @@ magephp:
on-deploy:
- symfony/cache-warmup: { env: 'dev' }
- symfony/assets-install: { env: 'dev' }
- symfony/cache-pool-prune: { env: 'dev' }
- symfony/assetic-dump: { env: 'dev' }
on-release:
post-release:
post-deploy:
post-deploy:

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
composer:
path: /usr/bin/composer.phar
environments:

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
composer:
path: /usr/bin/composer.phar
environments:

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
composer:
path: /usr/bin/composer.phar
exclude:

View file

@ -21,7 +21,7 @@ magephp:
on-deploy:
- symfony/cache-warmup: { env: 'dev' }
- symfony/assets-install: { env: 'dev' }
- symfony/cache-pool-prune: { env: 'dev' }
- symfony/assetic-dump: { env: 'dev' }
on-release:
post-release:
post-deploy:

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester
@ -17,7 +17,7 @@ magephp:
on-deploy:
- symfony/cache-warmup: { env: 'dev' }
- symfony/assets-install: { env: 'dev' }
- symfony/cache-pool-prune: { env: 'dev' }
- symfony/assetic-dump: { env: 'dev' }
on-release:
post-release:
post-deploy:
post-deploy:

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
symfony: { env: 'testenv' }
@ -14,7 +14,5 @@ magephp:
on-deploy:
- symfony/cache-warmup
- symfony/assets-install
- symfony/cache-pool-prune
- symfony/cache-pool-prune: { env: 'prod' }
- symfony/cache-pool-clear: { pools: 'main' }
- symfony/cache-pool-clear: { env: 'prod', pools: 'main' }
- symfony/assetic-dump
- symfony/assetic-dump: { env: 'prod' }

View file

@ -1,28 +0,0 @@
magephp:
log_dir: .logs/
environments:
test:
user: tester
branch: test
host_path: /var/www/test
releases: 4
symlink: prod
exclude:
- ./var/cache/*
- ./var/log/*
- ./web/app_dev.php
-
-
hosts:
- testhost
pre-deploy:
- git/update
- composer/install
- composer/dump-autoload
on-deploy:
- symfony/cache-warmup: { env: 'dev' }
- symfony/assets-install: { env: 'dev' }
- symfony/cache-pool-prune: { env: 'dev' }
on-release:
post-release:
post-deploy:

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester
@ -17,4 +17,4 @@ magephp:
- Mage\Tests\Task\CustomTask
on-release:
post-release:
post-deploy:
post-deploy:

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester
@ -12,4 +12,4 @@ magephp:
hosts:
- host2
on-deploy:
- deploy/release
- deploy/release

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester
@ -12,4 +12,4 @@ magephp:
hosts:
- host2
pre-deploy:
- deploy/tar/prepare
- deploy/tar/prepare

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester
@ -12,4 +12,4 @@ magephp:
hosts:
- host2
on-deploy:
- deploy/tar/copy
- deploy/tar/copy

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester
@ -12,4 +12,4 @@ magephp:
hosts:
- host2
post-deploy:
- deploy/tar/cleanup
- deploy/tar/cleanup

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

View file

@ -1,5 +1,5 @@
magephp:
log_dir: .logs/
log_dir: /tmp
environments:
test:
user: tester

Some files were not shown because too many files have changed in this diff Show more