Skip to content
Open

V2 #48

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1699dc4
Updates for PHP >=8.0
Brunty Sep 19, 2023
db08652
Remove un-needed dir in psr-4 dev autoloading
Brunty Sep 19, 2023
4a29c11
Only support PHP 8.1 and PHP 8.2
Brunty Sep 19, 2023
a7c99ef
Only support PHP 8.1 and PHP 8.2
Brunty Sep 19, 2023
f8bdde1
Coveralls
Brunty Sep 19, 2023
c241dd4
WIP: Remove coveralls for now
Brunty Sep 19, 2023
80503f1
Cigar 2.0 Dockerfile
Brunty Sep 19, 2023
ad0419f
Move from .cigar.json to just cigar.json default config file
Brunty Sep 19, 2023
75cfe0c
Forcing an empty commit to fix github weirdness?
Brunty Sep 19, 2023
adb132f
Rename example config file
Brunty Sep 19, 2023
74ed453
Refactor getopt into Input and InputOption class
Brunty Sep 21, 2023
5dd7f67
Code standards and static analysis updates
Brunty Sep 21, 2023
cbf26c3
Add github workflow for analysis
Brunty Sep 21, 2023
138f908
Update master -> main for GH actions
Brunty Sep 21, 2023
66aa1dc
Remove phpcs cache
Brunty Sep 21, 2023
fe1e9d2
Rename code analysis workflow
Brunty Sep 21, 2023
e0e3947
Add BC notes to readme
Brunty Sep 21, 2023
78d2593
Proper || on PHP requirement
Brunty Sep 21, 2023
bb5d16b
Start porting tests to PHPUnit with infection
Brunty Sep 24, 2023
02f585a
Refactor Parser -> ConfigParser
Brunty Sep 24, 2023
9c94a24
Config parser test
Brunty Sep 24, 2023
e30c781
More test updates lol messy commits
Brunty Sep 24, 2023
531b96e
A bunch of refactoring innit
Brunty Sep 24, 2023
f4f6262
More testing for output!
Brunty Sep 24, 2023
1c8f50a
More tests
Brunty Sep 24, 2023
60ff1ad
Fix phpcs
Brunty Sep 24, 2023
3c4a1f5
Move from kahlan to phpunit in CI tests
Brunty Sep 24, 2023
7537ec8
Remove kahlan dependency
Brunty Sep 24, 2023
41bc17e
Remove kahlan dependency in docs
Brunty Sep 24, 2023
52a9684
Infection config to ignore AsyncChecker
Brunty Sep 24, 2023
6baa12a
CS fix
Brunty Sep 24, 2023
01bb02d
Start adding command line tests
Brunty Sep 24, 2023
9207a7f
Command line tool tests
Brunty Sep 27, 2023
45b5e02
Exit code refactoring to enum to stop magic numbers
Brunty Sep 27, 2023
f34ec0b
Refactor console escape codes to new enum
Brunty Sep 30, 2023
1d97f75
Add some colour to socials output
Brunty Sep 30, 2023
77bfcfd
Update docker build docs for 2.0.0
Brunty Sep 30, 2023
79841a0
Improve psalm strictness and mutation coverage
Brunty Oct 3, 2023
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Ignoring files for distribution archives
spec/ export-ignore
.cigar.json.example export-ignore
cigar.json.example export-ignore
.coveralls.yml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Code Analysis
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2']
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: curl #optional
coverage: xdebug
- name: Check PHP Version
run: php -v
- name: Install dependencies
run: composer install
- name: Run PHP_CS
run: vendor/bin/phpcs -p --colors --standard=phpcs.xml
- name: Run Psalm
run: vendor/bin/psalm --config=psalm.xml --show-info=true
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Tests
on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.1', '7.2', '7.3', '7.4']
php-versions: ['8.1', '8.2']
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}
steps:
- name: Checkout
Expand All @@ -26,7 +26,7 @@ jobs:
run: php -v
- name: Install dependencies
run: composer install
- name: Run Kahlan
run: vendor/bin/kahlan --reporter=verbose --clover=coverage.xml
- name: Coveralls
run: php vendor/bin/coveralls
- name: Run Tests
run: composer test
#- name: Coveralls
# run: php vendor/bin/php-coveralls
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/vendor
/composer.lock
cigar.json
.cigar.json
.idea
coverage.xml
clover.xml
cache/
build/
tests/ConfigExamples/cigar.json
tests/ConfigExamples/alt.json
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This Code of Conduct is adapted from the Contributor Covenant, version 1.1.0, av
1. Fork the repository
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Install dependencies (`composer install`)
4. Cigar uses [Kahlan](https://kahlan.github.io/docs/) as test runner. The integration tests reside within the `spec` directory. So, please make sure all test suite pass (`vendor/bin/kahlan --reporter=verbose`)
4. Cigar uses [PHPUnit](https://phpunit.de/) as test runner. The tests reside within the `tests` directory. So, please make sure all tests pass with `composer test`
5. Commit your changes (`git commit -am 'Add some feature'`)
6. Push to the branch (`git push origin my-new-feature`)
7. Create new Pull Request
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cigar

[![Build Status](https://travis-ci.org/Brunty/cigar.svg?branch=master)](https://travis-ci.org/Brunty/cigar) [![Coverage Status](https://coveralls.io/repos/github/Brunty/cigar/badge.svg?branch=master)](https://coveralls.io/github/Brunty/cigar?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/d89a0b55-8ce6-4f85-a09c-7852d986225f/mini.png)](https://insight.sensiolabs.com/projects/d89a0b55-8ce6-4f85-a09c-7852d986225f)
[![Build Status](https://travis-ci.org/Brunty/cigar.svg?branch=main)](https://travis-ci.org/Brunty/cigar) [![Coverage Status](https://coveralls.io/repos/github/Brunty/cigar/badge.svg?branch=master)](https://coveralls.io/github/Brunty/cigar?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/d89a0b55-8ce6-4f85-a09c-7852d986225f/mini.png)](https://insight.sensiolabs.com/projects/d89a0b55-8ce6-4f85-a09c-7852d986225f)

A smoke testing tool inspired by [symm/vape](https://github.com/symm/vape)

Expand All @@ -18,9 +18,17 @@ Pull via docker:

`docker pull brunty/cigar`

## Upgrading from V1 - Breaking Changes

- `.cigar.json` default config file name is now just `cigar.json`
- No longer testing against PHP 7.X and PHP 8.0
- Command line option changes:
- `-c` is now `-f` for config file
- `-s` is now `-c` for connect-timeout

## To use

Create a `.cigar.json` file that contains an array of json objects specifying the `url`, `status`, (optional) `content`, and (optional) `content-type` to check.
Create a `cigar.json` file that contains an array of json objects specifying the `url`, `status`, (optional) `content`, and (optional) `content-type` to check.

```
[
Expand Down
150 changes: 85 additions & 65 deletions bin/cigar
Original file line number Diff line number Diff line change
@@ -1,108 +1,128 @@
#!/usr/bin/env php
<?php

define('CIGAR_VERSION', '1.12.3');
$start = microtime(true);
define('CIGAR_VERSION', '2.0.0');

foreach (['/../../..', '/../..', '/../vendor', '/vendor'] as $autoloadFileDirectory) {
if (file_exists(__DIR__ . $autoloadFileDirectory . '/autoload.php')) {
/** @psalm-suppress UnresolvableInclude */
require __DIR__ . $autoloadFileDirectory . '/autoload.php';
break;
}
}

use Brunty\Cigar\AsyncChecker;
use Brunty\Cigar\ConsoleColours;
use Brunty\Cigar\EchoWriter;
use Brunty\Cigar\ExitCode;
use Brunty\Cigar\Input;
use Brunty\Cigar\InputOption;
use Brunty\Cigar\InputOptions;
use Brunty\Cigar\JsonWriter;
use Brunty\Cigar\Outputter;
use Brunty\Cigar\Parser;
use Brunty\Cigar\Result;
use Brunty\Cigar\Output;
use Brunty\Cigar\ConfigParser;
use Brunty\Cigar\QuietWriter;
use Brunty\Cigar\SystemTimer;

$options = getopt('c:ia:u:jh:t:s:', ['version', 'help', 'quiet', 'config:', 'insecure', 'auth:', 'url:', 'json', 'header:', 'timeout:', 'connect-timeout:']);
$timer = new SystemTimer();
$start = $timer->now();

if (isset($options['help'])) {
$content = <<<HELP
$inputOptions = new InputOptions([
'config' => InputOption::create('config', 'f', InputOption::VALUE_REQUIRED, 'Use the specified config file instead of the default cigar.json file'),

\033[33mUsage:\033[0m
cigar [options]
'auth' => InputOption::create('auth', 'a', InputOption::VALUE_REQUIRED, 'Authorization header "<type> <credentials>"'),
'header' => InputOption::create('header', 'h', InputOption::VALUE_REQUIRED, 'Custom header "<name>: <value>", can be passed multiple times to send multiple headers'),
'insecure' => InputOption::create('insecure', 'i', InputOption::VALUE_NONE, 'Allow invalid SSL certificates'),
'url' => InputOption::create('url', 'u', InputOption::VALUE_REQUIRED, 'Base URL for checks, e.g. https://example.org/'),

'connect-timeout' => InputOption::create('connect-timeout', 'c', InputOption::VALUE_REQUIRED, 'Connect Timeout in seconds'),
'timeout' => InputOption::create('timeout', 't', InputOption::VALUE_REQUIRED, 'Timeout in seconds'),

'quiet' => InputOption::create('quiet', 'q', InputOption::VALUE_NONE, 'Do not output any message'),
'json' => InputOption::create('json', 'j', InputOption::VALUE_NONE, 'Output JSON'),

'help' => InputOption::create('help', '', InputOption::VALUE_NONE, 'Show the help message'),
'version' => InputOption::create('version', '', InputOption::VALUE_NONE, 'Print the version of Cigar'),
]);

$input = new Input($inputOptions, getopt($inputOptions->shortCodes, $inputOptions->longCodes));

$output = new Output(
$input->getOption('quiet')
? new QuietWriter()
: ($input->getOption('json') ? new JsonWriter() : new EchoWriter()),
$timer,
);

$consoleCyan = ConsoleColours::cyan();
$consoleYellow = ConsoleColours::yellow();
$consoleGrey = ConsoleColours::grey();
$consoleReset = ConsoleColours::reset();

if ($input->getOption('help')) {
echo <<<HELP

\033[33mOptions:\033[0m
\033[32m-c file.json, --config=file.json\033[0m Use the specified config file instead of the default .cigar.json file
\033[32m-u URL, --url=URL\033[0m Base URL for checks, e.g. https://example.org/
\033[32m-i, --insecure\033[0m Allow invalid SSL certificates
\033[32m-a, --auth\033[0m Authorization header "\074type\076 \074credentials\076"
\033[32m-h, --header\033[0m Custom header "\074name\076: \074value\076"
\033[32m-s --connect-timeout=TIMEOUT\033[0m Connect Timeout
\033[32m-t, --timeout=TIMEOUT\033[0m Timeout
\033[32m-j, --json\033[0m Output JSON
\033[32m --quiet\033[0m Do not output any message
\033[32m --version\033[0m Print the version of Cigar
{$consoleYellow}Usage:{$consoleReset}
cigar [options]

{$output->generateHelpOutputForOptions($inputOptions)}

Created by Matt Brunt
E: matt@mfyu.co.uk
T: twitter.com/Brunty
G: github.com/brunty/cigar
{$consoleCyan}E:{$consoleReset} matt@brunty.me
{$consoleCyan}M:{$consoleReset} brunty.social/@brunty
{$consoleCyan}T:{$consoleReset} twitter.com/Brunty
{$consoleCyan}G:{$consoleReset} github.com/brunty/cigar

HELP;
echo $content;
exit(0);
exit(ExitCode::SUCCESS->value);
}

if (isset($options['version'])) {
if ($input->getOption('version')) {
$version = CIGAR_VERSION;
$content = <<<VERSION
____ ___ ____ _ ____
/ ___|_ _/ ___| / \ | _ \
echo <<<VERSION
____ ___ ____ _ ____
/ ___|_ _/ ___| / \ | _ \
| | | | | _ / _ \ | |_) |
| |___ | | |_| |/ ___ \| _ <
| |___ | | |_| |/ ___ \| _ <
\____|___\____/_/ \_\_| \_\

\033[0;90;49mThe simple smoke testing tool.\033[0m

Version \033[36m{$version}\033[0m
{$consoleGrey}The simple smoke testing tool.{$consoleReset}

For additional help use \033[36m--help\033[0m
Version {$consoleCyan}$version{$consoleReset}

For additional help use {$consoleCyan}--help{$consoleReset}


VERSION;
echo $content;
exit(0);
exit(ExitCode::SUCCESS->value);
}

$writer = isset($options['j']) || isset($options['json']) ? new JsonWriter() : new EchoWriter();
$outputter = new Outputter(isset($options['quiet']), $writer);

$file = $options['c'] ?? ($options['config'] ?? '.cigar.json');
$baseUrl = $options['u'] ?? ($options['url'] ?? null);
$configFile = (string) $input->getOption('config') ?: 'cigar.json';
$baseUrl = (string) $input->getOption('url') ?: null;

if ( ! file_exists($file)) {
$outputter->writeErrorLine('Could not find configuration file: ' . $file);
exit(1);
if ( ! file_exists($configFile)) {
$output->writeErrorLine('Could not find configuration file: ' . $configFile);
exit(ExitCode::FAILURE->value);
}

$secure = ! (isset($options['i']) || isset($options['insecure']));
$authorization = $options['a'] ?? $options['auth'] ?? null;
$headers = (array) ($options['h'] ?? $options['header'] ?? []);
$connectTimeout = $options['s'] ?? $options['connect-timeout'] ?? null;
$timeout = $options['t'] ?? $options['timeout'] ?? null;

try {
$domains = (new Parser($baseUrl, $connectTimeout, $timeout))->parse($file);
} catch (\Throwable $e) {
$outputter->writeErrorLine(sprintf('Unable to parse Cigar JSON file: %s', $e->getMessage()));
exit(1);
$configParser = new ConfigParser(
$baseUrl,
(int) $input->getOption('connect-timeout') ?: null,
(int) $input->getOption('timeout') ?: null,
);
$domains = $configParser->parse($configFile);
} catch (Throwable $e) {
$output->writeErrorLine(sprintf('Unable to parse Cigar JSON file: %s', $e->getMessage()));
exit(ExitCode::FAILURE->value);
}

$results = (new AsyncChecker($secure, $authorization, $headers))->check($domains);
$passedResults = array_filter($results, function (Result $result) {
return $result->hasPassed();
});

$outputter->outputResults($passedResults, $results, $start);
$results = (new AsyncChecker(
! $input->getOption('insecure'),
(string) $input->getOption('auth') ?: null,
(array) $input->getOption('header') ?: [],
))->check($domains);

if (count($passedResults) !== count($results)) {
exit(1);
}
$output->outputResults($results, $start);

exit(0);
exit($results->hasPassed() ? ExitCode::SUCCESS->value : ExitCode::FAILURE->value);
File renamed without changes.
31 changes: 25 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"authors": [
{
"name": "Matt Brunt",
"email": "matt@mfyu.co.uk"
"email": "matt@brunty.me"
}
],
"autoload": {
Expand All @@ -20,20 +20,39 @@
}
},
"require": {
"php": ">=7.0",
"php": "8.1.*||8.2.*",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"symfony/process": "^3.3",
"mikey179/vfsstream": "^1.6",
"satooshi/php-coveralls": "^1.0",
"kahlan/kahlan": "^4.0"
"php-coveralls/php-coveralls": "^2.6",
"symfony/process": "^6.3",
"vimeo/psalm": "^5.15",
"squizlabs/php_codesniffer": "^3.7",
"slevomat/coding-standard": "^8.13",
"phpunit/phpunit": "^10.3",
"infection/infection": "^0.27.2"
},
"bin": [
"bin/cigar"
],
"scripts": {
"test": "vendor/bin/kahlan --reporter=verbose"
"test": "XDEBUG_MODE=coverage php vendor/bin/phpunit --color=always --coverage-html=./build/coverage",
"test:unit": "@test --testsuite=unit",
"test:mutation": "vendor/bin/infection",
"psalm": "vendor/bin/psalm --config=psalm.xml --show-info=true --no-cache",
"cs": "vendor/bin/phpcs -p --colors --standard=phpcs.xml",
"cs:fix": "vendor/bin/phpcbf -p --colors --standard=phpcs.xml",
"check": [
"@psalm",
"@cs"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true
}
}
}
24 changes: 24 additions & 0 deletions docker/2.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Cigar Docker Container
FROM composer AS composer

FROM php:8.2-cli-alpine

LABEL maintainer="matt@brunty.me"

COPY --from=composer /usr/bin/composer /usr/bin/composer

# Goto temporary directory
WORKDIR /tmp

# Run composer and cigar installation.
RUN composer require "brunty/cigar:^2.0" --optimize-autoloader --prefer-dist --no-scripts && \
ln -s /tmp/vendor/bin/cigar /usr/local/bin/cigar

# Set up the application directory.
VOLUME ["/app"]
WORKDIR /app

# Set up the command arguments.
ENTRYPOINT ["/usr/local/bin/cigar"]


Loading