Skip to content

Commit

Permalink
skeleton (tmp)
Browse files Browse the repository at this point in the history
  • Loading branch information
shudd3r committed Oct 2, 2022
1 parent 33c6e64 commit f7fa57e
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/skeleton.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"package.name": "Polymorphine/Dev",
"repository.name": "polymorphine/dev",
"package.description": "Development tools & coding standard scripts for Polymorphine libraries",
"namespace.src": "Polymorphine\\Dev",
"author.name": "Shudd3r",
"author.email": "q3.shudder@gmail.com",
"current.year": "2022"
}
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
run: |
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist src
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist --ignore=*/CodeSamples/* tests
- name: "Package skeleton validation"
run: php polymorphine-skeleton check
- name: "Run PhpUnit tests with coverage"
run: |
mkdir -p build/logs
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests",
"phpcs --extensions=php --standard=phpcs.xml.dist src",
"phpcs --extensions=php --standard=phpcs.xml.dist --ignore=*/CodeSamples/* tests"
]
}
],
"test-php": "phpunit",
"test-skeleton": "@php polymorphine-skeleton check"
},
"bin": [
"polymorphine-skeleton"
]
}
75 changes: 75 additions & 0 deletions polymorphine-skeleton
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

/*
* This file is part of Polymorphine/Dev package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

use Shudd3r\Skeletons\Application;
use Shudd3r\Skeletons\InputArgs;
use Shudd3r\Skeletons\Environment\Files\Directory\LocalDirectory;
use Shudd3r\Skeletons\Replacements\Replacement;
use Shudd3r\Skeletons\Templates\Contents;
use Shudd3r\Skeletons\Templates\Template;

// This script should be executed from package root directory
$rootDirectory = getcwd();
if (!file_exists($rootDirectory . '/vendor/autoload.php')) {
fwrite(STDERR, 'Cannot find vendor/autoload.php file in package root directory');
die(1);
}

if (!file_exists($rootDirectory . '/composer.json')) {
fwrite(STDERR, 'Cannot find composer.json file in package root directory');
die(1);
}

require_once $rootDirectory . '/vendor/autoload.php';

$args = new InputArgs($argv ?? []);

$skeleton = new LocalDirectory(__DIR__ . '/template');
$package = new LocalDirectory($rootDirectory);
$app = new Application($package, $skeleton);

$app->backup(new LocalDirectory(__DIR__ . '/.dev/.skeleton-backup'));

$app->replacement('package.name')->add(new Replacement\PackageName());
$app->replacement('repository.name')->add(new Replacement\RepositoryName('package.name'));
$app->replacement('package.description')->add(new Replacement\PackageDescription('package.name'));
$app->replacement('namespace.src')->add(new Replacement\SrcNamespace('package.name'));
$app->replacement('author.name')
->build(fn () => 'Author Name')
->argumentName('author')
->inputPrompt('Your name or nickname')
->description('Package author\'s name [format: non-empty string]')
->validate(fn (string $value) => !empty($value));
$app->replacement('author.email')
->build(fn () => 'default@example.com')
->argumentName('email')
->inputPrompt('Your email address')
->description('Package author\'s email address [format: <username>@<domain>]')
->validate(fn (string $value) => $value === filter_var($value, FILTER_VALIDATE_EMAIL));
$app->replacement('current.year')
->build(fn () => date('Y'));

$inSelfContext = $rootDirectory === __DIR__;
$app->template('composer.json')->createWith(function (Contents $contents) use ($inSelfContext, $args) {
$placeholders = ['${tpl.require-dev}', '${tpl.php-exec}'];
$replacements = $inSelfContext ? ['null', '@php '] : ['{ "polymorphine/dev": null }', ''];
$baseTemplate = new Template\BasicTemplate(str_replace($placeholders, $replacements, $contents->template()));
return new Template\MergedJsonTemplate($baseTemplate, $contents->package(), $args->command() === 'update');
});

$app->template('.github/workflows/build.yml')->createWith(function (Contents $contents) use ($inSelfContext) {
$replacement = $inSelfContext ? 'php ' : 'vendor/bin/';
return new Template\BasicTemplate(str_replace('${tpl.php-exec}', $replacement, $contents->template()));
});

$exitCode = $app->run($args);
exit($exitCode);
5 changes: 5 additions & 0 deletions template/.git.sk_dir/hooks/pre-push.sk_local
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

composer.phar test-cs
vendor/bin/phpunit
vendor/bin/polymorphine-skeleton check
7 changes: 7 additions & 0 deletions template/.gitattributes.sk_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.github export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpunit.xml.dist export-ignore
cs-fixer.php.dist export-ignore
{original.content}
110 changes: 110 additions & 0 deletions template/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: build
on: [push, pull_request]

jobs:
full-build:
name: "Coding standards & coverage tests"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['7.4']
env:
extensions: pcov, dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
key: cache-v2
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: "Setup PHP extensions cache environment"
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: "Cache PHP extensions"
uses: actions/cache@v2
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
extensions: ${{ env.extensions }}
ini-values: assert.exception=1, zend.assertions=1
- name: "Validate composer.json"
run: composer validate
- name: "Setup composer cache"
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: "Install highest dependencies"
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable
- name: "Coding standard Php-CS-Fixer checks"
run: vendor/bin/php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests
- name: "Coding standard CodeSniffer checks"
run: |
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist src
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist --ignore=*/CodeSamples/* tests
- name: "Package skeleton validation"
run: ${tpl.php-exec}polymorphine-skeleton check
- name: "Run PhpUnit tests with coverage"
run: |
mkdir -p build/logs
vendor/bin/phpunit --exclude-group integrated --coverage-clover build/logs/clover.xml
- name: "Send coverage report to coveralls.io"
run: vendor/bin/php-coveralls -v
env:
COVERALLS_RUN_LOCALLY: 1
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

php-os-builds:
name: "PHP 8 tests"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest']
php-versions: ['8.0', '8.1']
env:
extensions: dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
key: cache-v2
steps:
- name: "Turn off git EOL conversion"
run: git config --global core.autocrlf false
- name: "Checkout"
uses: actions/checkout@v2
- name: "Setup PHP extensions cache environment"
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: "Cache PHP extensions"
uses: actions/cache@v2
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
extensions: ${{ env.extensions }}
ini-values: assert.exception=1, zend.assertions=1
- name: "Setup composer cache"
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: ${{ runner.os }}-php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-php${{ matrix.php-versions }}-composer-
- name: "Install highest dependencies"
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable
- name: "Run PhpUnit tests (no coverage)"
run: vendor/bin/phpunit --exclude-group integrated --no-coverage
4 changes: 4 additions & 0 deletions template/.gitignore.sk_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.dev/
/vendor/
/composer.lock
{original.content}
21 changes: 21 additions & 0 deletions template/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) {current.year} {author.name} <{author.email}>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# {package.name}
[![Latest Stable Version](https://poser.pugx.org/{package.name.composer}/version)](https://packagist.org/packages/{package.name.composer})
[![Build status](https://github.com/{repository.name}/workflows/build/badge.svg)](https://github.com/{repository.name}/actions)
[![Coverage status](https://coveralls.io/repos/github/{repository.name}/badge.svg?branch=develop)](https://coveralls.io/github/{repository.name}?branch=develop)
[![PHP version](https://img.shields.io/packagist/php-v/{package.name.composer}.svg)](https://packagist.org/packages/{package.name.composer})
[![LICENSE](https://img.shields.io/github/license/{repository.name}.svg?color=blue)](LICENSE)
### {package.description}

{original.content>>>Your content here...<<<original.content}
38 changes: 38 additions & 0 deletions template/composer.json.sk_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "{package.name.composer}",
"description": "{package.description}",
"type": null,
"license": null,
"authors": [
{
"name": "{author.name}",
"email": "{author.email}",
"homepage": null,
"role": null
}
],
"minimum-stability": null,
"require": {
"php": null
},
"require-dev": ${tpl.require-dev},
"autoload": {
"psr-4": {
"{namespace.src.esc}\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"{namespace.src.esc}\\Tests\\": "tests/"
}
},
"scripts": {
"test-cs": [
"php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests",
"phpcs --extensions=php --standard=phpcs.xml.dist src",
"phpcs --extensions=php --standard=phpcs.xml.dist --ignore=*/CodeSamples/* tests"
],
"test-php": "phpunit",
"test-skeleton": "${tpl.php-exec}polymorphine-skeleton check"
}
}
16 changes: 16 additions & 0 deletions template/cs-fixer.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

/*
* This file is part of {package.name} package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

use Polymorphine\Dev\FixerFactory;

{original.content}

return FixerFactory::createFor('{package.name}'{original.content});
22 changes: 22 additions & 0 deletions template/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
cacheResultFile=".dev/temp/.phpunit.result.cache"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="{package.name} tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory>./src/</directory>
</include>
</coverage>
</phpunit>
19 changes: 19 additions & 0 deletions template/src/Example.php.sk_dummy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

/*
* This file is part of {package.name} package.
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace {namespace.src};


class Example
{
public function welcome(string $name = 'World'): string
{
return 'Hello ' . $name . '!';
}
}

0 comments on commit f7fa57e

Please sign in to comment.