Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  replace travis by github ci
  CS
  rename __toString to toString
  use pack arguments instead of an option to simplify the code
  CS
  add psalm
  update deps
  require php 7.4
  remove useless script
  • Loading branch information
Baptouuuu committed Mar 28, 2020
2 parents 064cdf8 + 3d5f463 commit 31b2f39
Show file tree
Hide file tree
Showing 38 changed files with 368 additions and 322 deletions.
3 changes: 0 additions & 3 deletions .gitattributes
@@ -1,7 +1,4 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/fixtures export-ignore
/tests export-ignore
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,65 @@
name: CI

on: [push]

jobs:
phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['7.4']
name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}'
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: xdebug
ini-values: xdebug.max_nesting_level=2048
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
psalm:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4']
name: 'Psalm - PHP/${{ matrix.php-version }}'
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Psalm
run: vendor/bin/psalm --shepherd
6 changes: 0 additions & 6 deletions .scrutinizer.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

8 changes: 3 additions & 5 deletions README.md
@@ -1,10 +1,8 @@
# Tower

| `master` | `develop` |
|----------|-----------|
| [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Innmind/Tower/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Innmind/Tower/?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Innmind/Tower/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Tower/?branch=develop) |
| [![Code Coverage](https://scrutinizer-ci.com/g/Innmind/Tower/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Innmind/Tower/?branch=master) | [![Code Coverage](https://scrutinizer-ci.com/g/Innmind/Tower/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Tower/?branch=develop) |
| [![Build Status](https://scrutinizer-ci.com/g/Innmind/Tower/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Innmind/Tower/build-status/master) | [![Build Status](https://scrutinizer-ci.com/g/Innmind/Tower/badges/build.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Tower/build-status/develop) |
[![Build Status](https://github.com/Innmind/Tower/workflows/CI/badge.svg)](https://github.com/Innmind/Tower/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/Innmind/Tower/branch/develop/graph/badge.svg)](https://codecov.io/gh/Innmind/Tower)
[![Type Coverage](https://shepherd.dev/github/Innmind/Tower/coverage.svg)](https://shepherd.dev/github/Innmind/Tower)

This is a command line tool to deploy your code base with a new approach. Instead of building another tool sending a set of shell commands over ssh with a logic of point to point, Tower takes the approach of servers as nodes of a tree where from a node you trigger the _tower_ of sub-nodes.

Expand Down
23 changes: 10 additions & 13 deletions composer.json
Expand Up @@ -15,16 +15,15 @@
"issues": "http://github.com/Innmind/Tower/issues"
},
"require": {
"php": "~7.2",
"innmind/immutable": "^2.8",
"innmind/url": "^2.0",
"symfony/config": "^4.0",
"symfony/yaml": "^4.0",
"innmind/server-control": "^2.2",
"innmind/socket": "^2.0",
"innmind/cli": "^1.2",
"php": "~7.4",
"innmind/immutable": "~3.5",
"innmind/url": "~3.3",
"symfony/config": "~5.0",
"symfony/yaml": "~5.0",
"innmind/operating-system": "~2.0",
"innmind/cli": "~2.0",
"innmind/json": "^1.1",
"innmind/silent-cartographer": "^1.1"
"innmind/silent-cartographer": "~2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -40,10 +39,8 @@
},
"require-dev": {
"phpunit/phpunit": "~8.0",
"giorgiosironi/eris": "^0.11.0"
},
"scripts": {
"test": "vendor/bin/phpunit --colors=always"
"giorgiosironi/eris": "^0.11.0",
"vimeo/psalm": "^3.10"
},
"bin": ["tower"],
"extra": {
Expand Down
16 changes: 16 additions & 0 deletions psalm.xml
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
22 changes: 11 additions & 11 deletions src/Command/Listen.php
Expand Up @@ -15,23 +15,23 @@
};
use Innmind\Socket\{
Internet\Transport,
Loop,
Serve,
};
use Innmind\OperatingSystem\Ports;
use Innmind\IP\IPv4;
use Innmind\Url\Authority\Port;

final class Listen implements Command
{
private $ports;
private $server;
private $loop;
private Ports $ports;
private Server $server;
private Serve $serve;

public function __construct(Ports $ports, Server $server, Loop $loop)
public function __construct(Ports $ports, Server $server, Serve $serve)
{
$this->ports = $ports;
$this->server = $server;
$this->loop = $loop;
$this->serve = $serve;
}

public function __invoke(Environment $env, Arguments $arguments, Options $options): void
Expand All @@ -44,7 +44,7 @@ public function __invoke(Environment $env, Arguments $arguments, Options $option
ServerCommand::background('tower')
->withArgument('listen')
->withArgument($arguments->get('port'))
->withWorkingDirectory((string) $env->workingDirectory())
->withWorkingDirectory($env->workingDirectory()),
);

return;
Expand All @@ -54,19 +54,19 @@ public function __invoke(Environment $env, Arguments $arguments, Options $option
try {
$socket = $this->ports->open(
Transport::tcp(),
new IPv4('127.0.0.1'),
new Port((int) $arguments->get('port'))
IPv4::of('127.0.0.1'),
Port::of((int) $arguments->get('port')),
);

($this->loop)($socket);
($this->serve)($socket);
} catch (\Throwable $e) {
//pass
}
//the while is to make sure we never exit
} while (true);
}

public function __toString(): string
public function toString(): string
{
return <<<USAGE
listen port -d|--daemon
Expand Down
35 changes: 12 additions & 23 deletions src/Command/Ping.php
Expand Up @@ -15,15 +15,18 @@
Environment,
};
use Innmind\Immutable\{
SetInterface,
Set,
Str,
};
use function Innmind\Immutable\{
first,
unwrap,
};

final class Ping implements Command
{
private $configuration;
private $ping;
private Configuration $configuration;
private ServerPing $ping;

public function __construct(Configuration $configuration, ServerPing $ping)
{
Expand All @@ -34,34 +37,20 @@ public function __construct(Configuration $configuration, ServerPing $ping)
public function __invoke(Environment $env, Arguments $arguments, Options $options): void
{
$name = $arguments->get('server');
$neighbour = $this
$neighbour = first($this
->configuration
->neighbours()
->filter(static function(Neighbour $neighbour) use ($name): bool {
return (string) $neighbour->name() === $name;
})
->current();

$tags = [];

if ($options->contains('tags')) {
$tags = Str::of($options->get('tags'))
->split(',')
->reduce(
Set::of('string'),
static function(SetInterface $tags, Str $tag): SetInterface {
return $tags->add((string) $tag->trim());
}
);
}
return $neighbour->name()->toString() === $name;
}));

($this->ping)($neighbour, ...$tags);
($this->ping)($neighbour, ...unwrap($arguments->pack()));
}

public function __toString(): string
public function toString(): string
{
return <<<USAGE
ping server --tags=
ping server ...tags
Send a ping to a configured server in order to trigger its behaviour
Expand Down
23 changes: 5 additions & 18 deletions src/Command/Trigger.php
Expand Up @@ -11,14 +11,14 @@
Environment,
};
use Innmind\Immutable\{
SetInterface,
Set,
Str,
};
use function Innmind\Immutable\unwrap;

final class Trigger implements Command
{
private $run;
private Run $run;

public function __construct(Run $run)
{
Expand All @@ -27,26 +27,13 @@ public function __construct(Run $run)

public function __invoke(Environment $env, Arguments $arguments, Options $options): void
{
$tags = [];

if ($options->contains('tags')) {
$tags = Str::of($options->get('tags'))
->split(',')
->reduce(
Set::of('string'),
static function(SetInterface $tags, Str $tag): SetInterface {
return $tags->add((string) $tag->trim());
}
);
}

($this->run)(...$tags);
($this->run)(...unwrap($arguments->pack()));
}

public function __toString(): string
public function toString(): string
{
return <<<USAGE
trigger --tags=
trigger ...tags
Will call the actions configured to happen when this server is pinged
Expand Down

0 comments on commit 31b2f39

Please sign in to comment.