Skip to content

Commit 878589b

Browse files
committed
Merge branch 'develop'
* develop: specify next release replace old gif by a showcase video update readme run CS when proofs changes do not run psalm when modifying tests update changelog do not run tests when properties change as it is only compatible with blackbox now run proofs independently from tests remove deadcode do not clear the terminal after the start CS fix tests remove object wrapper on top of activity enum fiw watched paths pause the source when there is no activity replace sub processes with fibers via innmind/mantle update actions version
2 parents c68e845 + ad881e5 commit 878589b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1445
-1715
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: 'PHPUnit'
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
@@ -27,7 +27,7 @@ jobs:
2727
dependency-versions: ${{ matrix.dependencies }}
2828
- name: PHPUnit
2929
run: vendor/bin/phpunit --coverage-clover=coverage.clover
30-
- uses: codecov/codecov-action@v1
30+
- uses: codecov/codecov-action@v3
3131
with:
3232
token: ${{ secrets.CODECOV_TOKEN }}
3333
psalm:
@@ -39,7 +39,7 @@ jobs:
3939
name: 'Psalm'
4040
steps:
4141
- name: Checkout
42-
uses: actions/checkout@v2
42+
uses: actions/checkout@v4
4343
- name: Setup PHP
4444
uses: shivammathur/setup-php@v2
4545
with:
@@ -59,7 +59,7 @@ jobs:
5959
name: 'CS'
6060
steps:
6161
- name: Checkout
62-
uses: actions/checkout@v2
62+
uses: actions/checkout@v4
6363
- name: Setup PHP
6464
uses: shivammathur/setup-php@v2
6565
with:

CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## 4.0.0 - 2023-11-12
4+
5+
### Added
6+
7+
- You can use `proofs`, `blackbox` or `bb` as triggers to only run proofs via BlackBox
8+
9+
### Changed
10+
11+
- Tests are no longer run when the `proofs` or `properties` directories are modified
12+
- Proofs are no longer run when the `tests` directory is modified
13+
- Psalm is no longer run when the `tests` directory is modified
14+
- Coding standard is run when the `proofs` directory is modified
15+
16+
### Fixed
17+
18+
- Agents sub processes would become zombies when the parent process would crash (no longer possible as everything is done in the same process)
19+
320
## 3.7.0 - 2023-09-24
421

522
### Added

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Development tool to automate certain parts of the dev cycle.
88

99
Automatisations:
1010
- Propose to update dependencies when starting working on the project
11-
- Launch BlackBox proofs when `src`, `tests`, `fixtures` or `properties` folders are modified
12-
- Launch PHPUnit tests when `src`, `tests`, `fixtures` or `properties` folders are modified
13-
- Launch Psalm checks (if a `psalm.xml` exists) when `src` or `tests` folders are modified
14-
- Verify the code style (if a `.php_cs.dist` or `.php-cs-fixer.dist.php` file exists) when `src`, `tests`, `fixtures` or `properties` folders are modified
11+
- Launch BlackBox proofs when `src`, `proofs`, `fixtures` or `properties` folders are modified
12+
- Launch PHPUnit tests when `src`, `tests` or `fixtures` folders are modified
13+
- Launch Psalm checks (if a `psalm.xml` exists) when `src` folder is modified
14+
- Verify the code style (if a `.php_cs.dist` or `.php-cs-fixer.dist.php` file exists) when `src`, `tests`, `proofs`, `fixtures` or `properties` folders are modified
1515
- Start docker compose when there is a `docker-compose.yml` at the project root
1616

17-
![](example.gif)
17+
https://github.com/Innmind/LabStation/assets/851425/cbb99153-20db-450a-ac3a-bf68980c9ad1
1818

1919
## Installation
2020

composer.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
"php": "~8.2",
1919
"innmind/url": "~4.0",
2020
"innmind/cli": "~3.4",
21-
"innmind/operating-system": "~3.1",
21+
"innmind/operating-system": "~4.1",
2222
"innmind/json": "^1.1",
23-
"innmind/ipc": "~4.0",
24-
"innmind/process-manager": "~4.0",
25-
"innmind/server-control": "~4.2|~5.0",
26-
"innmind/immutable": "~4.4|~5.0"
23+
"innmind/immutable": "~5.2",
24+
"innmind/mantle": "~2.0"
2725
},
2826
"autoload": {
2927
"psr-4": {

example.gif

-2.55 MB
Binary file not shown.

src/Activities.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Innmind\LabStation;
5+
6+
use Innmind\CLI\Console;
7+
use Innmind\OperatingSystem\OperatingSystem;
8+
use Innmind\TimeContinuum\Earth\Period\Millisecond;
9+
use Innmind\Immutable\Set;
10+
11+
final class Activities
12+
{
13+
private Trigger $trigger;
14+
private Iteration $iteration;
15+
/** @var Set<Triggers> */
16+
private Set $triggers;
17+
/** @var list<Activity> */
18+
private array $activities;
19+
20+
/**
21+
* @param Set<Triggers> $triggers
22+
* @param list<Activity> $activities
23+
*/
24+
private function __construct(
25+
Trigger $trigger,
26+
Iteration $iteration,
27+
Set $triggers,
28+
array $activities,
29+
) {
30+
$this->trigger = $trigger;
31+
$this->iteration = $iteration;
32+
$this->triggers = $triggers;
33+
$this->activities = $activities;
34+
}
35+
36+
public function __invoke(
37+
Console $console,
38+
OperatingSystem $os,
39+
): Console {
40+
// If no activities yet we wait a little bit to avoid always calling
41+
// this method.
42+
// The better approach would be to use sockets and to monitor them so we
43+
// would call the trigger as soon as an activity occured but the agents
44+
// watch directories and the underlyin mecanism runs every second so
45+
// there is always this delay. And if we use sockets we still need to
46+
// exit this method periodically to allow the source to be restarted in
47+
// order to check if any agent crashed in order to restart it.
48+
if (\count($this->activities) === 0) {
49+
$os->process()->halt(Millisecond::of(500));
50+
}
51+
52+
while ($activity = \array_shift($this->activities)) {
53+
$this->iteration->start();
54+
$console = ($this->trigger)(
55+
$console,
56+
$os,
57+
$activity,
58+
$this->triggers,
59+
);
60+
61+
if ($activity !== Activity::start) {
62+
$console = $this->iteration->end($console);
63+
}
64+
}
65+
66+
return $console;
67+
}
68+
69+
/**
70+
* @param Set<Triggers> $triggers
71+
*/
72+
public static function new(
73+
Trigger $trigger,
74+
Iteration $iteration,
75+
Set $triggers,
76+
): self {
77+
return new self(
78+
$trigger,
79+
$iteration,
80+
$triggers,
81+
[Activity::start],
82+
);
83+
}
84+
85+
public function push(Activity $activity): self
86+
{
87+
$this->activities[] = $activity;
88+
89+
return $this;
90+
}
91+
92+
/**
93+
* Used for tests only
94+
*
95+
* @return list<Activity>
96+
*/
97+
public function toList(): array
98+
{
99+
return $this->activities;
100+
}
101+
}

src/Activity.php

+7-14
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,12 @@
33

44
namespace Innmind\LabStation;
55

6-
use Innmind\LabStation\Activity\Type;
7-
8-
final class Activity
6+
enum Activity
97
{
10-
private Type $type;
11-
12-
public function __construct(Type $type)
13-
{
14-
$this->type = $type;
15-
}
16-
17-
public function type(): Type
18-
{
19-
return $this->type;
20-
}
8+
case sourcesModified;
9+
case testsModified;
10+
case proofsModified;
11+
case fixturesModified;
12+
case propertiesModified;
13+
case start;
2114
}

src/Activity/Type.php

-35
This file was deleted.

src/Agent.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33

44
namespace Innmind\LabStation;
55

6+
use Innmind\OperatingSystem\OperatingSystem;
67
use Innmind\Url\Path;
78

89
interface Agent
910
{
10-
public function __invoke(Path $project): void;
11+
/**
12+
* In case of a crash return the agent instance to be able to restart it
13+
*/
14+
public function __invoke(
15+
OperatingSystem $os,
16+
Path $project,
17+
Activities $activities,
18+
): ?self;
1119
}

src/Agent/WatchFixtures.php

+19-44
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,34 @@
55

66
use Innmind\LabStation\{
77
Agent,
8-
Protocol,
8+
Activities,
99
Activity,
10-
Activity\Type,
11-
};
12-
use Innmind\OperatingSystem\Filesystem;
13-
use Innmind\IPC\{
14-
IPC,
15-
Process\Name,
1610
};
11+
use Innmind\OperatingSystem\OperatingSystem;
1712
use Innmind\Url\Path;
18-
use Innmind\Immutable\{
19-
Sequence,
20-
Either,
21-
};
13+
use Innmind\Immutable\Either;
2214

2315
final class WatchFixtures implements Agent
2416
{
25-
private Protocol $protocol;
26-
private Filesystem $filesystem;
27-
private IPC $ipc;
28-
private Name $monitor;
29-
30-
public function __construct(
31-
Protocol $protocol,
32-
Filesystem $filesystem,
33-
IPC $ipc,
34-
Name $monitor,
35-
) {
36-
$this->protocol = $protocol;
37-
$this->filesystem = $filesystem;
38-
$this->ipc = $ipc;
39-
$this->monitor = $monitor;
40-
}
41-
42-
public function __invoke(Path $project): void
43-
{
44-
$fixtures = $project->resolve(Path::of('fixtures'));
17+
public function __invoke(
18+
OperatingSystem $os,
19+
Path $project,
20+
Activities $activities,
21+
): ?Agent {
22+
$fixtures = $project->resolve(Path::of('fixtures/'));
23+
$filesystem = $os->filesystem();
4524

46-
if (!$this->filesystem->contains($fixtures)) {
47-
return;
25+
if (!$filesystem->contains($fixtures)) {
26+
return null;
4827
}
4928

50-
$this->filesystem->watch($fixtures)(
51-
$this->ipc,
52-
fn(IPC $ipc) => $ipc
53-
->get($this->monitor)
54-
->flatMap(fn($process) => $process->send(Sequence::of(
55-
$this->protocol->encode(new Activity(Type::fixturesModified)),
56-
)))
57-
->flatMap(static fn($process) => $process->close())
58-
->either()
59-
->map(static fn() => $ipc)
60-
->otherwise(static fn() => Either::right($ipc)), // even if it failed to send the message continue to watch for file changes
29+
$filesystem->watch($fixtures)(
30+
$activities,
31+
static fn(Activities $activities) => Either::right( // right in order to have an infinite loop
32+
$activities->push(Activity::fixturesModified),
33+
),
6134
);
35+
36+
return $this;
6237
}
6338
}

0 commit comments

Comments
 (0)