Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add docker dev #96

Merged
merged 22 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM php:8.3-cli

ENV ANSIBLE_VERSION 2.9.17

# composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& mv composer.phar /usr/bin/composer \
&& chmod +x /usr/bin/composer

# python, pipx & ansible
RUN apt-get update \
&& apt-get install -y gcc python3 git zip 7zip unzip pipx \
&& apt-get clean all; \
pipx install --upgrade pip; \
pipx install "ansible==${ANSIBLE_VERSION}"; \
pipx install ansible;

# keep container running
CMD [ "bash", "-c", "echo 'running'; tail -f /dev/null" ]
23 changes: 13 additions & 10 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ jobs:

strategy:
matrix:
php:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
include:
- php-version: "8.0"
phpunit: "9.5"
- php: "8.1"
phpunit: "10"
phpunit-config: "phpunit-10.xml.dist"
- php: "8.2"
phpunit: "11"
phpunit-config: "phpunit.xml.dist"
- php: "8.3"
phpunit: "11"
phpunit-config: "phpunit.xml.dist"

steps:
Expand All @@ -29,21 +30,23 @@ jobs:
php-version: "${{ matrix.php }}"
extensions: redis, apcu, ctype, dom, iconv, gd, mbstring, fileinfo, intl, json, mysql, bcmath, zip
coverage: none # disable xdebug, pcov
ini-values: post_max_size=256M memory
#ini-values: post_max_size=256M memory
tools: cs2pr, pecl, php-cs-fixer, vimeo/psalm, phpstan, phpcs

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: "ramsey/composer-install@v2"
- uses: "ramsey/composer-install@v3"
with:
composer-options: "--no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist -q"

- name: PHPUnit tests
uses: php-actions/phpunit@v3
with:
version: "${{ matrix.phpunit }}"
php_version: "${{matrix.php}}"
configuration: "${{ matrix.phpunit-config }}"
memory_limit: "256M"
test_suffix: .php

- name: Run phpstan
run: phpstan analyse --error-format=checkstyle -c "phpstan.neon" | cs2pr
Expand Down
1 change: 0 additions & 1 deletion Asm/Ansible/Ansible.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Asm\Ansible\Process\ProcessBuilder;
use Asm\Ansible\Process\ProcessBuilderInterface;
use Asm\Ansible\Utils\Env;
use JetBrains\PhpStorm\Pure;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
Expand Down
2 changes: 1 addition & 1 deletion Asm/Ansible/Command/AnsiblePlaybook.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,4 @@ private function checkInventory(): void
$this->inventoryFile($inventory);
}
}
}
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ $ansible
```

## Development

You can use the provided docker image with ```docker compose up``` which uses a default php-cli docker image and ansible 2.x. See the ```.docker/Dockerfile``` for more info.

Composer install: ```docker exec -u <YOUR_UID> -w /var/php-ansible -it php-ansible composer install```

You can run code or the tests within the container: ```docker exec -u <YOUR_UID> -w /var/php-ansible -it php-ansible php ./vendor/bin/phpunit --testdox```

## Thank you for your contributions!

Expand All @@ -178,7 +184,6 @@ The Next steps for implementation are:
- improve type handling and structure, due to overall complexity of the playbook at the moment
- scalar typehints all over the place
- provide docker support for development
- move to php8.0 exclusively for the next major release
- wrapping the library into a bundle -> maybe
- provide commandline-capabilities -> maybe

Expand Down
58 changes: 11 additions & 47 deletions Tests/Asm/Ansible/AnsibleTest.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
<?php
/*
* This file is part of the php-ansible package.
*
* (c) Marc Aschmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Asm\Ansible;

use Asm\Ansible\Exception\CommandException;
use Asm\Ansible\Testing\AnsibleTestCase;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\CoversFunction;

#[CoversClass(\Asm\Ansible\Ansible::class)]
#[CoversFunction('playbook')]
#[CoversFunction('createProcess')]
#[CoversFunction('checkCommand')]
#[CoversFunction('checkDir')]
#[CoversFunction('__construct')]
class AnsibleTest extends AnsibleTestCase
{
/**
* @covers \Asm\Ansible\Ansible::checkCommand
* @covers \Asm\Ansible\Ansible::checkDir
* @covers \Asm\Ansible\Ansible::__construct
*/

public function testInstance()
{
$ansible = new Ansible(
Expand All @@ -31,11 +29,6 @@ public function testInstance()
$this->assertInstanceOf('\Asm\Ansible\Ansible', $ansible, 'Instantiation with given paths');
}

/**
* @covers \Asm\Ansible\Ansible::checkCommand
* @covers \Asm\Ansible\Ansible::checkDir
* @covers \Asm\Ansible\Ansible::__construct
*/
public function testAnsibleProjectPathNotFoundException()
{
$this->expectException(CommandException::class);
Expand All @@ -46,11 +39,6 @@ public function testAnsibleProjectPathNotFoundException()
);
}

/**
* @covers \Asm\Ansible\Ansible::checkCommand
* @covers \Asm\Ansible\Ansible::checkDir
* @covers \Asm\Ansible\Ansible::__construct
*/
public function testAnsibleCommandNotFoundException()
{
$this->expectException(CommandException::class);
Expand All @@ -61,11 +49,6 @@ public function testAnsibleCommandNotFoundException()
);
}

/**
* @covers \Asm\Ansible\Ansible::checkCommand
* @covers \Asm\Ansible\Ansible::checkDir
* @covers \Asm\Ansible\Ansible::__construct
*/
public function testAnsibleNoCommandGivenException()
{
// TODO: Not sure why the following command should give an error.
Expand All @@ -75,11 +58,6 @@ public function testAnsibleNoCommandGivenException()
// );
}

/**
* @covers \Asm\Ansible\Ansible::checkCommand
* @covers \Asm\Ansible\Ansible::checkDir
* @covers \Asm\Ansible\Ansible::__construct
*/
public function testAnsibleCommandNotExecutableException()
{
$this->expectException(CommandException::class);
Expand All @@ -94,13 +72,6 @@ public function testAnsibleCommandNotExecutableException()
);
}

/**
* @covers \Asm\Ansible\Ansible::playbook
* @covers \Asm\Ansible\Ansible::createProcess
* @covers \Asm\Ansible\Ansible::checkCommand
* @covers \Asm\Ansible\Ansible::checkDir
* @covers \Asm\Ansible\Ansible::__construct
*/
public function testPlaybookCommandInstance()
{
$ansible = new Ansible(
Expand All @@ -114,13 +85,6 @@ public function testPlaybookCommandInstance()
$this->assertInstanceOf('\Asm\Ansible\Command\AnsiblePlaybook', $playbook);
}

/**
* @covers \Asm\Ansible\Ansible::galaxy
* @covers \Asm\Ansible\Ansible::createProcess
* @covers \Asm\Ansible\Ansible::checkCommand
* @covers \Asm\Ansible\Ansible::checkDir
* @covers \Asm\Ansible\Ansible::__construct
*/
public function testGalaxyCommandInstance()
{
$ansible = new Ansible(
Expand Down
7 changes: 2 additions & 5 deletions Tests/Asm/Ansible/Command/AnsibleGalaxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ public function testCreateInstance(): AnsibleGalaxyInterface
return $ansibleGalaxy;
}

/**
* @depends testCreateInstance
* @param AnsibleGalaxyInterface $command
*/
public function testExecute(AnsibleGalaxyInterface $command): void
public function testExecute(): void
{
// Skipped on Windows
if (Env::isWindows()) {
$this->assertTrue(true);
return;
}

$command = $this->testCreateInstance();
$command->execute();

// if command executes without exception
Expand Down
Loading