mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-16 12:35:04 +02:00
Compare commits
141 commits
Author | SHA1 | Date | |
---|---|---|---|
c3ac15bfb9 | |||
40501f3d08 | |||
d32fa10a75 | |||
3fb2a15321 | |||
bb2ee8d279 | |||
d4db0ea4b6 | |||
0ccc2bbe45 | |||
a41e07eba6 | |||
1183907409 | |||
223bd680cf | |||
5d2ab6fa64 | |||
b80efc1e09 | |||
0d17d6b345 | |||
b893e102c6 | |||
2783292899 | |||
a370c1c0c9 | |||
fc8da5b229 | |||
d3023a6767 | |||
732b5d9cb6 | |||
ca808e4853 | |||
728f70fe6d | |||
2e04ed9fe1 | |||
47cb64137c | |||
e6ec044230 | |||
23b1794321 | |||
a3ce2679e6 | |||
9a46f89266 | |||
d6432d732a | |||
5f2646fe74 | |||
e7afcbfedf | |||
373ce5d761 | |||
b7ade4d2de | |||
9e4747947b | |||
eae991dc60 | |||
d1a89c6934 | |||
35bd3805e4 | |||
82a34a8c49 | |||
db1c5ba4ed | |||
1f8bd55483 | |||
1e82d85c6e | |||
7363a84853 | |||
e78049388e | |||
3a4129a7b5 | |||
f2239b6156 | |||
ac9178a05f | |||
3e4a6deff8 | |||
ddc3825e76 | |||
94eeb9cb9d | |||
695dfc5ff2 | |||
df248dd1b0 | |||
3f22cc6288 | |||
31a3941d11 | |||
e30de6b719 | |||
6563efb077 | |||
e73b97270c | |||
b4f613067e | |||
3dc7acf3d4 | |||
83110941eb | |||
05d9cf0b80 | |||
23dae99c1a | |||
27923f3e76 | |||
5fa99c68f5 | |||
7860fea425 | |||
b5f181bb18 | |||
50ddf081fb | |||
4232059d7e | |||
bab5e164a5 | |||
ceb07a306f | |||
1c654e4eac | |||
8db7a005f6 | |||
08dce880be | |||
b13b3f92b6 | |||
3ed4c758c0 | |||
621bb8e8df | |||
b62ae49bb0 | |||
c8d8689622 | |||
4735f0c51e | |||
26150f4e60 | |||
dbbb35fa70 | |||
3a2c00dbcb | |||
66191b7088 | |||
21bcdf76cc | |||
280f48cd18 | |||
46684ea649 | |||
b075430ec4 | |||
7c87fb4695 | |||
8a10e61c83 | |||
13658f2792 | |||
aa9793999a | |||
c14e3bc710 | |||
0d3c595b18 | |||
0fe106610a | |||
d95e498f54 | |||
591ac04229 | |||
c649814158 | |||
ef72936c52 | |||
ddee3f0226 | |||
261015981b | |||
88afbc76f9 | |||
49b96e00a8 | |||
32cd0aff02 | |||
5f0b5d86c7 | |||
91f246b579 | |||
2a9134cc35 | |||
1ebe6c4ba7 | |||
7dd445dc82 | |||
c5125f7940 | |||
f603adfb64 | |||
97911357c3 | |||
fc851dd661 | |||
2e7caa8229 | |||
b45d85c030 | |||
9d6163669a | |||
67c3a23bbb | |||
f7448e39e7 | |||
d8f2359d12 | |||
5054fb45d0 | |||
f6886f3d28 | |||
2c087ab477 | |||
55faaaa8f0 | |||
abf10b05f8 | |||
83f047aab0 | |||
5f4236c208 | |||
7c2f24b4c4 | |||
db1a1fd9b8 | |||
efdf816c7e | |||
50354a3624 | |||
eba1e61d47 | |||
33364f5e24 | |||
49d5587127 | |||
b36f90e80a | |||
35e835f0c9 | |||
e2bb29334d | |||
c6ec69b7f2 | |||
fef0fee920 | |||
67e3291375 | |||
18fd988c21 | |||
532a3146b0 | |||
b09089c270 | |||
b2099105fc | |||
dc48f19b26 |
32
.github/workflows/linters.yml
vendored
Normal file
32
.github/workflows/linters.yml
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
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
|
46
.github/workflows/tests.yml
vendored
Normal file
46
.github/workflows/tests.yml
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
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
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,3 +1,7 @@
|
||||||
/vendor/
|
/vendor/
|
||||||
/build
|
/build
|
||||||
composer.lock
|
composer.lock
|
||||||
|
.mage.yml
|
||||||
|
.phpunit.result.cache
|
||||||
|
.phpcs-cache
|
||||||
|
.logs
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
language: php
|
language: php
|
||||||
php:
|
php:
|
||||||
- '5.5'
|
- '8.0'
|
||||||
- '5.6'
|
- '8.1'
|
||||||
- '7.0'
|
|
||||||
- '7.1'
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- composer install
|
- composer install
|
||||||
|
|
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -1,8 +1,15 @@
|
||||||
CHANGELOG for 3.x
|
CHANGELOG for 5.X
|
||||||
=================
|
=================
|
||||||
|
|
||||||
* 3.0.1 (2017-01-10)
|
* 5.0.0 (2022-04-15)
|
||||||
* [BUGFIX] [#350] [#353] Fix escape issue when commands are sent through SSH
|
* v5 series release.
|
||||||
|
* Refactored for Symfony 6 and PHP 8.
|
||||||
* 3.0.0 (2017-01-31)
|
* Added strong types.
|
||||||
* v3 series release
|
* 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].
|
||||||
|
|
|
@ -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
|
1. Write clean code with no mess left
|
||||||
2. Contribute the docs when adding configurable new feature
|
2. Contribute the docs when adding configurable new feature
|
||||||
3. Create your pull request from `nostromo` branch
|
3. Create your pull request from `galactica` branch
|
||||||
4. Ensure your code is fully covered by tests
|
4. Ensure your code is fully covered by tests
|
||||||
|
|
||||||
----------
|
----------
|
||||||
|
@ -28,39 +28,36 @@ In order to have the PRs prioritized name them with the following tags.
|
||||||
[FEATURE] Create new PermissionsTask
|
[FEATURE] Create new PermissionsTask
|
||||||
[HOTFIX] Exception not caught on deployment
|
[HOTFIX] Exception not caught on deployment
|
||||||
```
|
```
|
||||||
All Pull Requests must be done to the `nostromo` branch, only exception are Hotfixes.
|
All Pull Requests must be done to the `galactica` 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!
|
Remember of square brackets when adding issue number. If you'd forget adding them, your whole message will be a comment!
|
||||||
|
|
||||||
# Developing Magallanes
|
# Developing Magallanes
|
||||||
## Branches
|
## Branches
|
||||||
The flow is pretty simple.
|
The flow is pretty simple.
|
||||||
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.
|
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.
|
||||||
|
|
||||||
If you want to use developing branch in your code, simple pass `dev-nostromo` to dependency version in your `composer.json` file:
|
If you want to use developing branch in your code, simple pass `dev-galactica` to dependency version in your `composer.json` file:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"andres-montanez/magallanes": "dev-nostromo"
|
"andres-montanez/magallanes": "dev-galactica"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Organization and code quality
|
## Organization and code quality
|
||||||
We use [PSR2](http://www.php-fig.org/psr/psr-2/) as PHP coding standard.
|
We use [PSR-12](http://www.php-fig.org/psr/psr-12/) as PHP coding standard.
|
||||||
|
|
||||||
### Tools you can use to ensure your code quality
|
### Tools you can use to ensure your code quality
|
||||||
|
|
||||||
1. PHP-CodeSniffer
|
1. PHPStan `./vendor/bin/phpstan analyse`
|
||||||
2. [PHP Mess Detector](https://phpmd.org/)
|
2. PHP Code Sniffer `./vendor/bin/phpcs`
|
||||||
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
|
## 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:
|
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
|
./vendor/bin/phpunit --coverage-clover build/logs/coverage.xml --coverage-text
|
||||||
vendor/bin/coveralls -v --coverage_clover build/logs/coverage.xml
|
./vendor/bin/php-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.
|
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.
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2011 - 2017 Andrés Montañez
|
Copyright (c) 2011 - 2022 Andrés Montañez
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any
|
Permission is hereby granted, free of charge, to any
|
||||||
person obtaining a copy of this software and associated
|
person obtaining a copy of this software and associated
|
||||||
|
|
25
README.md
25
README.md
|
@ -1,6 +1,6 @@
|
||||||
# Magallanes #
|
# Magallanes
|
||||||
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/ed0de53a-a12e-459b-9464-34def5907b56.svg?label=insight)](https://insight.sensiolabs.com/projects/ed0de53a-a12e-459b-9464-34def5907b56)
|
![Linters](https://github.com/andres-montanez/Magallanes/actions/workflows/linters.yml/badge.svg?)
|
||||||
[![Build Status](https://img.shields.io/travis/andres-montanez/Magallanes/master.svg)](https://travis-ci.org/andres-montanez/Magallanes)
|
![Tests](https://github.com/andres-montanez/Magallanes/actions/workflows/tests.yml/badge.svg?)
|
||||||
[![Coverage Status](https://img.shields.io/coveralls/andres-montanez/Magallanes/master.svg)](https://coveralls.io/github/andres-montanez/Magallanes?branch=master)
|
[![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/)
|
[![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)
|
[![Latest Stable Version](https://img.shields.io/packagist/v/andres-montanez/magallanes.svg?label=stable)](https://packagist.org/packages/andres-montanez/magallanes)
|
||||||
|
@ -8,25 +8,22 @@
|
||||||
[![Total Downloads](https://img.shields.io/packagist/dt/andres-montanez/magallanes.svg)](https://packagist.org/packages/andres-montanez/magallanes)
|
[![Total Downloads](https://img.shields.io/packagist/dt/andres-montanez/magallanes.svg)](https://packagist.org/packages/andres-montanez/magallanes)
|
||||||
[![License](https://img.shields.io/packagist/l/andres-montanez/magallanes.svg)](https://packagist.org/packages/andres-montanez/magallanes)
|
[![License](https://img.shields.io/packagist/l/andres-montanez/magallanes.svg)](https://packagist.org/packages/andres-montanez/magallanes)
|
||||||
|
|
||||||
### What's 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 http://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 [magephp.com](https://www.magephp.com/)
|
||||||
|
|
||||||
### Installing ###
|
### Installing
|
||||||
Simply add the following dependency to your project’s composer.json file:
|
Simply add the following dependency to your project’s composer.json file:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"require": {
|
"require-dev": {
|
||||||
"andres-montanez/magallanes": "^3.0"
|
"andres-montanez/magallanes": "^5.0"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Finally you can use **Magallanes** from the vendor's bin:
|
Finally you can use **Magallanes** from the vendor's bin:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ vendor/bin/mage version
|
vendor/bin/mage version
|
||||||
```
|
```
|
||||||
|
|
||||||
### What happend to version 2? ###
|
### Codename Galactica
|
||||||
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.
|
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.
|
||||||
|
|
||||||
### 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)*.
|
|
||||||
|
|
3
bin/mage
3
bin/mage
|
@ -11,7 +11,8 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) {
|
||||||
use Mage\MageApplication;
|
use Mage\MageApplication;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$mage = new MageApplication('.mage.yml');
|
$file = sprintf('%s/.mage.yml', getcwd());
|
||||||
|
$mage = new MageApplication($file);
|
||||||
$mage->run();
|
$mage->run();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
printf('Error: %s' . PHP_EOL, $exception->getMessage());
|
printf('Error: %s' . PHP_EOL, $exception->getMessage());
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "andres-montanez/magallanes",
|
"name": "andres-montanez/magallanes",
|
||||||
"description": "The Deployment Tool for PHP Applications",
|
"description": "The Deployment Tool for PHP Applications",
|
||||||
"homepage": "http://magephp.com",
|
"homepage": "https://magephp.com",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"keywords": ["deployment"],
|
"keywords": ["deployment"],
|
||||||
|
@ -12,18 +12,23 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5.9",
|
"php": "^8.0",
|
||||||
"monolog/monolog": "^1.0",
|
"monolog/monolog": "^2.5",
|
||||||
"symfony/console": "^3.0",
|
"symfony/console": "^6.0",
|
||||||
"symfony/filesystem": "^3.0",
|
"symfony/filesystem": "^6.0",
|
||||||
"symfony/event-dispatcher": "^3.0",
|
"symfony/event-dispatcher": "^6.0",
|
||||||
"symfony/finder": "^3.0",
|
"symfony/finder": "^6.0",
|
||||||
"symfony/yaml": "^3.0",
|
"symfony/yaml": "^6.0",
|
||||||
"symfony/process": "^3.0"
|
"symfony/process": "^6.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "4.8.*",
|
"phpunit/phpunit": "^9.5",
|
||||||
"satooshi/php-coveralls": "~1.0"
|
"phpstan/phpstan": "^1.5",
|
||||||
|
"squizlabs/php_codesniffer": "^3.6",
|
||||||
|
"php-coveralls/php-coveralls": "^2.5"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-posix": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -38,8 +43,8 @@
|
||||||
"bin": ["bin/mage"],
|
"bin": ["bin/mage"],
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "3.0.x-dev",
|
"dev-master": "5.0.x-dev",
|
||||||
"dev-nostromo": "3.x-dev"
|
"dev-galactica": "5.x-dev"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
7
docs/dockers/docker-compose.yml
Normal file
7
docs/dockers/docker-compose.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
version: '2'
|
||||||
|
services:
|
||||||
|
php8.0:
|
||||||
|
container_name: mage-php8.0
|
||||||
|
build: ./php8.0
|
||||||
|
volumes:
|
||||||
|
- ../../:/home/magephp
|
12
docs/dockers/php8.0/Dockerfile
Normal file
12
docs/dockers/php8.0/Dockerfile
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
FROM ubuntu:21.10
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
|
TZ=UTC
|
||||||
|
|
||||||
|
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 curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
|
||||||
|
|
||||||
|
WORKDIR /home/magephp
|
|
@ -3,13 +3,12 @@ magephp:
|
||||||
production:
|
production:
|
||||||
user: app
|
user: app
|
||||||
branch: test
|
branch: test
|
||||||
|
from: ./
|
||||||
host_path: /var/www/test
|
host_path: /var/www/test
|
||||||
releases: 4
|
releases: 4
|
||||||
exclude:
|
exclude:
|
||||||
- vendor
|
- var/cache
|
||||||
- app/cache
|
- var/log
|
||||||
- app/log
|
|
||||||
- web/app_dev.php
|
|
||||||
hosts:
|
hosts:
|
||||||
- webserver1
|
- webserver1
|
||||||
- webserver2
|
- webserver2
|
||||||
|
@ -17,11 +16,14 @@ magephp:
|
||||||
pre-deploy:
|
pre-deploy:
|
||||||
- git/update
|
- git/update
|
||||||
- composer/install
|
- composer/install
|
||||||
- composer/generate-autoload
|
- composer/dump-autoload
|
||||||
on-deploy:
|
on-deploy:
|
||||||
- symfony/cache-warmup: { env: 'dev' }
|
- symfony/cache-warmup: { env: 'prod' }
|
||||||
- symfony/assets-install: { env: 'dev' }
|
- symfony/assets-install: { env: 'prod' }
|
||||||
- symfony/assetic-dump: { env: 'dev' }
|
- symfony/assetic-dump: { env: 'prod' }
|
||||||
on-release:
|
on-release:
|
||||||
post-release:
|
post-release:
|
||||||
post-deploy:
|
post-deploy:
|
||||||
|
- magic
|
||||||
|
custom_tasks:
|
||||||
|
- App\Deployment\MagicTask
|
||||||
|
|
14
phpcs.xml.dist
Normal file
14
phpcs.xml.dist
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?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>
|
4
phpstan.neon
Normal file
4
phpstan.neon
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
parameters:
|
||||||
|
level: 6
|
||||||
|
paths:
|
||||||
|
- src
|
|
@ -1,37 +1,28 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<coverage>
|
||||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
|
<include>
|
||||||
backupGlobals="false"
|
<directory>./src/</directory>
|
||||||
colors="true"
|
</include>
|
||||||
bootstrap="vendor/autoload.php"
|
<exclude>
|
||||||
>
|
<directory>./tests/</directory>
|
||||||
<php>
|
</exclude>
|
||||||
<ini name="error_reporting" value="-1" />
|
</coverage>
|
||||||
<ini name="intl.default_locale" value="en" />
|
<php>
|
||||||
<ini name="intl.error_level" value="0" />
|
<ini name="error_reporting" value="-1"/>
|
||||||
<ini name="memory_limit" value="-1" />
|
<ini name="intl.default_locale" value="en"/>
|
||||||
</php>
|
<ini name="intl.error_level" value="0"/>
|
||||||
|
<ini name="memory_limit" value="-1"/>
|
||||||
<testsuites>
|
</php>
|
||||||
<testsuite name="Magallanes Test Suite">
|
<testsuites>
|
||||||
<directory>./tests/</directory>
|
<testsuite name="Magallanes Test Suite">
|
||||||
</testsuite>
|
<directory>./tests/</directory>
|
||||||
</testsuites>
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
<groups>
|
<groups>
|
||||||
<exclude>
|
<exclude>
|
||||||
<group>benchmark</group>
|
<group>benchmark</group>
|
||||||
<group>intl-data</group>
|
<group>intl-data</group>
|
||||||
</exclude>
|
</exclude>
|
||||||
</groups>
|
</groups>
|
||||||
|
|
||||||
<filter>
|
|
||||||
<whitelist>
|
|
||||||
<directory>./src/</directory>
|
|
||||||
<exclude>
|
|
||||||
<directory>./tests/</directory>
|
|
||||||
</exclude>
|
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -23,46 +24,30 @@ use Symfony\Component\Console\Command\Command;
|
||||||
*/
|
*/
|
||||||
abstract class AbstractCommand extends Command
|
abstract class AbstractCommand extends Command
|
||||||
{
|
{
|
||||||
/**
|
protected int $statusCode = 0;
|
||||||
* @var int
|
protected Runtime $runtime;
|
||||||
*/
|
|
||||||
protected $statusCode = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Runtime Current Runtime instance
|
|
||||||
*/
|
|
||||||
protected $runtime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Runtime configuration
|
* Set the Runtime configuration
|
||||||
*
|
|
||||||
* @param Runtime $runtime Runtime container
|
|
||||||
* @return AbstractCommand
|
|
||||||
*/
|
*/
|
||||||
public function setRuntime(Runtime $runtime)
|
public function setRuntime(Runtime $runtime): self
|
||||||
{
|
{
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a message
|
* Logs a message
|
||||||
*
|
|
||||||
* @param string $message
|
|
||||||
* @param string $level
|
|
||||||
*/
|
*/
|
||||||
public function log($message, $level = LogLevel::DEBUG)
|
public function log(string $message, string $level = LogLevel::DEBUG): void
|
||||||
{
|
{
|
||||||
$this->runtime->log($message, $level);
|
$this->runtime->log($message, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Human friendly Stage name
|
* Get the Human friendly Stage name
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
protected function getStageName()
|
protected function getStageName(): string
|
||||||
{
|
{
|
||||||
$utils = new Utils();
|
$utils = new Utils();
|
||||||
return $utils->getStageName($this->runtime->getStage());
|
return $utils->getStageName($this->runtime->getStage());
|
||||||
|
@ -71,7 +56,7 @@ abstract class AbstractCommand extends Command
|
||||||
/**
|
/**
|
||||||
* Requires the configuration to be loaded
|
* Requires the configuration to be loaded
|
||||||
*/
|
*/
|
||||||
protected function requireConfig()
|
protected function requireConfig(): void
|
||||||
{
|
{
|
||||||
$app = $this->getApplication();
|
$app = $this->getApplication();
|
||||||
if ($app instanceof MageApplication) {
|
if ($app instanceof MageApplication) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -24,22 +25,17 @@ class DumpCommand extends AbstractCommand
|
||||||
/**
|
/**
|
||||||
* Configure the Command
|
* Configure the Command
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('config:dump')
|
->setName('config:dump')
|
||||||
->setDescription('Dumps the Magallanes configuration')
|
->setDescription('Dumps the Magallanes configuration');
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the Command
|
* Execute the Command
|
||||||
*
|
|
||||||
* @param InputInterface $input
|
|
||||||
* @param OutputInterface $output
|
|
||||||
* @return int|mixed
|
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$this->requireConfig();
|
$this->requireConfig();
|
||||||
|
|
||||||
|
@ -51,6 +47,6 @@ class DumpCommand extends AbstractCommand
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
$output->writeln('Finished <fg=blue>Magallanes</>');
|
$output->writeln('Finished <fg=blue>Magallanes</>');
|
||||||
|
|
||||||
return 0;
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -25,22 +26,17 @@ class EnvironmentsCommand extends AbstractCommand
|
||||||
/**
|
/**
|
||||||
* Configure the Command
|
* Configure the Command
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('config:environments')
|
->setName('config:environments')
|
||||||
->setDescription('List all Magallanes configured Environments')
|
->setDescription('List all Magallanes configured Environments');
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the Command
|
* Execute the Command
|
||||||
*
|
|
||||||
* @param InputInterface $input
|
|
||||||
* @param OutputInterface $output
|
|
||||||
* @return int|mixed
|
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$this->requireConfig();
|
$this->requireConfig();
|
||||||
|
|
||||||
|
@ -66,6 +62,6 @@ class EnvironmentsCommand extends AbstractCommand
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
$output->writeln('Finished <fg=blue>Magallanes</>');
|
$output->writeln('Finished <fg=blue>Magallanes</>');
|
||||||
|
|
||||||
return 0;
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -31,32 +32,37 @@ use Mage\Command\AbstractCommand;
|
||||||
*/
|
*/
|
||||||
class DeployCommand extends AbstractCommand
|
class DeployCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
/**
|
protected TaskFactory $taskFactory;
|
||||||
* @var TaskFactory
|
|
||||||
*/
|
|
||||||
protected $taskFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the Command
|
* Configure the Command
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('deploy')
|
->setName('deploy')
|
||||||
->setDescription('Deploy code to hosts')
|
->setDescription('Deploy code to hosts')
|
||||||
->addArgument('environment', InputArgument::REQUIRED, 'Name of the environment to deploy to')
|
->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(
|
||||||
;
|
'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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the Command
|
* Execute the Command
|
||||||
*
|
|
||||||
* @param InputInterface $input
|
|
||||||
* @param OutputInterface $output
|
|
||||||
* @return integer
|
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$this->requireConfig();
|
$this->requireConfig();
|
||||||
|
|
||||||
|
@ -84,14 +90,25 @@ class DeployCommand extends AbstractCommand
|
||||||
|
|
||||||
$output->writeln(sprintf(' Strategy: <fg=green>%s</>', $strategy->getName()));
|
$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) {
|
if ($input->getOption('branch') !== false) {
|
||||||
$this->runtime->setEnvOption('branch', $input->getOption('branch'));
|
$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)) {
|
if ($this->runtime->getEnvOption('branch', false)) {
|
||||||
$output->writeln(sprintf(' Branch: <fg=green>%s</>', $this->runtime->getEnvOption('branch')));
|
$output->writeln(sprintf(' Branch: <fg=green>%s</>', $this->runtime->getEnvOption('branch')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
$this->runDeployment($output, $strategy);
|
$this->runDeployment($output, $strategy);
|
||||||
} catch (RuntimeException $exception) {
|
} catch (RuntimeException $exception) {
|
||||||
|
@ -103,17 +120,15 @@ class DeployCommand extends AbstractCommand
|
||||||
|
|
||||||
$output->writeln('Finished <fg=blue>Magallanes</>');
|
$output->writeln('Finished <fg=blue>Magallanes</>');
|
||||||
|
|
||||||
return $this->statusCode;
|
return intval($this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the Deployment Process
|
* Run the Deployment Process
|
||||||
*
|
*
|
||||||
* @param OutputInterface $output
|
|
||||||
* @param StrategyInterface $strategy
|
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
protected function runDeployment(OutputInterface $output, StrategyInterface $strategy)
|
protected function runDeployment(OutputInterface $output, StrategyInterface $strategy): void
|
||||||
{
|
{
|
||||||
// Run "Pre Deploy" Tasks
|
// Run "Pre Deploy" Tasks
|
||||||
$this->runtime->setStage(Runtime::PRE_DEPLOY);
|
$this->runtime->setStage(Runtime::PRE_DEPLOY);
|
||||||
|
@ -140,13 +155,20 @@ class DeployCommand extends AbstractCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function runOnHosts(OutputInterface $output, $tasks)
|
/**
|
||||||
|
* @param string[] $tasks
|
||||||
|
*/
|
||||||
|
protected function runOnHosts(OutputInterface $output, array $tasks): void
|
||||||
{
|
{
|
||||||
$hosts = $this->runtime->getEnvOption('hosts');
|
$hosts = $this->runtime->getEnvOption('hosts');
|
||||||
if (count($hosts) == 0) {
|
if (!is_array($hosts) && !$hosts instanceof \Countable) {
|
||||||
|
$hosts = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($hosts) === 0) {
|
||||||
$output->writeln(sprintf(' No hosts defined, skipping %s tasks', $this->getStageName()));
|
$output->writeln(sprintf(' No hosts defined, skipping %s tasks', $this->getStageName()));
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($hosts as $host) {
|
foreach ($hosts as $host) {
|
||||||
|
@ -162,21 +184,27 @@ class DeployCommand extends AbstractCommand
|
||||||
/**
|
/**
|
||||||
* Runs all the tasks
|
* Runs all the tasks
|
||||||
*
|
*
|
||||||
* @param OutputInterface $output
|
* @param string[] $tasks
|
||||||
* @param $tasks
|
|
||||||
* @return bool
|
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
protected function runTasks(OutputInterface $output, $tasks)
|
protected function runTasks(OutputInterface $output, array $tasks): bool
|
||||||
{
|
{
|
||||||
if (count($tasks) == 0) {
|
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('');
|
$output->writeln('');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->runtime->getWorkingHost() !== null) {
|
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->getWorkingHost()));
|
$output->writeln(
|
||||||
|
sprintf(
|
||||||
|
' Starting <fg=black;options=bold>%s</> tasks on host <fg=black;options=bold>%s</>:',
|
||||||
|
$this->getStageName(),
|
||||||
|
$this->runtime->getHostName()
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$output->writeln(sprintf(' Starting <fg=black;options=bold>%s</> tasks:', $this->getStageName()));
|
$output->writeln(sprintf(' Starting <fg=black;options=bold>%s</> tasks:', $this->getStageName()));
|
||||||
}
|
}
|
||||||
|
@ -185,7 +213,6 @@ class DeployCommand extends AbstractCommand
|
||||||
$succeededTasks = 0;
|
$succeededTasks = 0;
|
||||||
|
|
||||||
foreach ($tasks as $taskName) {
|
foreach ($tasks as $taskName) {
|
||||||
/** @var AbstractTask $task */
|
|
||||||
$task = $this->taskFactory->get($taskName);
|
$task = $this->taskFactory->get($taskName);
|
||||||
$output->write(sprintf(' Running <fg=magenta>%s</> ... ', $task->getDescription()));
|
$output->write(sprintf(' Running <fg=magenta>%s</> ... ', $task->getDescription()));
|
||||||
$this->log(sprintf('Running task %s (%s)', $task->getDescription(), $task->getName()));
|
$this->log(sprintf('Running task %s (%s)', $task->getDescription(), $task->getName()));
|
||||||
|
@ -193,25 +220,48 @@ class DeployCommand extends AbstractCommand
|
||||||
if ($this->runtime->inRollback() && !$task instanceof ExecuteOnRollbackInterface) {
|
if ($this->runtime->inRollback() && !$task instanceof ExecuteOnRollbackInterface) {
|
||||||
$succeededTasks++;
|
$succeededTasks++;
|
||||||
$output->writeln('<fg=yellow>SKIPPED</>');
|
$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 {
|
} else {
|
||||||
try {
|
try {
|
||||||
if ($task->execute()) {
|
if ($task->execute()) {
|
||||||
$succeededTasks++;
|
$succeededTasks++;
|
||||||
$output->writeln('<fg=green>OK</>');
|
$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 {
|
} else {
|
||||||
$output->writeln('<fg=red>FAIL</>');
|
$output->writeln('<fg=red>FAIL</>');
|
||||||
$this->statusCode = 180;
|
$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) {
|
} catch (SkipException $exception) {
|
||||||
$succeededTasks++;
|
$succeededTasks++;
|
||||||
$output->writeln('<fg=yellow>SKIPPED</>');
|
$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) {
|
} catch (ErrorException $exception) {
|
||||||
$output->writeln(sprintf('<fg=red>ERROR</> [%s]', $exception->getTrimmedMessage()));
|
$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;
|
$this->statusCode = 190;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +276,15 @@ class DeployCommand extends AbstractCommand
|
||||||
$alertColor = 'green';
|
$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('');
|
$output->writeln('');
|
||||||
|
|
||||||
return ($succeededTasks == $totalTasks);
|
return ($succeededTasks == $totalTasks);
|
||||||
|
@ -235,8 +293,11 @@ class DeployCommand extends AbstractCommand
|
||||||
/**
|
/**
|
||||||
* Exception for halting the the current process
|
* Exception for halting the the current process
|
||||||
*/
|
*/
|
||||||
protected function getException()
|
protected function getException(): RuntimeException
|
||||||
{
|
{
|
||||||
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -25,31 +26,21 @@ use Mage\Command\AbstractCommand;
|
||||||
*/
|
*/
|
||||||
class ListCommand extends AbstractCommand
|
class ListCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $statusCode = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the Command
|
* Configure the Command
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('releases:list')
|
->setName('releases:list')
|
||||||
->setDescription('List the releases on an environment')
|
->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
|
* Execute the Command
|
||||||
*
|
|
||||||
* @param InputInterface $input
|
|
||||||
* @param OutputInterface $output
|
|
||||||
* @return int|mixed
|
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$this->requireConfig();
|
$this->requireConfig();
|
||||||
|
|
||||||
|
@ -74,6 +65,9 @@ class ListCommand extends AbstractCommand
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
|
|
||||||
$hosts = $this->runtime->getEnvOption('hosts');
|
$hosts = $this->runtime->getEnvOption('hosts');
|
||||||
|
if (!is_array($hosts) && !$hosts instanceof \Countable) {
|
||||||
|
$hosts = [];
|
||||||
|
}
|
||||||
if (count($hosts) == 0) {
|
if (count($hosts) == 0) {
|
||||||
$output->writeln('No hosts defined');
|
$output->writeln('No hosts defined');
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
|
@ -94,12 +88,14 @@ class ListCommand extends AbstractCommand
|
||||||
|
|
||||||
$releases = [];
|
$releases = [];
|
||||||
if (trim($process->getOutput()) != '') {
|
if (trim($process->getOutput()) != '') {
|
||||||
$releases = explode(PHP_EOL, trim($process->getOutput()));
|
$releases = explode("\n", trim($process->getOutput()));
|
||||||
rsort($releases);
|
rsort($releases);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($releases) == 0) {
|
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 {
|
} else {
|
||||||
// Get Current Release
|
// Get Current Release
|
||||||
$cmdCurrentRelease = sprintf('readlink -f %s/current', $hostPath);
|
$cmdCurrentRelease = sprintf('readlink -f %s/current', $hostPath);
|
||||||
|
@ -107,7 +103,10 @@ class ListCommand extends AbstractCommand
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runRemoteCommand($cmdCurrentRelease, false);
|
$process = $this->runtime->runRemoteCommand($cmdCurrentRelease, false);
|
||||||
if (!$process->isSuccessful()) {
|
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()));
|
$currentReleaseId = explode('/', trim($process->getOutput()));
|
||||||
|
@ -118,7 +117,8 @@ class ListCommand extends AbstractCommand
|
||||||
foreach ($releases as $releaseId) {
|
foreach ($releases as $releaseId) {
|
||||||
$releaseDate = $utils->getReleaseDate($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,
|
$releaseId,
|
||||||
$releaseDate->format('Y-m-d H:i:s'),
|
$releaseDate->format('Y-m-d H:i:s'),
|
||||||
$utils->getTimeDiff($releaseDate)
|
$utils->getTimeDiff($releaseDate)
|
||||||
|
@ -143,6 +143,6 @@ class ListCommand extends AbstractCommand
|
||||||
|
|
||||||
$output->writeln('Finished <fg=blue>Magallanes</>');
|
$output->writeln('Finished <fg=blue>Magallanes</>');
|
||||||
|
|
||||||
return $this->statusCode;
|
return intval($this->statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -25,32 +26,22 @@ use Mage\Command\BuiltIn\DeployCommand;
|
||||||
*/
|
*/
|
||||||
class RollbackCommand extends DeployCommand
|
class RollbackCommand extends DeployCommand
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $statusCode = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the Command
|
* Configure the Command
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('releases:rollback')
|
->setName('releases:rollback')
|
||||||
->setDescription('Rollback to a release on an environment')
|
->setDescription('Rollback to a release 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')
|
||||||
->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
|
* Execute the Command
|
||||||
*
|
|
||||||
* @param InputInterface $input
|
|
||||||
* @param OutputInterface $output
|
|
||||||
* @return int|mixed
|
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$this->requireConfig();
|
$this->requireConfig();
|
||||||
|
|
||||||
|
@ -68,11 +59,14 @@ class RollbackCommand extends DeployCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
$releaseToRollback = $input->getArgument('release');
|
$releaseToRollback = $input->getArgument('release');
|
||||||
if (($releaseId = $this->checkReleaseAvailability($releaseToRollback)) === false) {
|
if ($this->checkReleaseAvailability($releaseToRollback) === false) {
|
||||||
throw new RuntimeException(sprintf('Release "%s" is not available on all hosts', $releaseToRollback), 72);
|
throw new RuntimeException(
|
||||||
|
sprintf('Release "%s" is not available on all hosts', $releaseToRollback),
|
||||||
|
72
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->runtime->setReleaseId($releaseId)->setRollback(true);
|
$this->runtime->setReleaseId($releaseToRollback)->setRollback(true);
|
||||||
|
|
||||||
$output->writeln(sprintf(' Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
|
$output->writeln(sprintf(' Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
|
||||||
$this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));
|
$this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));
|
||||||
|
@ -95,16 +89,13 @@ class RollbackCommand extends DeployCommand
|
||||||
|
|
||||||
$output->writeln('Finished <fg=blue>Magallanes</>');
|
$output->writeln('Finished <fg=blue>Magallanes</>');
|
||||||
|
|
||||||
return $this->statusCode;
|
return intval($this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the provided Release ID is available in all hosts
|
* Check if the provided Release ID is available in all hosts
|
||||||
*
|
|
||||||
* @param string $releaseToRollback Release ID
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
protected function checkReleaseAvailability($releaseToRollback)
|
protected function checkReleaseAvailability(string $releaseToRollback): bool
|
||||||
{
|
{
|
||||||
$hosts = $this->runtime->getEnvOption('hosts');
|
$hosts = $this->runtime->getEnvOption('hosts');
|
||||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
|
@ -120,7 +111,7 @@ class RollbackCommand extends DeployCommand
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runRemoteCommand($cmdListReleases, false);
|
$process = $this->runtime->runRemoteCommand($cmdListReleases, false);
|
||||||
if ($process->isSuccessful()) {
|
if ($process->isSuccessful()) {
|
||||||
$releases = explode(PHP_EOL, trim($process->getOutput()));
|
$releases = explode("\n", trim($process->getOutput()));
|
||||||
rsort($releases);
|
rsort($releases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +123,7 @@ class RollbackCommand extends DeployCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($availableInHosts === count($hosts)) {
|
if ($availableInHosts === count($hosts)) {
|
||||||
return $releaseToRollback;
|
return (bool) $releaseToRollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -25,25 +26,20 @@ class VersionCommand extends AbstractCommand
|
||||||
/**
|
/**
|
||||||
* Configure the Command
|
* Configure the Command
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('version')
|
->setName('version')
|
||||||
->setDescription('Get the version of Magallanes')
|
->setDescription('Get the version of Magallanes');
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the Command
|
* Executes the Command
|
||||||
*
|
|
||||||
* @param InputInterface $input
|
|
||||||
* @param OutputInterface $output
|
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$output->writeln(sprintf('Magallanes v%s [%s]', Mage::VERSION, Mage::CODENAME));
|
$output->writeln(sprintf('Magallanes v%s [%s]', Mage::VERSION, Mage::CODENAME));
|
||||||
|
|
||||||
return 0;
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -20,27 +21,28 @@ use Mage\Runtime\Runtime;
|
||||||
*/
|
*/
|
||||||
class ReleasesStrategy implements StrategyInterface
|
class ReleasesStrategy implements StrategyInterface
|
||||||
{
|
{
|
||||||
/**
|
protected Runtime $runtime;
|
||||||
* @var Runtime
|
|
||||||
*/
|
|
||||||
protected $runtime;
|
|
||||||
|
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'Releases';
|
return 'Releases';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRuntime(Runtime $runtime)
|
public function setRuntime(Runtime $runtime): void
|
||||||
{
|
{
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPreDeployTasks()
|
public function getPreDeployTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::PRE_DEPLOY);
|
$this->checkStage(Runtime::PRE_DEPLOY);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
|
if (
|
||||||
|
($this->runtime->getBranch() || $this->runtime->getTag()) &&
|
||||||
|
!$this->runtime->inRollback() &&
|
||||||
|
!in_array('git/change-branch', $tasks)
|
||||||
|
) {
|
||||||
array_unshift($tasks, 'git/change-branch');
|
array_unshift($tasks, 'git/change-branch');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ class ReleasesStrategy implements StrategyInterface
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOnDeployTasks()
|
public function getOnDeployTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::ON_DEPLOY);
|
$this->checkStage(Runtime::ON_DEPLOY);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
@ -67,7 +69,7 @@ class ReleasesStrategy implements StrategyInterface
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOnReleaseTasks()
|
public function getOnReleaseTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::ON_RELEASE);
|
$this->checkStage(Runtime::ON_RELEASE);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
@ -79,7 +81,7 @@ class ReleasesStrategy implements StrategyInterface
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPostReleaseTasks()
|
public function getPostReleaseTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::POST_RELEASE);
|
$this->checkStage(Runtime::POST_RELEASE);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
@ -91,17 +93,21 @@ class ReleasesStrategy implements StrategyInterface
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPostDeployTasks()
|
public function getPostDeployTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::POST_DEPLOY);
|
$this->checkStage(Runtime::POST_DEPLOY);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if (!$this->runtime->inRollback() && !in_array('deploy/tar/cleanup', $tasks)) {
|
if (
|
||||||
array_unshift($tasks, 'deploy/tar/cleanup');
|
($this->runtime->getBranch() || $this->runtime->getTag()) &&
|
||||||
|
!$this->runtime->inRollback() &&
|
||||||
|
!in_array('git/change-branch', $tasks)
|
||||||
|
) {
|
||||||
|
array_unshift($tasks, 'git/change-branch');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
|
if (!$this->runtime->inRollback() && !in_array('deploy/tar/cleanup', $tasks)) {
|
||||||
array_push($tasks, 'git/change-branch');
|
array_unshift($tasks, 'deploy/tar/cleanup');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tasks;
|
return $tasks;
|
||||||
|
@ -110,13 +116,14 @@ class ReleasesStrategy implements StrategyInterface
|
||||||
/**
|
/**
|
||||||
* Check the runtime stage is correct
|
* Check the runtime stage is correct
|
||||||
*
|
*
|
||||||
* @param $stage
|
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
private function checkStage($stage)
|
private function checkStage(string $stage): void
|
||||||
{
|
{
|
||||||
if ($this->runtime->getStage() !== $stage) {
|
if ($this->runtime->getStage() !== $stage) {
|
||||||
throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage));
|
throw new RuntimeException(
|
||||||
|
sprintf('Invalid stage, got "%s" but expected "%s"', $this->runtime->getStage(), $stage)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -20,34 +21,35 @@ use Mage\Runtime\Runtime;
|
||||||
*/
|
*/
|
||||||
class RsyncStrategy implements StrategyInterface
|
class RsyncStrategy implements StrategyInterface
|
||||||
{
|
{
|
||||||
/**
|
protected Runtime $runtime;
|
||||||
* @var Runtime
|
|
||||||
*/
|
|
||||||
protected $runtime;
|
|
||||||
|
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'Rsync';
|
return 'Rsync';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRuntime(Runtime $runtime)
|
public function setRuntime(Runtime $runtime): void
|
||||||
{
|
{
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPreDeployTasks()
|
public function getPreDeployTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::PRE_DEPLOY);
|
$this->checkStage(Runtime::PRE_DEPLOY);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
|
if (
|
||||||
|
($this->runtime->getBranch() || $this->runtime->getTag()) &&
|
||||||
|
!$this->runtime->inRollback() &&
|
||||||
|
!in_array('git/change-branch', $tasks)
|
||||||
|
) {
|
||||||
array_unshift($tasks, 'git/change-branch');
|
array_unshift($tasks, 'git/change-branch');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOnDeployTasks()
|
public function getOnDeployTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::ON_DEPLOY);
|
$this->checkStage(Runtime::ON_DEPLOY);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
@ -59,22 +61,27 @@ class RsyncStrategy implements StrategyInterface
|
||||||
return $tasks;
|
return $tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOnReleaseTasks()
|
public function getOnReleaseTasks(): array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPostReleaseTasks()
|
public function getPostReleaseTasks(): array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPostDeployTasks()
|
public function getPostDeployTasks(): array
|
||||||
{
|
{
|
||||||
$this->checkStage(Runtime::POST_DEPLOY);
|
$this->checkStage(Runtime::POST_DEPLOY);
|
||||||
$tasks = $this->runtime->getTasks();
|
$tasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
|
if (
|
||||||
|
($this->runtime->getBranch() ||
|
||||||
|
$this->runtime->getTag()) &&
|
||||||
|
!$this->runtime->inRollback() &&
|
||||||
|
!in_array('git/change-branch', $tasks)
|
||||||
|
) {
|
||||||
array_push($tasks, 'git/change-branch');
|
array_push($tasks, 'git/change-branch');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +91,14 @@ class RsyncStrategy implements StrategyInterface
|
||||||
/**
|
/**
|
||||||
* Check the runtime stage is correct
|
* Check the runtime stage is correct
|
||||||
*
|
*
|
||||||
* @param $stage
|
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
private function checkStage($stage)
|
private function checkStage(string $stage): void
|
||||||
{
|
{
|
||||||
if ($this->runtime->getStage() !== $stage) {
|
if ($this->runtime->getStage() !== $stage) {
|
||||||
throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%"', $this->runtime->getStage(), $stage));
|
throw new RuntimeException(
|
||||||
|
sprintf('Invalid stage, got "%s" but expected "%s"', $this->runtime->getStage(), $stage)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -19,17 +20,32 @@ use Mage\Runtime\Runtime;
|
||||||
*/
|
*/
|
||||||
interface StrategyInterface
|
interface StrategyInterface
|
||||||
{
|
{
|
||||||
public function getName();
|
public function getName(): string;
|
||||||
|
|
||||||
public function setRuntime(Runtime $runtime);
|
public function setRuntime(Runtime $runtime): void;
|
||||||
|
|
||||||
public function getPreDeployTasks();
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getPreDeployTasks(): array;
|
||||||
|
|
||||||
public function getOnDeployTasks();
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getOnDeployTasks(): array;
|
||||||
|
|
||||||
public function getOnReleaseTasks();
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getOnReleaseTasks(): array;
|
||||||
|
|
||||||
public function getPostReleaseTasks();
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getPostReleaseTasks(): array;
|
||||||
|
|
||||||
public function getPostDeployTasks();
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getPostDeployTasks(): array;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -17,6 +18,6 @@ namespace Mage;
|
||||||
*/
|
*/
|
||||||
class Mage
|
class Mage
|
||||||
{
|
{
|
||||||
const VERSION = '3.0.1';
|
public const VERSION = '5.0.0';
|
||||||
const CODENAME = 'Nostromo';
|
public const CODENAME = 'Galactica';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -17,13 +18,13 @@ use Symfony\Component\Finder\SplFileInfo;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
use Symfony\Component\Console\Event\ConsoleErrorEvent;
|
||||||
use Symfony\Component\Console\ConsoleEvents;
|
use Symfony\Component\Console\ConsoleEvents;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Yaml\Parser;
|
use Symfony\Component\Yaml\Parser;
|
||||||
use Symfony\Component\Yaml\Exception\ParseException;
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
use ReflectionClass;
|
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Console Application for launching the Mage command in a standalone instance
|
* The Console Application for launching the Mage command in a standalone instance
|
||||||
|
@ -32,13 +33,13 @@ use Mage\Runtime\Exception\RuntimeException;
|
||||||
*/
|
*/
|
||||||
class MageApplication extends Application
|
class MageApplication extends Application
|
||||||
{
|
{
|
||||||
protected $runtime;
|
protected Runtime $runtime;
|
||||||
protected $file;
|
protected string $file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $file The YAML file from which to read the configuration
|
* @param string $file The YAML file from which to read the configuration
|
||||||
*/
|
*/
|
||||||
public function __construct($file)
|
public function __construct(string $file)
|
||||||
{
|
{
|
||||||
parent::__construct('Magallanes', Mage::VERSION);
|
parent::__construct('Magallanes', Mage::VERSION);
|
||||||
|
|
||||||
|
@ -46,12 +47,14 @@ class MageApplication extends Application
|
||||||
$dispatcher = new EventDispatcher();
|
$dispatcher = new EventDispatcher();
|
||||||
$this->setDispatcher($dispatcher);
|
$this->setDispatcher($dispatcher);
|
||||||
|
|
||||||
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
|
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) {
|
||||||
$output = $event->getOutput();
|
$output = $event->getOutput();
|
||||||
$command = $event->getCommand();
|
$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();
|
$exitCode = $event->getExitCode();
|
||||||
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
|
$event->setError(new \LogicException('Caught exception', $exitCode, $event->getError()));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->runtime = $this->instantiateRuntime();
|
$this->runtime = $this->instantiateRuntime();
|
||||||
|
@ -63,7 +66,7 @@ class MageApplication extends Application
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function configure()
|
public function configure(): void
|
||||||
{
|
{
|
||||||
if (!file_exists($this->file) || !is_readable($this->file)) {
|
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));
|
throw new RuntimeException(sprintf('The file "%s" does not exists or is not readable.', $this->file));
|
||||||
|
@ -77,14 +80,26 @@ class MageApplication extends Application
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
|
if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
|
||||||
|
|
||||||
$logger = null;
|
$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'));
|
$logfile = sprintf('%s/%s.log', $config['magephp']['log_dir'], date('Ymd_His'));
|
||||||
$config['magephp']['log_file'] = $logfile;
|
$config['magephp']['log_file'] = $logfile;
|
||||||
|
|
||||||
$logger = new Logger('magephp');
|
$logger = new Logger('magephp');
|
||||||
$logger->pushHandler(new StreamHandler($logfile));
|
$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']
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->runtime->setConfiguration($config['magephp']);
|
$this->runtime->setConfiguration($config['magephp']);
|
||||||
|
@ -92,13 +107,33 @@ class MageApplication extends Application
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $this->file));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the BuiltIn Commands
|
* Loads the BuiltIn Commands
|
||||||
*/
|
*/
|
||||||
protected function loadBuiltInCommands()
|
protected function loadBuiltInCommands(): void
|
||||||
{
|
{
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
$finder->files()->in(__DIR__ . '/Command/BuiltIn')->name('*Command.php');
|
$finder->files()->in(__DIR__ . '/Command/BuiltIn')->name('*Command.php');
|
||||||
|
@ -107,7 +142,7 @@ class MageApplication extends Application
|
||||||
foreach ($finder as $file) {
|
foreach ($finder as $file) {
|
||||||
$class = substr('\\Mage\\Command\\BuiltIn\\' . str_replace('/', '\\', $file->getRelativePathname()), 0, -4);
|
$class = substr('\\Mage\\Command\\BuiltIn\\' . str_replace('/', '\\', $file->getRelativePathname()), 0, -4);
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
$reflex = new ReflectionClass($class);
|
$reflex = new \ReflectionClass($class);
|
||||||
if ($reflex->isInstantiable()) {
|
if ($reflex->isInstantiable()) {
|
||||||
$command = new $class();
|
$command = new $class();
|
||||||
if ($command instanceof AbstractCommand) {
|
if ($command instanceof AbstractCommand) {
|
||||||
|
@ -121,20 +156,16 @@ class MageApplication extends Application
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Runtime instance to use
|
* Gets the Runtime instance to use
|
||||||
*
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
protected function instantiateRuntime()
|
protected function instantiateRuntime(): Runtime
|
||||||
{
|
{
|
||||||
return new Runtime();
|
return new Runtime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Runtime instance
|
* Get the Runtime instance
|
||||||
*
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function getRuntime()
|
public function getRuntime(): Runtime
|
||||||
{
|
{
|
||||||
return $this->runtime;
|
return $this->runtime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -10,13 +11,11 @@
|
||||||
|
|
||||||
namespace Mage\Runtime\Exception;
|
namespace Mage\Runtime\Exception;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Error occurred while running
|
* An Error occurred while running
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class RuntimeException extends Exception
|
class RuntimeException extends \Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -17,6 +18,7 @@ use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\LogLevel;
|
use Psr\Log\LogLevel;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
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.
|
* Runtime is a container of all run in time configuration, stages of progress, hosts being deployed, etc.
|
||||||
|
@ -25,58 +27,63 @@ use Mage\Runtime\Exception\RuntimeException;
|
||||||
*/
|
*/
|
||||||
class Runtime
|
class Runtime
|
||||||
{
|
{
|
||||||
const PRE_DEPLOY = 'pre-deploy';
|
public const PRE_DEPLOY = 'pre-deploy';
|
||||||
const ON_DEPLOY = 'on-deploy';
|
public const ON_DEPLOY = 'on-deploy';
|
||||||
const POST_DEPLOY = 'post-deploy';
|
public const POST_DEPLOY = 'post-deploy';
|
||||||
const ON_RELEASE = 'on-release';
|
public const ON_RELEASE = 'on-release';
|
||||||
const POST_RELEASE = 'post-release';
|
public const POST_RELEASE = 'post-release';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Magallanes configuration
|
* @var array<string, mixed> Magallanes configuration
|
||||||
*/
|
*/
|
||||||
protected $configuration = [];
|
protected array $configuration = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null Environment being deployed
|
* @var string|null Environment being deployed
|
||||||
*/
|
*/
|
||||||
protected $environment;
|
protected ?string $environment = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Stage of Deployment
|
* @var string|null Stage of Deployment
|
||||||
*/
|
*/
|
||||||
protected $stage;
|
protected ?string $stage = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null The host being deployed to
|
* @var string|null The host being deployed to
|
||||||
*/
|
*/
|
||||||
protected $workingHost = null;
|
protected ?string $workingHost = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null The Release ID
|
* @var string|null The Release ID
|
||||||
*/
|
*/
|
||||||
protected $releaseId = null;
|
protected ?string $releaseId = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Hold a bag of variables for sharing information between tasks, if needed
|
* @var array<string, string> Hold a bag of variables for sharing information between tasks, if needed
|
||||||
*/
|
*/
|
||||||
protected $vars = [];
|
protected $vars = [];
|
||||||
|
|
||||||
/**
|
protected ?LoggerInterface $logger = null;
|
||||||
* @var LoggerInterface|null The logger instance
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool Indicates if a Rollback operation is in progress
|
* @var bool Indicates if a Rollback operation is in progress
|
||||||
*/
|
*/
|
||||||
protected $rollback = false;
|
protected bool $rollback = false;
|
||||||
|
|
||||||
|
public function isWindows(): bool
|
||||||
|
{
|
||||||
|
return stripos(PHP_OS, 'WIN') === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasPosix(): bool
|
||||||
|
{
|
||||||
|
return function_exists('posix_getpwuid');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the Release ID
|
* Generate the Release ID
|
||||||
*
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function generateReleaseId()
|
public function generateReleaseId(): self
|
||||||
{
|
{
|
||||||
$this->setReleaseId(date('YmdHis'));
|
$this->setReleaseId(date('YmdHis'));
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -84,11 +91,8 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Release ID
|
* Sets the Release ID
|
||||||
*
|
|
||||||
* @param string $releaseId Release ID
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setReleaseId($releaseId)
|
public function setReleaseId(string $releaseId): self
|
||||||
{
|
{
|
||||||
$this->releaseId = $releaseId;
|
$this->releaseId = $releaseId;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -96,21 +100,16 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current Release ID
|
* Retrieve the current Release ID
|
||||||
*
|
|
||||||
* @return null|string Release ID
|
|
||||||
*/
|
*/
|
||||||
public function getReleaseId()
|
public function getReleaseId(): ?string
|
||||||
{
|
{
|
||||||
return $this->releaseId;
|
return $this->releaseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Runtime in Rollback mode On or Off
|
* Sets the Runtime in Rollback mode On or Off
|
||||||
*
|
|
||||||
* @param bool $inRollback
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setRollback($inRollback)
|
public function setRollback(bool $inRollback): self
|
||||||
{
|
{
|
||||||
$this->rollback = $inRollback;
|
$this->rollback = $inRollback;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -118,35 +117,25 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if Runtime is in rollback
|
* Indicates if Runtime is in rollback
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function inRollback()
|
public function inRollback(): bool
|
||||||
{
|
{
|
||||||
return $this->rollback;
|
return $this->rollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a value in the Vars bag
|
* Sets a value in the Vars bag
|
||||||
*
|
|
||||||
* @param string $key Variable name
|
|
||||||
* @param string $value Variable value
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setVar($key, $value)
|
public function setVar(string $key, string $value): self
|
||||||
{
|
{
|
||||||
$this->vars[$key] = $value;
|
$this->vars[$key] = $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a value from the Vars bag
|
* Retrieve a value from the Vars bag, or a default (null) if not set
|
||||||
*
|
|
||||||
* @param string $key Variable name
|
|
||||||
* @param mixed $default Variable default value, returned if not found
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getVar($key, $default = null)
|
public function getVar(string $key, mixed $default = null): ?string
|
||||||
{
|
{
|
||||||
if (array_key_exists($key, $this->vars)) {
|
if (array_key_exists($key, $this->vars)) {
|
||||||
return $this->vars[$key];
|
return $this->vars[$key];
|
||||||
|
@ -157,11 +146,8 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Logger instance
|
* Sets the Logger instance
|
||||||
*
|
|
||||||
* @param LoggerInterface $logger Logger instance
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setLogger(LoggerInterface $logger = null)
|
public function setLogger(?LoggerInterface $logger = null): self
|
||||||
{
|
{
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -170,10 +156,9 @@ class Runtime
|
||||||
/**
|
/**
|
||||||
* Sets the Magallanes Configuration to the Runtime
|
* Sets the Magallanes Configuration to the Runtime
|
||||||
*
|
*
|
||||||
* @param array $configuration Configuration
|
* @param array<string, mixed> $configuration
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setConfiguration($configuration)
|
public function setConfiguration(array $configuration): self
|
||||||
{
|
{
|
||||||
$this->configuration = $configuration;
|
$this->configuration = $configuration;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -182,21 +167,17 @@ class Runtime
|
||||||
/**
|
/**
|
||||||
* Retrieve the Configuration
|
* Retrieve the Configuration
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array<string, mixed> $configuration
|
||||||
*/
|
*/
|
||||||
public function getConfiguration()
|
public function getConfiguration(): array
|
||||||
{
|
{
|
||||||
return $this->configuration;
|
return $this->configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the Configuration Option for a specific section in the 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($key, $default = null)
|
public function getConfigOption(string $key, mixed $default = null): mixed
|
||||||
{
|
{
|
||||||
if (array_key_exists($key, $this->configuration)) {
|
if (array_key_exists($key, $this->configuration)) {
|
||||||
return $this->configuration[$key];
|
return $this->configuration[$key];
|
||||||
|
@ -207,14 +188,13 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Configuration Option for a specific section the current Environment
|
* 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($key, $default = null)
|
public function getEnvOption(string $key, mixed $default = null): mixed
|
||||||
{
|
{
|
||||||
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;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,13 +210,27 @@ class Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites an Environment Configuration Option
|
* 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 string $key
|
* @param array<string, mixed> $defaultEnv
|
||||||
* @param mixed $value
|
* @return array<string, mixed>
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setEnvOption($key, $value)
|
public function getMergedOption(string $key, array $defaultEnv = []): array
|
||||||
|
{
|
||||||
|
$userGlobalOptions = $this->getConfigOption($key, $defaultEnv);
|
||||||
|
$userEnvOptions = $this->getEnvOption($key, $defaultEnv);
|
||||||
|
|
||||||
|
return array_merge(
|
||||||
|
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||||
|
(is_array($userEnvOptions) ? $userEnvOptions : [])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrites an Environment Configuration Option
|
||||||
|
*/
|
||||||
|
public function setEnvOption(string $key, mixed $value): self
|
||||||
{
|
{
|
||||||
if (array_key_exists('environments', $this->configuration) && is_array($this->configuration['environments'])) {
|
if (array_key_exists('environments', $this->configuration) && is_array($this->configuration['environments'])) {
|
||||||
if (array_key_exists($this->environment, $this->configuration['environments'])) {
|
if (array_key_exists($this->environment, $this->configuration['environments'])) {
|
||||||
|
@ -250,13 +244,14 @@ class Runtime
|
||||||
/**
|
/**
|
||||||
* Sets the working Environment
|
* Sets the working Environment
|
||||||
*
|
*
|
||||||
* @param string $environment Environment name
|
|
||||||
* @return Runtime
|
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function setEnvironment($environment)
|
public function setEnvironment(string $environment): self
|
||||||
{
|
{
|
||||||
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;
|
$this->environment = $environment;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -266,21 +261,16 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current working Environment
|
* Returns the current working Environment
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
*/
|
*/
|
||||||
public function getEnvironment()
|
public function getEnvironment(): ?string
|
||||||
{
|
{
|
||||||
return $this->environment;
|
return $this->environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the working stage
|
* Sets the working stage
|
||||||
*
|
|
||||||
* @param string $stage Stage code
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setStage($stage)
|
public function setStage(string $stage): self
|
||||||
{
|
{
|
||||||
$this->stage = $stage;
|
$this->stage = $stage;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -288,10 +278,8 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current working Stage
|
* Retrieve the current working Stage
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getStage()
|
public function getStage(): ?string
|
||||||
{
|
{
|
||||||
return $this->stage;
|
return $this->stage;
|
||||||
}
|
}
|
||||||
|
@ -299,11 +287,14 @@ class Runtime
|
||||||
/**
|
/**
|
||||||
* Retrieve the defined Tasks for the current Environment and Stage
|
* Retrieve the defined Tasks for the current Environment and Stage
|
||||||
*
|
*
|
||||||
* @return array
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function getTasks()
|
public function getTasks(): array
|
||||||
{
|
{
|
||||||
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 [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,11 +313,8 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the working Host
|
* Sets the working Host
|
||||||
*
|
|
||||||
* @param string $host Host name
|
|
||||||
* @return Runtime
|
|
||||||
*/
|
*/
|
||||||
public function setWorkingHost($host)
|
public function setWorkingHost(?string $host): self
|
||||||
{
|
{
|
||||||
$this->workingHost = $host;
|
$this->workingHost = $host;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -334,21 +322,16 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the working Host
|
* Retrieve the working Host
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
*/
|
*/
|
||||||
public function getWorkingHost()
|
public function getWorkingHost(): ?string
|
||||||
{
|
{
|
||||||
return $this->workingHost;
|
return $this->workingHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a Message into the Logger
|
* Logs a Message into the Logger
|
||||||
*
|
|
||||||
* @param string $message Log message
|
|
||||||
* @param string $level Log Level
|
|
||||||
*/
|
*/
|
||||||
public function log($message, $level = LogLevel::DEBUG)
|
public function log(string $message, string $level = LogLevel::DEBUG): void
|
||||||
{
|
{
|
||||||
if ($this->logger instanceof LoggerInterface) {
|
if ($this->logger instanceof LoggerInterface) {
|
||||||
$this->logger->log($level, $message);
|
$this->logger->log($level, $message);
|
||||||
|
@ -357,12 +340,8 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a command, it will be run Locally or Remotely based on the working Stage
|
* 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($cmd, $timeout = 120)
|
public function runCommand(string $cmd, int $timeout = 120): Process
|
||||||
{
|
{
|
||||||
switch ($this->getStage()) {
|
switch ($this->getStage()) {
|
||||||
case self::ON_DEPLOY:
|
case self::ON_DEPLOY:
|
||||||
|
@ -376,16 +355,12 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a command locally
|
* Execute a command locally
|
||||||
*
|
|
||||||
* @param string $cmd Command to execute
|
|
||||||
* @param int $timeout Seconds to wait
|
|
||||||
* @return Process
|
|
||||||
*/
|
*/
|
||||||
public function runLocalCommand($cmd, $timeout = 120)
|
public function runLocalCommand(string $cmd, int $timeout = 120): Process
|
||||||
{
|
{
|
||||||
$this->log($cmd, LogLevel::INFO);
|
$this->log($cmd, LogLevel::INFO);
|
||||||
|
|
||||||
$process = new Process($cmd);
|
$process = Process::fromShellCommandline($cmd);
|
||||||
$process->setTimeout($timeout);
|
$process->setTimeout($timeout);
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
|
@ -399,17 +374,12 @@ class Runtime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a command remotely, if jail is true, it will run inside the Host Path and the Release (if available)
|
* 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($cmd, $jail, $timeout = 120)
|
public function runRemoteCommand(string $cmd, bool $jail, int $timeout = 120): Process
|
||||||
{
|
{
|
||||||
$user = $this->getEnvOption('user', $this->getCurrentUser());
|
$user = $this->getEnvOption('user', $this->getCurrentUser());
|
||||||
$sudo = $this->getEnvOption('sudo', false);
|
$sudo = $this->getEnvOption('sudo', false);
|
||||||
$host = $this->getWorkingHost();
|
$host = $this->getHostName();
|
||||||
$sshConfig = $this->getSSHConfig();
|
$sshConfig = $this->getSSHConfig();
|
||||||
|
|
||||||
$cmdDelegate = $cmd;
|
$cmdDelegate = $cmd;
|
||||||
|
@ -425,7 +395,14 @@ class Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmdRemote = str_replace('"', '\"', $cmdDelegate);
|
$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);
|
return $this->runLocalCommand($cmdLocal, $timeout);
|
||||||
}
|
}
|
||||||
|
@ -433,11 +410,21 @@ class Runtime
|
||||||
/**
|
/**
|
||||||
* Get the SSH configuration based on the environment
|
* Get the SSH configuration based on the environment
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
public function getSSHConfig()
|
public function getSSHConfig(): array
|
||||||
{
|
{
|
||||||
$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();
|
||||||
|
}
|
||||||
|
|
||||||
if (!array_key_exists('port', $sshConfig)) {
|
if (!array_key_exists('port', $sshConfig)) {
|
||||||
$sshConfig['port'] = '22';
|
$sshConfig['port'] = '22';
|
||||||
|
@ -447,46 +434,81 @@ class Runtime
|
||||||
$sshConfig['flags'] = '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no';
|
$sshConfig['flags'] = '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists('timeout', $sshConfig)) {
|
||||||
|
$sshConfig['timeout'] = 300;
|
||||||
|
}
|
||||||
|
|
||||||
return $sshConfig;
|
return $sshConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a Temporal File name
|
* Get the current Host Port or default ssh port
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getTempFile()
|
public function getHostPort(): ?int
|
||||||
|
{
|
||||||
|
$info = explode(':', strval($this->getWorkingHost()));
|
||||||
|
return isset($info[1]) ? intval($info[1]) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current Host Name
|
||||||
|
*/
|
||||||
|
public function getHostName(): ?string
|
||||||
|
{
|
||||||
|
if (strpos(strval($this->getWorkingHost()), ':') === false) {
|
||||||
|
return $this->getWorkingHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
$info = explode(':', $this->getWorkingHost());
|
||||||
|
return strval($info[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a Temporal File name
|
||||||
|
*/
|
||||||
|
public function getTempFile(): string
|
||||||
{
|
{
|
||||||
return tempnam(sys_get_temp_dir(), 'mage');
|
return tempnam(sys_get_temp_dir(), 'mage');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current user
|
* Get the current user
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getCurrentUser()
|
public function getCurrentUser(): string
|
||||||
{
|
{
|
||||||
$userData = posix_getpwuid(posix_geteuid());
|
if ($this->hasPosix()) {
|
||||||
return $userData['name'];
|
$userData = posix_getpwuid(posix_geteuid());
|
||||||
|
return $userData['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Windows fallback
|
||||||
|
return strval(getenv('USERNAME'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut for getting Branch information
|
* Shortcut for getting Branch information
|
||||||
*
|
*
|
||||||
* @return boolean|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public function getBranch()
|
public function getBranch(): mixed
|
||||||
{
|
{
|
||||||
return $this->getEnvOption('branch', false);
|
return $this->getEnvOption('branch', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guesses the Deploy Strategy to use
|
* Shortcut for getting Tag information
|
||||||
*
|
*
|
||||||
* @return StrategyInterface
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public function guessStrategy()
|
public function getTag(): mixed
|
||||||
|
{
|
||||||
|
return $this->getEnvOption('tag', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guesses the Deploy Strategy to use
|
||||||
|
*/
|
||||||
|
public function guessStrategy(): StrategyInterface
|
||||||
{
|
{
|
||||||
$strategy = new RsyncStrategy();
|
$strategy = new RsyncStrategy();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -19,61 +20,53 @@ use Mage\Runtime\Runtime;
|
||||||
*/
|
*/
|
||||||
abstract class AbstractTask
|
abstract class AbstractTask
|
||||||
{
|
{
|
||||||
/**
|
/** @var array<string, string|int|null> */
|
||||||
* @var array Task custom options
|
protected array $options = [];
|
||||||
*/
|
|
||||||
protected $options = [];
|
|
||||||
|
|
||||||
/**
|
protected Runtime $runtime;
|
||||||
* @var Runtime
|
|
||||||
*/
|
|
||||||
protected $runtime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Name/Code of the Task
|
* Get the Name/Code of the Task
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
abstract public function getName();
|
abstract public function getName(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a short Description of the Task
|
* Get a short Description of the Task
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
abstract public function getDescription();
|
abstract public function getDescription(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the Command
|
* Executes the Command
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
abstract public function execute();
|
abstract public function execute(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set additional Options for the Task
|
* Set additional Options for the Task
|
||||||
*
|
*
|
||||||
* @param array $options Options
|
* @param array<string, string|int|null> $options
|
||||||
* @return AbstractTask
|
|
||||||
*/
|
*/
|
||||||
public function setOptions($options = [])
|
public function setOptions(array $options = []): self
|
||||||
{
|
{
|
||||||
if (!is_array($options)) {
|
$this->options = array_merge($this->getDefaults(), $options);
|
||||||
$options = [];
|
|
||||||
}
|
|
||||||
$this->options = $options;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Runtime instance
|
* Set the Runtime instance
|
||||||
*
|
|
||||||
* @param Runtime $runtime
|
|
||||||
* @return AbstractTask
|
|
||||||
*/
|
*/
|
||||||
public function setRuntime(Runtime $runtime)
|
public function setRuntime(Runtime $runtime): self
|
||||||
{
|
{
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Default options
|
||||||
|
*
|
||||||
|
* @return array<string, string|int|null>
|
||||||
|
*/
|
||||||
|
public function getDefaults(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
45
src/Task/BuiltIn/Composer/AbstractComposerTask.php
Normal file
45
src/Task/BuiltIn/Composer/AbstractComposerTask.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?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\AbstractTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract Composer Task
|
||||||
|
*
|
||||||
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractComposerTask extends AbstractTask
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
$options = array_merge(
|
||||||
|
['path' => 'composer'],
|
||||||
|
$this->getComposerOptions(),
|
||||||
|
$this->runtime->getMergedOption('composer'),
|
||||||
|
$this->options
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string|int>
|
||||||
|
*/
|
||||||
|
protected function getComposerOptions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,45 +12,37 @@
|
||||||
namespace Mage\Task\BuiltIn\Composer;
|
namespace Mage\Task\BuiltIn\Composer;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Mage\Task\AbstractTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Composer Task - Generate Autoload
|
* Composer Task - Generate Autoload
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class DumpAutoloadTask extends AbstractTask
|
class DumpAutoloadTask extends AbstractComposerTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'composer/dump-autoload';
|
return 'composer/dump-autoload';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Composer] Dump Autoload';
|
return '[Composer] Dump Autoload';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
$command = sprintf('%s dump-autoload %s', $options['path'], $options['flags']);
|
$cmd = sprintf('%s dump-autoload %s', $options['path'], $options['flags']);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runCommand(trim($command));
|
$process = $this->runtime->runCommand(trim($cmd));
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getComposerOptions(): array
|
||||||
{
|
{
|
||||||
$userOptions = $this->runtime->getConfigOption('composer', []);
|
return ['flags' => '--optimize'];
|
||||||
$options = array_merge(
|
|
||||||
['path' => 'composer', 'flags' => '--optimize'],
|
|
||||||
(is_array($userOptions) ? $userOptions : []),
|
|
||||||
$this->options
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,45 +12,37 @@
|
||||||
namespace Mage\Task\BuiltIn\Composer;
|
namespace Mage\Task\BuiltIn\Composer;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Mage\Task\AbstractTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Composer Task - Install Vendors
|
* Composer Task - Install Vendors
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class InstallTask extends AbstractTask
|
class InstallTask extends AbstractComposerTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'composer/install';
|
return 'composer/install';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Composer] Install';
|
return '[Composer] Install';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
$command = sprintf('%s install %s', $options['path'], $options['flags']);
|
$cmd = sprintf('%s install %s', $options['path'], $options['flags']);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runCommand(trim($command));
|
$process = $this->runtime->runCommand(trim($cmd), intval($options['timeout']));
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getComposerOptions(): array
|
||||||
{
|
{
|
||||||
$userOptions = $this->runtime->getConfigOption('composer', []);
|
return ['flags' => '--optimize-autoloader', 'timeout' => 120];
|
||||||
$options = array_merge(
|
|
||||||
['path' => 'composer', 'flags' => '--optimize-autoloader'],
|
|
||||||
(is_array($userOptions) ? $userOptions : []),
|
|
||||||
$this->options
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -20,17 +21,17 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class CleanupTask extends AbstractTask
|
class CleanupTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'deploy/release/cleanup';
|
return 'deploy/release/cleanup';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Release] Cleaning up old Releases';
|
return '[Release] Cleaning up old Releases';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$currentReleaseId = $this->runtime->getReleaseId();
|
$currentReleaseId = $this->runtime->getReleaseId();
|
||||||
|
@ -42,13 +43,13 @@ class CleanupTask extends AbstractTask
|
||||||
$process = $this->runtime->runRemoteCommand($cmdListReleases, false);
|
$process = $this->runtime->runRemoteCommand($cmdListReleases, false);
|
||||||
if ($process->isSuccessful()) {
|
if ($process->isSuccessful()) {
|
||||||
$releases = $process->getOutput();
|
$releases = $process->getOutput();
|
||||||
$releases = explode(PHP_EOL, trim($releases));
|
$releases = explode("\n", trim($releases));
|
||||||
|
|
||||||
if (count($releases) > $maxReleases) {
|
if (count($releases) > $maxReleases) {
|
||||||
sort($releases);
|
sort($releases);
|
||||||
$releasesToDelete = array_slice($releases, 0, count($releases) - $maxReleases);
|
$releasesToDelete = array_slice($releases, 0, count($releases) - $maxReleases);
|
||||||
foreach ($releasesToDelete as $releaseId) {
|
foreach ($releasesToDelete as $releaseId) {
|
||||||
if ($releaseId != $currentReleaseId) {
|
if ($releaseId !== $currentReleaseId) {
|
||||||
$cmdDeleteRelease = sprintf('rm -rf %s/releases/%s', $hostPath, $releaseId);
|
$cmdDeleteRelease = sprintf('rm -rf %s/releases/%s', $hostPath, $releaseId);
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runRemoteCommand($cmdDeleteRelease, false);
|
$process = $this->runtime->runRemoteCommand($cmdDeleteRelease, false);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -20,17 +21,17 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class PrepareTask extends AbstractTask
|
class PrepareTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'deploy/release/prepare';
|
return 'deploy/release/prepare';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Release] Preparing Release';
|
return '[Release] Preparing Release';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -22,17 +23,17 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
|
class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'deploy/release';
|
return 'deploy/release';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Release] Creating Symlink';
|
return '[Release] Creating Symlink';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvOption('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
|
@ -41,10 +42,12 @@ class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
|
||||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$releaseId = $this->runtime->getReleaseId();
|
$releaseId = $this->runtime->getReleaseId();
|
||||||
|
|
||||||
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s current', $hostPath, $releaseId);
|
$symlink = $this->runtime->getEnvOption('symlink', 'current');
|
||||||
|
|
||||||
|
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s %s', $hostPath, $releaseId, $symlink);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false);
|
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false, 0);
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -21,22 +22,22 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class RsyncTask extends AbstractTask
|
class RsyncTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'deploy/rsync';
|
return 'deploy/rsync';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Deploy] Copying files with Rsync';
|
return '[Deploy] Copying files with Rsync';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$flags = $this->runtime->getEnvOption('rsync', '-avz');
|
$flags = $this->runtime->getEnvOption('rsync', '-avz');
|
||||||
$sshConfig = $this->runtime->getSSHConfig();
|
$sshConfig = $this->runtime->getSSHConfig();
|
||||||
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
||||||
$host = $this->runtime->getWorkingHost();
|
$host = $this->runtime->getHostName();
|
||||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$targetDir = rtrim($hostPath, '/');
|
$targetDir = rtrim($hostPath, '/');
|
||||||
|
|
||||||
|
@ -45,17 +46,28 @@ class RsyncTask extends AbstractTask
|
||||||
}
|
}
|
||||||
|
|
||||||
$excludes = $this->getExcludes();
|
$excludes = $this->getExcludes();
|
||||||
$cmdRsync = sprintf('rsync -e "ssh -p %d %s" %s %s ./ %s@%s:%s', $sshConfig['port'], $sshConfig['flags'], $flags, $excludes, $user, $host, $targetDir);
|
$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
|
||||||
|
);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runLocalCommand($cmdRsync, 600);
|
$process = $this->runtime->runLocalCommand($cmdRsync, 0);
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getExcludes()
|
protected function getExcludes(): string
|
||||||
{
|
{
|
||||||
$excludes = $this->runtime->getEnvOption('exclude', []);
|
$excludes = $this->runtime->getMergedOption('exclude', []);
|
||||||
$excludes = array_merge(['.git'], $excludes);
|
$excludes = array_merge(['.git'], array_filter($excludes));
|
||||||
|
|
||||||
foreach ($excludes as &$exclude) {
|
foreach ($excludes as &$exclude) {
|
||||||
$exclude = '--exclude=' . $exclude;
|
$exclude = '--exclude=' . $exclude;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -21,17 +22,17 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class CleanupTask extends AbstractTask
|
class CleanupTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'deploy/tar/cleanup';
|
return 'deploy/tar/cleanup';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Deploy] Cleanup Tar file';
|
return '[Deploy] Cleanup Tar file';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvOption('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -21,40 +22,50 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class CopyTask extends AbstractTask
|
class CopyTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'deploy/tar/copy';
|
return 'deploy/tar/copy';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Deploy] Copying files with Tar';
|
return '[Deploy] Copying files with Tar';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvOption('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
||||||
$host = $this->runtime->getWorkingHost();
|
$host = $this->runtime->getHostName();
|
||||||
$sshConfig = $sshConfig = $this->runtime->getSSHConfig();
|
$sshConfig = $sshConfig = $this->runtime->getSSHConfig();
|
||||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$currentReleaseId = $this->runtime->getReleaseId();
|
$currentReleaseId = $this->runtime->getReleaseId();
|
||||||
|
|
||||||
|
$tarPath = $this->runtime->getEnvOption('tar_extract_path', 'tar');
|
||||||
$flags = $this->runtime->getEnvOption('tar_extract', 'xfzop');
|
$flags = $this->runtime->getEnvOption('tar_extract', 'xfzop');
|
||||||
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
|
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
|
||||||
|
|
||||||
$tarLocal = $this->runtime->getVar('tar_local');
|
$tarLocal = $this->runtime->getVar('tar_local');
|
||||||
$tarRemote = basename($tarLocal);
|
$tarRemote = basename($tarLocal);
|
||||||
|
|
||||||
$cmdCopy = sprintf('scp -P %d %s %s %s@%s:%s/%s', $sshConfig['port'], $sshConfig['flags'], $tarLocal, $user, $host, $targetDir, $tarRemote);
|
$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
|
||||||
|
);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runLocalCommand($cmdCopy, 300);
|
$process = $this->runtime->runLocalCommand($cmdCopy, intval($sshConfig['timeout']));
|
||||||
if ($process->isSuccessful()) {
|
if ($process->isSuccessful()) {
|
||||||
$cmdUnTar = sprintf('cd %s && tar %s %s', $targetDir, $flags, $tarRemote);
|
$cmdUnTar = sprintf('cd %s && %s %s %s', $targetDir, $tarPath, $flags, $tarRemote);
|
||||||
$process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600);
|
$process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600);
|
||||||
if ($process->isSuccessful()) {
|
if ($process->isSuccessful()) {
|
||||||
$cmdDelete = sprintf('rm %s/%s', $targetDir, $tarRemote);
|
$cmdDelete = sprintf('rm %s/%s', $targetDir, $tarRemote);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -21,17 +22,17 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class PrepareTask extends AbstractTask
|
class PrepareTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'deploy/tar/prepare';
|
return 'deploy/tar/prepare';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Deploy] Preparing Tar file';
|
return '[Deploy] Preparing Tar file';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvOption('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
|
@ -41,18 +42,28 @@ class PrepareTask extends AbstractTask
|
||||||
$this->runtime->setVar('tar_local', $tarLocal);
|
$this->runtime->setVar('tar_local', $tarLocal);
|
||||||
|
|
||||||
$excludes = $this->getExcludes();
|
$excludes = $this->getExcludes();
|
||||||
$flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
|
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
|
||||||
$cmdTar = sprintf('tar %s %s %s ./', $flags, $tarLocal, $excludes);
|
$flags = $this->runtime->getEnvOption(
|
||||||
|
'tar_create',
|
||||||
|
$this->runtime->isWindows() ? '--force-local -c -z -p -f' : '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 */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runLocalCommand($cmdTar, 300);
|
$process = $this->runtime->runLocalCommand($cmdTar, 300);
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getExcludes()
|
protected function getExcludes(): string
|
||||||
{
|
{
|
||||||
$excludes = $this->runtime->getEnvOption('exclude', []);
|
$excludes = $this->runtime->getMergedOption('exclude', []);
|
||||||
$excludes = array_merge(['.git'], $excludes);
|
$excludes = array_merge(['.git'], array_filter($excludes));
|
||||||
|
|
||||||
foreach ($excludes as &$exclude) {
|
foreach ($excludes as &$exclude) {
|
||||||
$exclude = '--exclude="' . $exclude . '"';
|
$exclude = '--exclude="' . $exclude . '"';
|
||||||
|
|
91
src/Task/BuiltIn/ExecTask.php
Normal file
91
src/Task/BuiltIn/ExecTask.php
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
<?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;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exec task. Allows you to execute arbitrary commands.
|
||||||
|
*
|
||||||
|
* @author Yanick Witschi <https://github.com/Toflar>
|
||||||
|
*/
|
||||||
|
class ExecTask extends AbstractTask
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return 'exec';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
$options = $this->getOptions();
|
||||||
|
|
||||||
|
if ($options['desc']) {
|
||||||
|
return '[Exec] ' . $options['desc'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '[Exec] Custom command';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @throws ErrorException
|
||||||
|
*/
|
||||||
|
public function execute(): bool
|
||||||
|
{
|
||||||
|
$options = $this->getOptions();
|
||||||
|
|
||||||
|
if (!$options['cmd']) {
|
||||||
|
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']));
|
||||||
|
return $process->isSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string|int>
|
||||||
|
*/
|
||||||
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
$options = array_merge(
|
||||||
|
['cmd' => '', 'desc' => '', 'timeout' => 120],
|
||||||
|
$this->options
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -23,14 +24,16 @@ abstract class AbstractFileTask extends AbstractTask
|
||||||
/**
|
/**
|
||||||
* Returns the Task options
|
* Returns the Task options
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array<string, string|int|null>
|
||||||
* @throws ErrorException
|
* @throws ErrorException
|
||||||
*/
|
*/
|
||||||
protected function getOptions()
|
protected function getOptions(): array
|
||||||
{
|
{
|
||||||
$mandatory = $this->getParameters();
|
$mandatory = $this->getParameters();
|
||||||
|
$defaults = array_keys($this->getDefaults());
|
||||||
|
$missing = array_diff($mandatory, $defaults);
|
||||||
|
|
||||||
foreach ($mandatory as $parameter) {
|
foreach ($missing as $parameter) {
|
||||||
if (!array_key_exists($parameter, $this->options)) {
|
if (!array_key_exists($parameter, $this->options)) {
|
||||||
throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
|
throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
|
||||||
}
|
}
|
||||||
|
@ -42,25 +45,23 @@ abstract class AbstractFileTask extends AbstractTask
|
||||||
/**
|
/**
|
||||||
* Returns the mandatory parameters
|
* Returns the mandatory parameters
|
||||||
*
|
*
|
||||||
* @return array
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
abstract protected function getParameters();
|
abstract protected function getParameters(): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a file with the placeholders replaced
|
* Returns a file with the placeholders replaced
|
||||||
*
|
*
|
||||||
* @param string $file
|
|
||||||
* @return string
|
|
||||||
* @throws ErrorException
|
* @throws ErrorException
|
||||||
*/
|
*/
|
||||||
protected function getFile($file)
|
protected function getFile(string $file): string
|
||||||
{
|
{
|
||||||
$mapping = [
|
$mapping = [
|
||||||
'%environment%' => $this->runtime->getEnvironment(),
|
'%environment%' => $this->runtime->getEnvironment(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->runtime->getWorkingHost() !== null) {
|
if ($this->runtime->getHostName() !== null) {
|
||||||
$mapping['%host%'] = $this->runtime->getWorkingHost();
|
$mapping['%host%'] = $this->runtime->getHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->runtime->getReleaseId() !== null) {
|
if ($this->runtime->getReleaseId() !== null) {
|
||||||
|
@ -71,7 +72,7 @@ abstract class AbstractFileTask extends AbstractTask
|
||||||
return str_replace(
|
return str_replace(
|
||||||
array_keys($mapping),
|
array_keys($mapping),
|
||||||
array_values($mapping),
|
array_values($mapping),
|
||||||
$options[$file]
|
strval($options[$file])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
60
src/Task/BuiltIn/FS/ChangeModeTask.php
Normal file
60
src/Task/BuiltIn/FS/ChangeModeTask.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?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\FS;
|
||||||
|
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File System Task - Copy a File
|
||||||
|
*
|
||||||
|
* @author Marian Bäuerle
|
||||||
|
*/
|
||||||
|
class ChangeModeTask extends AbstractFileTask
|
||||||
|
{
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return 'fs/chmod';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
return '[FS] Chmod [missing parameters]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(): bool
|
||||||
|
{
|
||||||
|
$file = $this->getFile('file');
|
||||||
|
$mode = $this->options['mode'];
|
||||||
|
$flags = $this->options['flags'];
|
||||||
|
|
||||||
|
$cmd = sprintf('chmod %s %s "%s"', $flags, $mode, $file);
|
||||||
|
|
||||||
|
/** @var Process $process */
|
||||||
|
$process = $this->runtime->runCommand($cmd);
|
||||||
|
|
||||||
|
return $process->isSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getParameters(): array
|
||||||
|
{
|
||||||
|
return ['file', 'mode', 'flags'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaults(): array
|
||||||
|
{
|
||||||
|
return ['flags' => null];
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,7 +12,6 @@
|
||||||
namespace Mage\Task\BuiltIn\FS;
|
namespace Mage\Task\BuiltIn\FS;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File System Task - Copy a File
|
* File System Task - Copy a File
|
||||||
|
@ -20,26 +20,27 @@ use Exception;
|
||||||
*/
|
*/
|
||||||
class CopyTask extends AbstractFileTask
|
class CopyTask extends AbstractFileTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'fs/copy';
|
return 'fs/copy';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
||||||
} catch (Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
return '[FS] Copy [missing parameters]';
|
return '[FS] Copy [missing parameters]';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$copyFrom = $this->getFile('from');
|
$copyFrom = $this->getFile('from');
|
||||||
$copyTo = $this->getFile('to');
|
$copyTo = $this->getFile('to');
|
||||||
|
$flags = $this->options['flags'];
|
||||||
|
|
||||||
$cmd = sprintf('cp -p %s %s', $copyFrom, $copyTo);
|
$cmd = sprintf('cp %s "%s" "%s"', $flags, $copyFrom, $copyTo);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runCommand($cmd);
|
$process = $this->runtime->runCommand($cmd);
|
||||||
|
@ -47,8 +48,13 @@ class CopyTask extends AbstractFileTask
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getParameters()
|
protected function getParameters(): array
|
||||||
{
|
{
|
||||||
return ['from', 'to'];
|
return ['from', 'to', 'flags'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaults(): array
|
||||||
|
{
|
||||||
|
return ['flags' => '-p'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,7 +12,6 @@
|
||||||
namespace Mage\Task\BuiltIn\FS;
|
namespace Mage\Task\BuiltIn\FS;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File System Task - Symlink a File
|
* File System Task - Symlink a File
|
||||||
|
@ -20,26 +20,27 @@ use Exception;
|
||||||
*/
|
*/
|
||||||
class LinkTask extends AbstractFileTask
|
class LinkTask extends AbstractFileTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'fs/link';
|
return 'fs/link';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
||||||
} catch (Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
return '[FS] Link [missing parameters]';
|
return '[FS] Link [missing parameters]';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$linkFrom = $this->getFile('from');
|
$linkFrom = $this->getFile('from');
|
||||||
$linkTo = $this->getFile('to');
|
$linkTo = $this->getFile('to');
|
||||||
|
$flags = $this->options['flags'];
|
||||||
|
|
||||||
$cmd = sprintf('ln -snf %s %s', $linkFrom, $linkTo);
|
$cmd = sprintf('ln %s "%s" "%s"', $flags, $linkFrom, $linkTo);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runCommand($cmd);
|
$process = $this->runtime->runCommand($cmd);
|
||||||
|
@ -47,8 +48,13 @@ class LinkTask extends AbstractFileTask
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getParameters()
|
protected function getParameters(): array
|
||||||
{
|
{
|
||||||
return ['from', 'to'];
|
return ['from', 'to', 'flags'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaults(): array
|
||||||
|
{
|
||||||
|
return ['flags' => '-snf'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -20,12 +21,12 @@ use Exception;
|
||||||
*/
|
*/
|
||||||
class MoveTask extends AbstractFileTask
|
class MoveTask extends AbstractFileTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'fs/move';
|
return 'fs/move';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
||||||
|
@ -34,12 +35,13 @@ class MoveTask extends AbstractFileTask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$moveFrom = $this->getFile('from');
|
$moveFrom = $this->getFile('from');
|
||||||
$moveTo = $this->getFile('to');
|
$moveTo = $this->getFile('to');
|
||||||
|
$flags = $this->options['flags'];
|
||||||
|
|
||||||
$cmd = sprintf('mv %s %s', $moveFrom, $moveTo);
|
$cmd = sprintf('mv %s "%s" "%s"', $flags, $moveFrom, $moveTo);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runCommand($cmd);
|
$process = $this->runtime->runCommand($cmd);
|
||||||
|
@ -47,8 +49,13 @@ class MoveTask extends AbstractFileTask
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getParameters()
|
protected function getParameters(): array
|
||||||
{
|
{
|
||||||
return ['from', 'to'];
|
return ['from', 'to', 'flags'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaults(): array
|
||||||
|
{
|
||||||
|
return ['flags' => null];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,7 +12,6 @@
|
||||||
namespace Mage\Task\BuiltIn\FS;
|
namespace Mage\Task\BuiltIn\FS;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File System Task - Remove a File
|
* File System Task - Remove a File
|
||||||
|
@ -20,25 +20,26 @@ use Exception;
|
||||||
*/
|
*/
|
||||||
class RemoveTask extends AbstractFileTask
|
class RemoveTask extends AbstractFileTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'fs/remove';
|
return 'fs/remove';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return sprintf('[FS] Remove "%s"', $this->getFile('file'));
|
return sprintf('[FS] Remove "%s"', $this->getFile('file'));
|
||||||
} catch (Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
return '[FS] Remove [missing parameters]';
|
return '[FS] Remove [missing parameters]';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$file = $this->getFile('file');
|
$file = $this->getFile('file');
|
||||||
|
$flags = $this->options['flags'];
|
||||||
|
|
||||||
$cmd = sprintf('rm %s', $file);
|
$cmd = sprintf('rm %s "%s"', $flags, $file);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runCommand($cmd);
|
$process = $this->runtime->runCommand($cmd);
|
||||||
|
@ -46,8 +47,13 @@ class RemoveTask extends AbstractFileTask
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getParameters()
|
protected function getParameters(): array
|
||||||
{
|
{
|
||||||
return ['file'];
|
return ['file', 'flags'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaults(): array
|
||||||
|
{
|
||||||
|
return ['flags' => null];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -21,29 +22,35 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class ChangeBranchTask extends AbstractTask
|
class ChangeBranchTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'git/change-branch';
|
return 'git/change-branch';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
|
$tag = $options['tag'];
|
||||||
$branch = $options['branch'];
|
$branch = $options['branch'];
|
||||||
|
|
||||||
if ($this->runtime->getVar('git_revert_branch', false)) {
|
if ($this->runtime->getVar('git_revert_branch', null)) {
|
||||||
$branch = $this->runtime->getVar('git_revert_branch');
|
$branch = $this->runtime->getVar('git_revert_branch');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($tag) {
|
||||||
|
return sprintf('[Git] Checkout Tag (%s)', $tag);
|
||||||
|
}
|
||||||
|
|
||||||
return sprintf('[Git] Change Branch (%s)', $branch);
|
return sprintf('[Git] Change Branch (%s)', $branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
$branch = $this->runtime->getVar('git_revert_branch', false);
|
/** @var string|bool */
|
||||||
|
$branch = $this->runtime->getVar('git_revert_branch', null);
|
||||||
|
|
||||||
if ($branch === false) {
|
if (!$branch) {
|
||||||
$cmdGetCurrent = sprintf('%s branch | grep "*"', $options['path']);
|
$cmdGetCurrent = sprintf('%s branch | grep "*"', $options['path']);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
|
@ -53,11 +60,11 @@ class ChangeBranchTask extends AbstractTask
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentBranch = str_replace('* ', '', trim($process->getOutput()));
|
$currentBranch = str_replace('* ', '', trim($process->getOutput()));
|
||||||
if ($currentBranch == $options['branch']) {
|
if ($currentBranch === $options['branch']) {
|
||||||
throw new SkipException();
|
throw new SkipException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$branch = $options['branch'];
|
$branch = $options['tag'] ? $options['tag'] : $options['branch'];
|
||||||
$this->runtime->setVar('git_revert_branch', $currentBranch);
|
$this->runtime->setVar('git_revert_branch', $currentBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,11 +75,15 @@ class ChangeBranchTask extends AbstractTask
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions()
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function getOptions(): array
|
||||||
{
|
{
|
||||||
|
$tag = $this->runtime->getEnvOption('tag', false);
|
||||||
$branch = $this->runtime->getEnvOption('branch', 'master');
|
$branch = $this->runtime->getEnvOption('branch', 'master');
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['path' => 'git', 'branch' => $branch],
|
['path' => 'git', 'branch' => $branch, 'tag' => $tag],
|
||||||
$this->options
|
$this->options
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -12,6 +13,7 @@ namespace Mage\Task\BuiltIn\Git;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Mage\Task\AbstractTask;
|
use Mage\Task\AbstractTask;
|
||||||
|
use Mage\Task\Exception\SkipException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Git Task - Pull
|
* Git Task - Pull
|
||||||
|
@ -20,32 +22,40 @@ use Mage\Task\AbstractTask;
|
||||||
*/
|
*/
|
||||||
class UpdateTask extends AbstractTask
|
class UpdateTask extends AbstractTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'git/update';
|
return 'git/update';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Git] Update';
|
return '[Git] Update';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
|
if ($options['tag']) {
|
||||||
|
throw new SkipException();
|
||||||
|
}
|
||||||
|
|
||||||
$command = $options['path'] . ' pull';
|
$command = $options['path'] . ' pull';
|
||||||
|
|
||||||
/** @var Process $process */
|
|
||||||
$process = $this->runtime->runLocalCommand($command);
|
$process = $this->runtime->runLocalCommand($command);
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions()
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function getOptions(): array
|
||||||
{
|
{
|
||||||
$branch = $this->runtime->getEnvOption('branch', 'master');
|
$branch = $this->runtime->getEnvOption('branch', 'master');
|
||||||
|
$tag = $this->runtime->getEnvOption('tag', false);
|
||||||
|
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['path' => 'git', 'branch' => $branch],
|
['path' => 'git', 'branch' => $branch, 'tag' => $tag],
|
||||||
$this->options
|
$this->options
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
61
src/Task/BuiltIn/SleepTask.php
Normal file
61
src/Task/BuiltIn/SleepTask.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
45
src/Task/BuiltIn/Symfony/AbstractSymfonyTask.php
Normal file
45
src/Task/BuiltIn/Symfony/AbstractSymfonyTask.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?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\AbstractTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract Symfony Task
|
||||||
|
*
|
||||||
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractSymfonyTask extends AbstractTask
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
$options = array_merge(
|
||||||
|
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||||
|
$this->getSymfonyOptions(),
|
||||||
|
$this->runtime->getMergedOption('symfony'),
|
||||||
|
$this->options
|
||||||
|
);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string|null>
|
||||||
|
*/
|
||||||
|
protected function getSymfonyOptions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,57 +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;
|
|
||||||
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));
|
|
||||||
|
|
||||||
return $process->isSuccessful();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getOptions()
|
|
||||||
{
|
|
||||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
|
||||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
|
||||||
$options = array_merge(
|
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
|
||||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
|
||||||
$this->options
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,47 +12,42 @@
|
||||||
namespace Mage\Task\BuiltIn\Symfony;
|
namespace Mage\Task\BuiltIn\Symfony;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Mage\Task\AbstractTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Symfony Task - Install Assets
|
* Symfony Task - Install Assets
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class AssetsInstallTask extends AbstractTask
|
class AssetsInstallTask extends AbstractSymfonyTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'symfony/assets-install';
|
return 'symfony/assets-install';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Symfony] Assets Install';
|
return '[Symfony] Assets Install';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$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));
|
$process = $this->runtime->runCommand(trim($command));
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getSymfonyOptions(): array
|
||||||
{
|
{
|
||||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
return ['target' => 'web', 'flags' => '--symlink --relative'];
|
||||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
|
||||||
$options = array_merge(
|
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
|
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
|
||||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
|
||||||
$this->options
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,26 +12,25 @@
|
||||||
namespace Mage\Task\BuiltIn\Symfony;
|
namespace Mage\Task\BuiltIn\Symfony;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Mage\Task\AbstractTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Symfony Task - Clear Cache
|
* Symfony Task - Clear Cache
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class CacheClearTask extends AbstractTask
|
class CacheClearTask extends AbstractSymfonyTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'symfony/cache-clear';
|
return 'symfony/cache-clear';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Symfony] Cache Clear';
|
return '[Symfony] Cache Clear';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
$command = $options['console'] . ' cache:clear --env=' . $options['env'] . ' ' . $options['flags'];
|
$command = $options['console'] . ' cache:clear --env=' . $options['env'] . ' ' . $options['flags'];
|
||||||
|
@ -40,18 +40,4 @@ class CacheClearTask extends AbstractTask
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions()
|
|
||||||
{
|
|
||||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
|
||||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
|
||||||
$options = array_merge(
|
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
|
||||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
|
||||||
$this->options
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
60
src/Task/BuiltIn/Symfony/CachePoolClearTask.php
Normal file
60
src/Task/BuiltIn/Symfony/CachePoolClearTask.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?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];
|
||||||
|
}
|
||||||
|
}
|
43
src/Task/BuiltIn/Symfony/CachePoolPruneTask.php
Normal file
43
src/Task/BuiltIn/Symfony/CachePoolPruneTask.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,26 +12,25 @@
|
||||||
namespace Mage\Task\BuiltIn\Symfony;
|
namespace Mage\Task\BuiltIn\Symfony;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Mage\Task\AbstractTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Symfony Task - Cache Warmup
|
* Symfony Task - Cache Warmup
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class CacheWarmupTask extends AbstractTask
|
class CacheWarmupTask extends AbstractSymfonyTask
|
||||||
{
|
{
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'symfony/cache-warmup';
|
return 'symfony/cache-warmup';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription(): string
|
||||||
{
|
{
|
||||||
return '[Symfony] Cache Warmup';
|
return '[Symfony] Cache Warmup';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute(): bool
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
$command = $options['console'] . ' cache:warmup --env=' . $options['env'] . ' ' . $options['flags'];
|
$command = $options['console'] . ' cache:warmup --env=' . $options['env'] . ' ' . $options['flags'];
|
||||||
|
@ -40,18 +40,4 @@ class CacheWarmupTask extends AbstractTask
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOptions()
|
|
||||||
{
|
|
||||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
|
||||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
|
||||||
$options = array_merge(
|
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
|
||||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
|
||||||
$this->options
|
|
||||||
);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -10,16 +11,14 @@
|
||||||
|
|
||||||
namespace Mage\Task\Exception;
|
namespace Mage\Task\Exception;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Task Failed, and it has a Custom Message
|
* The Task Failed, and it has a Custom Message
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class ErrorException extends Exception
|
class ErrorException extends \Exception
|
||||||
{
|
{
|
||||||
public function getTrimmedMessage($maxLength = 60)
|
public function getTrimmedMessage(int $maxLength = 60): string
|
||||||
{
|
{
|
||||||
$message = $this->getMessage();
|
$message = $this->getMessage();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -10,13 +11,11 @@
|
||||||
|
|
||||||
namespace Mage\Task\Exception;
|
namespace Mage\Task\Exception;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Task will be Skipped
|
* The Task will be Skipped
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class SkipException extends Exception
|
class SkipException extends \Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -23,33 +24,27 @@ use ReflectionClass;
|
||||||
*/
|
*/
|
||||||
class TaskFactory
|
class TaskFactory
|
||||||
{
|
{
|
||||||
/**
|
protected Runtime $runtime;
|
||||||
* @var Runtime
|
|
||||||
*/
|
|
||||||
protected $runtime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Registered Tasks
|
* @var AbstractTask[] Registered Tasks
|
||||||
*/
|
*/
|
||||||
protected $registeredTasks = [];
|
protected array $registeredTasks = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
|
||||||
* @param Runtime $runtime
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Runtime $runtime)
|
public function __construct(Runtime $runtime)
|
||||||
{
|
{
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
$this->loadBuiltInTasks();
|
$this->loadBuiltInTasks();
|
||||||
|
$this->loadCustomTasks($runtime->getConfigOption('custom_tasks', []));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Task
|
* Add a Task
|
||||||
*
|
|
||||||
* @param AbstractTask $task
|
|
||||||
*/
|
*/
|
||||||
public function add(AbstractTask $task)
|
public function add(AbstractTask $task): void
|
||||||
{
|
{
|
||||||
$task->setRuntime($this->runtime);
|
$task->setRuntime($this->runtime);
|
||||||
$this->registeredTasks[$task->getName()] = $task;
|
$this->registeredTasks[$task->getName()] = $task;
|
||||||
|
@ -59,11 +54,10 @@ class TaskFactory
|
||||||
* Get a Task by it's registered Name/Code, or it can be a Class Name,
|
* Get a Task by it's registered Name/Code, or it can be a Class Name,
|
||||||
* in that case the class will be instantiated
|
* in that case the class will be instantiated
|
||||||
*
|
*
|
||||||
* @param string $name Name/Code or Class of the Task
|
* @param string|mixed[] $name
|
||||||
* @return AbstractTask
|
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get(mixed $name): AbstractTask
|
||||||
{
|
{
|
||||||
$options = [];
|
$options = [];
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
|
@ -95,18 +89,26 @@ class TaskFactory
|
||||||
/**
|
/**
|
||||||
* Load BuiltIn Tasks
|
* Load BuiltIn Tasks
|
||||||
*/
|
*/
|
||||||
protected function loadBuiltInTasks()
|
protected function loadBuiltInTasks(): void
|
||||||
{
|
{
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
$finder->files()->in(__DIR__ . '/BuiltIn')->name('*Task.php');
|
$finder->files()->in(__DIR__ . '/BuiltIn')->name('*Task.php');
|
||||||
|
|
||||||
/** @var SplFileInfo $file */
|
/** @var SplFileInfo $file */
|
||||||
foreach ($finder as $file) {
|
foreach ($finder as $file) {
|
||||||
$class = substr('\\Mage\\Task\\BuiltIn\\' . str_replace('/', '\\', $file->getRelativePathname()), 0, -4);
|
$taskClass = substr(
|
||||||
if (class_exists($class)) {
|
'\\Mage\\Task\\BuiltIn\\' . str_replace(
|
||||||
$reflex = new ReflectionClass($class);
|
'/',
|
||||||
|
'\\',
|
||||||
|
$file->getRelativePathname()
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
-4
|
||||||
|
);
|
||||||
|
if (class_exists($taskClass)) {
|
||||||
|
$reflex = new ReflectionClass($taskClass);
|
||||||
if ($reflex->isInstantiable()) {
|
if ($reflex->isInstantiable()) {
|
||||||
$task = new $class();
|
$task = new $taskClass();
|
||||||
if ($task instanceof AbstractTask) {
|
if ($task instanceof AbstractTask) {
|
||||||
$this->add($task);
|
$this->add($task);
|
||||||
}
|
}
|
||||||
|
@ -114,4 +116,34 @@ class TaskFactory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load Custom Tasks
|
||||||
|
*
|
||||||
|
* @param string[] $tasksToLoad
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
protected function loadCustomTasks(array $tasksToLoad): void
|
||||||
|
{
|
||||||
|
foreach ($tasksToLoad as $taskClass) {
|
||||||
|
if (!class_exists($taskClass)) {
|
||||||
|
throw new RuntimeException(sprintf('Custom Task "%s" does not exists.', $taskClass));
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflex = new ReflectionClass($taskClass);
|
||||||
|
if (!$reflex->isInstantiable()) {
|
||||||
|
throw new RuntimeException(sprintf('Custom Task "%s" can not be instantiated.', $taskClass));
|
||||||
|
}
|
||||||
|
|
||||||
|
$task = new $taskClass();
|
||||||
|
if (!$task instanceof AbstractTask) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
sprintf('Custom Task "%s" must inherit "Mage\\Task\\AbstractTask".', $taskClass)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Task
|
||||||
|
$this->add($task);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Magallanes package.
|
* This file is part of the Magallanes package.
|
||||||
*
|
*
|
||||||
|
@ -11,8 +12,6 @@
|
||||||
namespace Mage;
|
namespace Mage;
|
||||||
|
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\Runtime;
|
||||||
use DateTime;
|
|
||||||
use DateInterval;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for resolving trivial operations
|
* Utility class for resolving trivial operations
|
||||||
|
@ -23,11 +22,8 @@ class Utils
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Given a stage code it will resolve a human friendly name
|
* Given a stage code it will resolve a human friendly name
|
||||||
*
|
|
||||||
* @param string $stage
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getStageName($stage)
|
public function getStageName(string $stage): string
|
||||||
{
|
{
|
||||||
switch ($stage) {
|
switch ($stage) {
|
||||||
case Runtime::PRE_DEPLOY:
|
case Runtime::PRE_DEPLOY:
|
||||||
|
@ -51,35 +47,36 @@ class Utils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a Release ID, convert it to a DateTime instance
|
* Given a Release ID, convert it to a DateTime instance
|
||||||
*
|
|
||||||
* @param string $releaseId The Release ID
|
|
||||||
* @return DateTime
|
|
||||||
*/
|
*/
|
||||||
public function getReleaseDate($releaseId)
|
public function getReleaseDate(string $releaseId): \DateTime
|
||||||
{
|
{
|
||||||
$formatted = sprintf('%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d',
|
$formatted = sprintf(
|
||||||
$releaseId[0], $releaseId[1], $releaseId[2], $releaseId[3],
|
'%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d',
|
||||||
$releaseId[4], $releaseId[5],
|
$releaseId[0],
|
||||||
$releaseId[6], $releaseId[7],
|
$releaseId[1],
|
||||||
$releaseId[8], $releaseId[9],
|
$releaseId[2],
|
||||||
$releaseId[10], $releaseId[11],
|
$releaseId[3],
|
||||||
$releaseId[12], $releaseId[13]
|
$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
|
* Given a Date, calculate friendly how much time has passed
|
||||||
*
|
|
||||||
* @param DateTime $releaseDate
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getTimeDiff(DateTime $releaseDate)
|
public function getTimeDiff(\DateTime $releaseDate): string
|
||||||
{
|
{
|
||||||
$now = new DateTime();
|
$now = new \DateTime();
|
||||||
|
|
||||||
/** @var DateInterval $diff */
|
|
||||||
$diff = $now->diff($releaseDate);
|
$diff = $now->diff($releaseDate);
|
||||||
|
|
||||||
if ($diff->days > 7) {
|
if ($diff->days > 7) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Config\DumpCommand;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DumpCommandTest extends TestCase
|
class DumpCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Config\EnvironmentsCommand;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class EnvironmentsCommandTest extends TestCase
|
class EnvironmentsCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
76
tests/Command/BuiltIn/DeployCommandMiscTasksTest.php
Normal file → Executable file
76
tests/Command/BuiltIn/DeployCommandMiscTasksTest.php
Normal file → Executable file
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\DeployCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DeployCommandMiscTasksTest extends TestCase
|
class DeployCommandMiscTasksTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -35,8 +35,10 @@ 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',
|
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"',
|
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"',
|
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 assetic:dump --env=testenv"',
|
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 assetic:dump --env=prod"',
|
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"',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check total of Executed Commands
|
// Check total of Executed Commands
|
||||||
|
@ -80,6 +82,66 @@ class DeployCommandMiscTasksTest extends TestCase
|
||||||
$this->assertEquals(0, $tester->getStatusCode());
|
$this->assertEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGlobalExcludeFlags()
|
||||||
|
{
|
||||||
|
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/global-exclude.yml');
|
||||||
|
|
||||||
|
/** @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 => '/usr/bin/composer.phar install --prefer-source',
|
||||||
|
1 => '/usr/bin/composer.phar dump-autoload --no-scripts',
|
||||||
|
2 => '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',
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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 testComposerEnvFlags()
|
||||||
|
{
|
||||||
|
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/composer-env.yml');
|
||||||
|
|
||||||
|
/** @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 => '/usr/foobar/composer install --prefer-source',
|
||||||
|
1 => '/usr/foobar/composer dump-autoload --no-scripts',
|
||||||
|
2 => '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',
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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 testInvalidTaskName()
|
public function testInvalidTaskName()
|
||||||
{
|
{
|
||||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
|
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
|
||||||
|
@ -92,7 +154,7 @@ class DeployCommandMiscTasksTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
$this->assertEquals(7, $tester->getStatusCode());
|
$this->assertEquals(7, $tester->getStatusCode());
|
||||||
$this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay());
|
$this->assertStringContainsString('Invalid task name "invalid/task"', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBrokenGitBranch()
|
public function testBrokenGitBranch()
|
||||||
|
@ -109,7 +171,7 @@ class DeployCommandMiscTasksTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +189,7 @@ class DeployCommandMiscTasksTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +207,7 @@ class DeployCommandMiscTasksTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('Running [Git] Update ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Running [Git] Update ... FAIL', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
53
tests/Command/BuiltIn/DeployCommandMiscTest.php
Normal file → Executable file
53
tests/Command/BuiltIn/DeployCommandMiscTest.php
Normal file → Executable file
|
@ -11,10 +11,11 @@
|
||||||
namespace Mage\Tests\Command\BuiltIn;
|
namespace Mage\Tests\Command\BuiltIn;
|
||||||
|
|
||||||
use Mage\Command\BuiltIn\DeployCommand;
|
use Mage\Command\BuiltIn\DeployCommand;
|
||||||
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DeployCommandMiscTest extends TestCase
|
class DeployCommandMiscTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -29,13 +30,51 @@ class DeployCommandMiscTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('No hosts defined, skipping On Deploy tasks', $tester->getDisplay());
|
$this->assertStringContainsString('No hosts defined, skipping On Deploy tasks', $tester->getDisplay());
|
||||||
$this->assertContains('No hosts defined, skipping On Release tasks', $tester->getDisplay());
|
$this->assertStringContainsString('No hosts defined, skipping On Release tasks', $tester->getDisplay());
|
||||||
$this->assertContains('No hosts defined, skipping Post Release tasks', $tester->getDisplay());
|
$this->assertStringContainsString('No hosts defined, skipping Post Release tasks', $tester->getDisplay());
|
||||||
|
|
||||||
$this->assertEquals(0, $tester->getStatusCode());
|
$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');
|
||||||
|
|
||||||
|
/** @var AbstractCommand $command */
|
||||||
|
$command = $application->find('deploy');
|
||||||
|
$this->assertTrue($command instanceof DeployCommand);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$tester = new CommandTester($command);
|
||||||
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
} catch (RuntimeException $exception) {
|
||||||
|
$this->assertEquals('The configured log_dir "/no-temp" does not exists or is not a directory.', $exception->getMessage());
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$this->assertFalse(true, sprintf('Exception "%s" catched, message: "%s"', get_class($exception), $exception->getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testDeploymentWithSudo()
|
public function testDeploymentWithSudo()
|
||||||
{
|
{
|
||||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-sudo.yml');
|
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-sudo.yml');
|
||||||
|
@ -59,7 +98,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"',
|
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"',
|
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"',
|
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 assetic:dump --env=dev"',
|
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"',
|
||||||
10 => 'git checkout master',
|
10 => 'git checkout master',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -96,7 +135,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',
|
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"',
|
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"',
|
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 assetic:dump --env=dev"',
|
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"',
|
||||||
9 => 'git checkout master',
|
9 => 'git checkout master',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -240,7 +279,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',
|
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"',
|
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"',
|
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 assetic:dump --env=dev"',
|
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"',
|
||||||
8 => 'git branch | grep "*"',
|
8 => 'git branch | grep "*"',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
483
tests/Command/BuiltIn/DeployCommandWithReleasesTest.php
Normal file → Executable file
483
tests/Command/BuiltIn/DeployCommandWithReleasesTest.php
Normal file → Executable file
|
@ -13,8 +13,9 @@ namespace Mage\Tests\Command\BuiltIn;
|
||||||
use Mage\Command\BuiltIn\DeployCommand;
|
use Mage\Command\BuiltIn\DeployCommand;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
|
use Mage\Tests\MageApplicationWindowsMockup;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DeployCommandWithReleasesTest extends TestCase
|
class DeployCommandWithReleasesTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -46,7 +47,406 @@ 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"',
|
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"',
|
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"',
|
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 assetic:dump --env=dev"',
|
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 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');
|
||||||
|
|
||||||
|
$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 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
|
||||||
|
7 => 'scp -P 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
||||||
|
8 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
|
||||||
|
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"',
|
||||||
|
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"',
|
||||||
|
16 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
|
||||||
|
17 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
|
||||||
|
18 => 'ssh -p 202 -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 testDeploymentWithReleasesWithFromCommands()
|
||||||
|
{
|
||||||
|
$application = new MageApplicationMockup(__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 cfzp /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 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"',
|
||||||
13 => '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 "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"',
|
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"',
|
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||||
|
@ -79,7 +479,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +494,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +509,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +524,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('Copying files with Tar ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Copying files with Tar ... FAIL', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +539,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
$this->assertStringContainsString('This task is only available with releases enabled', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +580,8 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$this->assertEquals($command, $ranCommands[$index]);
|
$this->assertEquals($command, $ranCommands[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertContains('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
|
||||||
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
$this->assertStringContainsString('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,8 +621,8 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$this->assertEquals($command, $ranCommands[$index]);
|
$this->assertEquals($command, $ranCommands[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertContains('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Running [Deploy] Copying files with Tar ... FAIL', $tester->getDisplay());
|
||||||
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
$this->assertStringContainsString('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +656,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"',
|
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"',
|
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"',
|
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 assetic:dump --env=dev"',
|
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"',
|
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"',
|
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"',
|
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||||
|
@ -274,8 +674,57 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$this->assertEquals($command, $ranCommands[$index]);
|
$this->assertEquals($command, $ranCommands[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertContains('Running [Deploy] Cleanup Tar file ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Running [Deploy] Cleanup Tar file ... FAIL', $tester->getDisplay());
|
||||||
$this->assertContains('Stage "Post Deploy" did not finished successfully, halting command.', $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->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +758,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"',
|
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"',
|
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"',
|
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 assetic:dump --env=dev"',
|
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"',
|
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"',
|
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||||
);
|
);
|
||||||
|
@ -322,8 +771,8 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
$this->assertEquals($command, $ranCommands[$index]);
|
$this->assertEquals($command, $ranCommands[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertContains('Running [Release] Cleaning up old Releases ... FAIL', $tester->getDisplay());
|
$this->assertStringContainsString('Running [Release] Cleaning up old Releases ... FAIL', $tester->getDisplay());
|
||||||
$this->assertContains('Stage "Post Release" did not finished successfully, halting command.', $tester->getDisplay());
|
$this->assertStringContainsString('Stage "Post Release" did not finished successfully, halting command.', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
80
tests/Command/BuiltIn/DeployCommandWithoutReleasesTest.php
Normal file → Executable file
80
tests/Command/BuiltIn/DeployCommandWithoutReleasesTest.php
Normal file → Executable file
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\DeployCommand;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DeployCommandWithoutReleasesTest extends TestCase
|
class DeployCommandWithoutReleasesTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,81 @@ 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',
|
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"',
|
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"',
|
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 assetic:dump --env=dev"',
|
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"',
|
||||||
|
9 => '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 testDeploymentWithoutReleasesWithPortCommands()
|
||||||
|
{
|
||||||
|
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases-with-port.yml');
|
||||||
|
|
||||||
|
/** @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 => '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"',
|
||||||
|
9 => '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 testDeploymentWithoutReleasesWithFromCommands()
|
||||||
|
{
|
||||||
|
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases-with-from.yml');
|
||||||
|
|
||||||
|
/** @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 => '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"',
|
||||||
9 => 'git checkout master',
|
9 => 'git checkout master',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -87,7 +161,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
|
||||||
$this->assertEquals($command, $ranCommands[$index]);
|
$this->assertEquals($command, $ranCommands[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
$this->assertStringContainsString('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
tests/Command/BuiltIn/Releases/ListCommandTest.php
Normal file → Executable file
14
tests/Command/BuiltIn/Releases/ListCommandTest.php
Normal file → Executable file
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Releases\ListCommand;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ListCommandTest extends TestCase
|
class ListCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ class ListCommandTest extends TestCase
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'developers']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'developers']);
|
||||||
|
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
|
$this->assertStringContainsString('The environment "developers" does not exists.', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListReleasesWithoutReleases()
|
public function testListReleasesWithoutReleases()
|
||||||
|
@ -72,7 +72,7 @@ class ListCommandTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
$this->assertContains('Releases are not enabled', $tester->getDisplay());
|
$this->assertStringContainsString('Releases are not enabled', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFailToGetCurrentRelease()
|
public function testFailToGetCurrentRelease()
|
||||||
|
@ -87,7 +87,7 @@ class ListCommandTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
$this->assertContains('Unable to retrieve current release from host "host1"', $tester->getDisplay());
|
$this->assertStringContainsString('Unable to retrieve current release from host "host1"', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoReleasesAvailable()
|
public function testNoReleasesAvailable()
|
||||||
|
@ -101,7 +101,7 @@ class ListCommandTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
$this->assertContains('No releases available on host host2', $tester->getDisplay());
|
$this->assertStringContainsString('No releases available on host host2', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFailGetReleases()
|
public function testFailGetReleases()
|
||||||
|
@ -116,7 +116,7 @@ class ListCommandTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
$this->assertContains('Unable to retrieve releases from host "host3"', $tester->getDisplay());
|
$this->assertStringContainsString('Unable to retrieve releases from host "host3"', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoHosts()
|
public function testNoHosts()
|
||||||
|
@ -130,6 +130,6 @@ class ListCommandTest extends TestCase
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
$this->assertContains('No hosts defined', $tester->getDisplay());
|
$this->assertStringContainsString('No hosts defined', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
tests/Command/BuiltIn/Releases/RollbackCommandTest.php
Normal file → Executable file
8
tests/Command/BuiltIn/Releases/RollbackCommandTest.php
Normal file → Executable file
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Releases\RollbackCommand;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class RollbackCommandTest extends TestCase
|
class RollbackCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ class RollbackCommandTest extends TestCase
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'developers', 'release' => '20170101015115']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'developers', 'release' => '20170101015115']);
|
||||||
|
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
|
$this->assertStringContainsString('The environment "developers" does not exists.', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRollbackReleaseWithoutReleases()
|
public function testRollbackReleaseWithoutReleases()
|
||||||
|
@ -72,7 +72,7 @@ class RollbackCommandTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
$this->assertContains('Releases are not enabled', $tester->getDisplay());
|
$this->assertStringContainsString('Releases are not enabled', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRollbackReleaseNotAvailable()
|
public function testRollbackReleaseNotAvailable()
|
||||||
|
@ -87,6 +87,6 @@ class RollbackCommandTest extends TestCase
|
||||||
|
|
||||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||||
$this->assertContains('Release "20170101015115" is not available on all hosts', $tester->getDisplay());
|
$this->assertStringContainsString('Release "20170101015115" is not available on all hosts', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use Mage\Command\BuiltIn\VersionCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
use Mage\Mage;
|
use Mage\Mage;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class VersionCommandTest extends TestCase
|
class VersionCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
23
tests/Deploy/StrategyTest.php
Normal file → Executable file
23
tests/Deploy/StrategyTest.php
Normal file → Executable file
|
@ -15,7 +15,7 @@ use Mage\Deploy\Strategy\RsyncStrategy;
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\Runtime;
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class StrategyTest extends TestCase
|
class StrategyTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ class StrategyTest extends TestCase
|
||||||
$rsync->getPreDeployTasks();
|
$rsync->getPreDeployTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -39,7 +39,7 @@ class StrategyTest extends TestCase
|
||||||
$rsync->getOnDeployTasks();
|
$rsync->getOnDeployTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -47,7 +47,7 @@ class StrategyTest extends TestCase
|
||||||
$rsync->getOnReleaseTasks();
|
$rsync->getOnReleaseTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -55,7 +55,7 @@ class StrategyTest extends TestCase
|
||||||
$rsync->getPostReleaseTasks();
|
$rsync->getPostReleaseTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -63,7 +63,7 @@ class StrategyTest extends TestCase
|
||||||
$rsync->getPostDeployTasks();
|
$rsync->getPostDeployTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class StrategyTest extends TestCase
|
||||||
$releases->getPreDeployTasks();
|
$releases->getPreDeployTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -87,7 +87,7 @@ class StrategyTest extends TestCase
|
||||||
$releases->getOnDeployTasks();
|
$releases->getOnDeployTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -95,7 +95,7 @@ class StrategyTest extends TestCase
|
||||||
$releases->getOnReleaseTasks();
|
$releases->getOnReleaseTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -103,7 +103,7 @@ class StrategyTest extends TestCase
|
||||||
$releases->getPostReleaseTasks();
|
$releases->getPostReleaseTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -111,8 +111,7 @@ class StrategyTest extends TestCase
|
||||||
$releases->getPostDeployTasks();
|
$releases->getPostDeployTasks();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->assertTrue($exception instanceof RuntimeException);
|
$this->assertTrue($exception instanceof RuntimeException);
|
||||||
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
|
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class MageApplicationMockup extends MageApplication
|
||||||
*
|
*
|
||||||
* @return RuntimeMockup
|
* @return RuntimeMockup
|
||||||
*/
|
*/
|
||||||
protected function instantiateRuntime()
|
protected function instantiateRuntime(): RuntimeMockup
|
||||||
{
|
{
|
||||||
return new RuntimeMockup();
|
return new RuntimeMockup();
|
||||||
}
|
}
|
||||||
|
|
4
tests/MageApplicationTest.php
Normal file → Executable file
4
tests/MageApplicationTest.php
Normal file → Executable file
|
@ -14,7 +14,7 @@ use Mage\MageApplication;
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit_Framework_TestCase as TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class MageApplicationTest extends TestCase
|
class MageApplicationTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -73,6 +73,6 @@ class MageApplicationTest extends TestCase
|
||||||
$tester = new ApplicationTester($application);
|
$tester = new ApplicationTester($application);
|
||||||
$tester->run(['command' => 'foo']);
|
$tester->run(['command' => 'foo']);
|
||||||
|
|
||||||
$this->assertContains('Oops, exception thrown while running command foo', $tester->getDisplay());
|
$this->assertStringContainsString('Oops, exception thrown while running command foo', $tester->getDisplay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
tests/MageApplicationWindowsMockup.php
Normal file
28
tests/MageApplicationWindowsMockup.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
production:
|
production:
|
||||||
user: app
|
user: app
|
||||||
|
@ -21,7 +21,7 @@ magephp:
|
||||||
on-deploy:
|
on-deploy:
|
||||||
- symfony/cache-warmup: { env: 'dev' }
|
- symfony/cache-warmup: { env: 'dev' }
|
||||||
- symfony/assets-install: { env: 'dev' }
|
- symfony/assets-install: { env: 'dev' }
|
||||||
- symfony/assetic-dump: { env: 'dev' }
|
- symfony/cache-pool-prune: { env: 'dev' }
|
||||||
on-release:
|
on-release:
|
||||||
post-release:
|
post-release:
|
||||||
post-deploy:
|
post-deploy:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
|
19
tests/Resources/composer-env.yml
Normal file
19
tests/Resources/composer-env.yml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
magephp:
|
||||||
|
log_dir: .logs/
|
||||||
|
composer:
|
||||||
|
path: /usr/bin/composer.phar
|
||||||
|
environments:
|
||||||
|
test:
|
||||||
|
composer:
|
||||||
|
path: /usr/foobar/composer
|
||||||
|
user: tester
|
||||||
|
host_path: /var/www/test
|
||||||
|
exclude:
|
||||||
|
- ./var/cache/*
|
||||||
|
- ./var/log/*
|
||||||
|
- ./web/app_dev.php
|
||||||
|
hosts:
|
||||||
|
- testhost
|
||||||
|
pre-deploy:
|
||||||
|
- composer/install: { flags: '--prefer-source' }
|
||||||
|
- composer/dump-autoload: { flags: '--no-scripts' }
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
composer:
|
composer:
|
||||||
path: /usr/bin/composer.phar
|
path: /usr/bin/composer.phar
|
||||||
environments:
|
environments:
|
||||||
|
|
13
tests/Resources/custom-task-invalid-class.yml
Normal file
13
tests/Resources/custom-task-invalid-class.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
magephp:
|
||||||
|
environments:
|
||||||
|
production:
|
||||||
|
user: app
|
||||||
|
host_path: /var/www/myapp
|
||||||
|
hosts:
|
||||||
|
- webserver
|
||||||
|
pre-deploy:
|
||||||
|
on-deploy:
|
||||||
|
- custom-invalid-class
|
||||||
|
post-deploy:
|
||||||
|
custom_tasks:
|
||||||
|
- Mage\Tests\Task\Custom\InvalidClass
|
13
tests/Resources/custom-task-invalid-inheritance.yml
Normal file
13
tests/Resources/custom-task-invalid-inheritance.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
magephp:
|
||||||
|
environments:
|
||||||
|
production:
|
||||||
|
user: app
|
||||||
|
host_path: /var/www/myapp
|
||||||
|
hosts:
|
||||||
|
- webserver
|
||||||
|
pre-deploy:
|
||||||
|
on-deploy:
|
||||||
|
- custom-invalid-inheritance
|
||||||
|
post-deploy:
|
||||||
|
custom_tasks:
|
||||||
|
- Mage\Tests\Task\Custom\InvalidInheritanceTask
|
13
tests/Resources/custom-task-not-instantiable.yml
Normal file
13
tests/Resources/custom-task-not-instantiable.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
magephp:
|
||||||
|
environments:
|
||||||
|
production:
|
||||||
|
user: app
|
||||||
|
host_path: /var/www/myapp
|
||||||
|
hosts:
|
||||||
|
- webserver
|
||||||
|
pre-deploy:
|
||||||
|
on-deploy:
|
||||||
|
- custom-not-instantiable
|
||||||
|
post-deploy:
|
||||||
|
custom_tasks:
|
||||||
|
- Mage\Tests\Task\Custom\NotInstantiableTask
|
13
tests/Resources/custom-task.yml
Normal file
13
tests/Resources/custom-task.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
magephp:
|
||||||
|
environments:
|
||||||
|
production:
|
||||||
|
user: app
|
||||||
|
host_path: /var/www/myapp
|
||||||
|
hosts:
|
||||||
|
- webserver
|
||||||
|
pre-deploy:
|
||||||
|
on-deploy:
|
||||||
|
- custom-valid
|
||||||
|
post-deploy:
|
||||||
|
custom_tasks:
|
||||||
|
- Mage\Tests\Task\Custom\ValidTask
|
17
tests/Resources/global-exclude.yml
Normal file
17
tests/Resources/global-exclude.yml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
magephp:
|
||||||
|
log_dir: .logs/
|
||||||
|
composer:
|
||||||
|
path: /usr/bin/composer.phar
|
||||||
|
exclude:
|
||||||
|
- ./var/cache/*
|
||||||
|
- ./var/log/*
|
||||||
|
- ./web/app_dev.php
|
||||||
|
environments:
|
||||||
|
test:
|
||||||
|
user: tester
|
||||||
|
host_path: /var/www/test
|
||||||
|
hosts:
|
||||||
|
- testhost
|
||||||
|
pre-deploy:
|
||||||
|
- composer/install: { flags: '--prefer-source' }
|
||||||
|
- composer/dump-autoload: { flags: '--no-scripts' }
|
27
tests/Resources/invalid-log.yml
Normal file
27
tests/Resources/invalid-log.yml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
magephp:
|
||||||
|
log_dir: /no-temp
|
||||||
|
environments:
|
||||||
|
production:
|
||||||
|
user: app
|
||||||
|
branch: master
|
||||||
|
host_path: /var/www/myapp
|
||||||
|
releases: 4
|
||||||
|
exclude:
|
||||||
|
- ./var/cache/*
|
||||||
|
- ./var/log/*
|
||||||
|
- ./web/app_dev.php
|
||||||
|
hosts:
|
||||||
|
- webserver1
|
||||||
|
- webserver2
|
||||||
|
- webserver3
|
||||||
|
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:
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
@ -17,7 +17,7 @@ magephp:
|
||||||
on-deploy:
|
on-deploy:
|
||||||
- symfony/cache-warmup: { env: 'dev' }
|
- symfony/cache-warmup: { env: 'dev' }
|
||||||
- symfony/assets-install: { env: 'dev' }
|
- symfony/assets-install: { env: 'dev' }
|
||||||
- symfony/assetic-dump: { env: 'dev' }
|
- symfony/cache-pool-prune: { env: 'dev' }
|
||||||
on-release:
|
on-release:
|
||||||
post-release:
|
post-release:
|
||||||
post-deploy:
|
post-deploy:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
symfony: { env: 'testenv' }
|
symfony: { env: 'testenv' }
|
||||||
|
@ -14,5 +14,7 @@ magephp:
|
||||||
on-deploy:
|
on-deploy:
|
||||||
- symfony/cache-warmup
|
- symfony/cache-warmup
|
||||||
- symfony/assets-install
|
- symfony/assets-install
|
||||||
- symfony/assetic-dump
|
- symfony/cache-pool-prune
|
||||||
- symfony/assetic-dump: { env: 'prod' }
|
- symfony/cache-pool-prune: { env: 'prod' }
|
||||||
|
- symfony/cache-pool-clear: { pools: 'main' }
|
||||||
|
- symfony/cache-pool-clear: { env: 'prod', pools: 'main' }
|
||||||
|
|
28
tests/Resources/testhost-custom-symlink.yml
Normal file
28
tests/Resources/testhost-custom-symlink.yml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
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:
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
@ -17,4 +17,4 @@ magephp:
|
||||||
- Mage\Tests\Task\CustomTask
|
- Mage\Tests\Task\CustomTask
|
||||||
on-release:
|
on-release:
|
||||||
post-release:
|
post-release:
|
||||||
post-deploy:
|
post-deploy:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
@ -12,4 +12,4 @@ magephp:
|
||||||
hosts:
|
hosts:
|
||||||
- host2
|
- host2
|
||||||
on-deploy:
|
on-deploy:
|
||||||
- deploy/release
|
- deploy/release
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
@ -12,4 +12,4 @@ magephp:
|
||||||
hosts:
|
hosts:
|
||||||
- host2
|
- host2
|
||||||
pre-deploy:
|
pre-deploy:
|
||||||
- deploy/tar/prepare
|
- deploy/tar/prepare
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
@ -12,4 +12,4 @@ magephp:
|
||||||
hosts:
|
hosts:
|
||||||
- host2
|
- host2
|
||||||
on-deploy:
|
on-deploy:
|
||||||
- deploy/tar/copy
|
- deploy/tar/copy
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
@ -12,4 +12,4 @@ magephp:
|
||||||
hosts:
|
hosts:
|
||||||
- host2
|
- host2
|
||||||
post-deploy:
|
post-deploy:
|
||||||
- deploy/tar/cleanup
|
- deploy/tar/cleanup
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
magephp:
|
magephp:
|
||||||
log_dir: /tmp
|
log_dir: .logs/
|
||||||
environments:
|
environments:
|
||||||
test:
|
test:
|
||||||
user: tester
|
user: tester
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue