Skip to content

Commit 0787dcd

Browse files
committed
Added scripted package skeleton template
2 parents ccd5f75 + 4b50859 commit 0787dcd

File tree

15 files changed

+393
-5
lines changed

15 files changed

+393
-5
lines changed

.github/skeleton.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"package.name": "Polymorphine/Dev",
3+
"repository.name": "polymorphine/dev",
4+
"package.description": "Development tools & coding standard scripts for Polymorphine libraries",
5+
"namespace.src": "Polymorphine\\Dev",
6+
"author.name": "Shudd3r",
7+
"author.email": "q3.shudder@gmail.com"
8+
}

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ jobs:
5050
- name: "Coding standard CodeSniffer checks"
5151
run: |
5252
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist src
53-
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist --ignore=*/CodeSamples/* tests
53+
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist --ignore=tests/CodeSamples/* tests
54+
- name: "Package skeleton validation"
55+
run: php polymorphine-skeleton check
5456
- name: "Run PhpUnit tests with coverage"
5557
run: |
5658
mkdir -p build/logs

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Polymorphine/Dev
2-
[![Latest Stable Version](https://poser.pugx.org/polymorphine/dev/version)](https://packagist.org/packages/polymorphine/dev)
2+
[![Latest stable release](https://poser.pugx.org/polymorphine/dev/version)](https://packagist.org/packages/polymorphine/dev)
33
[![Build status](https://github.com/polymorphine/dev/workflows/build/badge.svg)](https://github.com/polymorphine/dev/actions)
44
[![Coverage status](https://coveralls.io/repos/github/polymorphine/dev/badge.svg?branch=develop)](https://coveralls.io/github/polymorphine/dev?branch=develop)
55
[![PHP version](https://img.shields.io/packagist/php-v/polymorphine/dev.svg)](https://packagist.org/packages/polymorphine/dev)

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"friendsofphp/php-cs-fixer": "3.9.*",
1616
"squizlabs/php_codesniffer": "^3.7.1",
1717
"phpunit/phpunit": "^9.5.21",
18-
"php-coveralls/php-coveralls": "^2.5.2"
18+
"php-coveralls/php-coveralls": "^2.5.2",
19+
"shudd3r/skeletons": "~0.5.3"
1920
},
2021
"autoload": {
2122
"psr-4": {
@@ -27,11 +28,16 @@
2728
"Polymorphine\\Dev\\Tests\\": "tests/"
2829
}
2930
},
31+
"bin": [
32+
"polymorphine-skeleton"
33+
],
3034
"scripts": {
3135
"test-cs": [
3236
"php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests",
3337
"phpcs --extensions=php --standard=phpcs.xml.dist src",
34-
"phpcs --extensions=php --standard=phpcs.xml.dist --ignore=*/CodeSamples/* tests"
35-
]
38+
"phpcs --extensions=php --standard=phpcs.xml.dist --ignore=tests/CodeSamples/* tests"
39+
],
40+
"test-php": "phpunit",
41+
"test-skeleton": "@php polymorphine-skeleton check"
3642
}
3743
}

polymorphine-skeleton

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env php
2+
<?php declare(strict_types=1);
3+
4+
/*
5+
* This file is part of Polymorphine/Dev package.
6+
*
7+
* (c) Shudd3r <q3.shudder@gmail.com>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
use Shudd3r\Skeletons\Application;
14+
use Shudd3r\Skeletons\InputArgs;
15+
use Shudd3r\Skeletons\Environment\Files\Directory\LocalDirectory;
16+
use Shudd3r\Skeletons\Replacements\Replacement;
17+
use Shudd3r\Skeletons\Replacements\Source;
18+
use Shudd3r\Skeletons\Templates\Contents;
19+
use Shudd3r\Skeletons\Templates\Template;
20+
21+
// This script should be executed from package root directory
22+
$rootDirectory = getcwd();
23+
if (!file_exists($rootDirectory . '/vendor/autoload.php')) {
24+
fwrite(STDERR, 'Cannot find vendor/autoload.php file in package root directory');
25+
die(1);
26+
}
27+
28+
if (!file_exists($rootDirectory . '/composer.json')) {
29+
fwrite(STDERR, 'Cannot find composer.json file in package root directory');
30+
die(1);
31+
}
32+
33+
require_once $rootDirectory . '/vendor/autoload.php';
34+
35+
$args = new InputArgs($argv ?? []);
36+
37+
$skeleton = new LocalDirectory(__DIR__ . '/template');
38+
$package = new LocalDirectory($rootDirectory);
39+
$app = new Application($package, $skeleton);
40+
41+
$app->backup(new LocalDirectory($rootDirectory . '/.dev/.skeleton-backup'));
42+
43+
$app->replacement('package.name')->add(new Replacement\PackageName());
44+
$app->replacement('repository.name')->add(new Replacement\RepositoryName('package.name'));
45+
$app->replacement('package.description')->add(new Replacement\PackageDescription('package.name'));
46+
$app->replacement('namespace.src')->add(new Replacement\SrcNamespace('package.name'));
47+
$app->replacement('author.name')
48+
->build(fn (Source $source) => $source->composer()->value('authors.0.name') ?? 'Author Name')
49+
->argumentName('author')
50+
->inputPrompt('Author\'s name')
51+
->description('Name of package author [format: non-empty string]' . PHP_EOL . 'Replaces {%s} placeholder')
52+
->validate(fn (string $value) => !empty($value));
53+
$app->replacement('author.email')
54+
->build(fn (Source $source) => $source->composer()->value('authors.0.email') ?? 'default@example.com')
55+
->argumentName('email')
56+
->inputPrompt('Author\'s email address')
57+
->description('Email address of package author [format: <username>@<domain>]' . PHP_EOL . 'Replaces {%s} placeholder')
58+
->validate(fn (string $value) => $value === filter_var($value, FILTER_VALIDATE_EMAIL));
59+
60+
$isUpdate = $args->command() === 'update';
61+
$isSelf = $rootDirectory === __DIR__;
62+
63+
$app->template('composer.json')->createWith(function (Contents $contents) use ($isSelf, $isUpdate) {
64+
$placeholders = ['{$tpl.REQUIRE_DEV}', '{$tpl.PHP_EXEC}', '{$tpl.PHPCS}'];
65+
$replacements = $isSelf
66+
? ['null', '@php ', 'phpcs.xml.dist']
67+
: ['{ "polymorphine/dev": null }', '', 'vendor/polymorphine/dev/phpcs.xml'];
68+
$baseTemplate = new Template\BasicTemplate(str_replace($placeholders, $replacements, $contents->template()));
69+
return new Template\MergedJsonTemplate($baseTemplate, $contents->package(), $isUpdate);
70+
});
71+
72+
$app->template('.github/workflows/build.yml')->createWith(function (Contents $contents) use ($isSelf) {
73+
$placeholders = ['${tpl.PHP_EXEC}', '${tpl.PHPCS}'];
74+
$replacements = $isSelf
75+
? ['php ', 'phpcs.xml.dist']
76+
: ['vendor/bin/', 'vendor/polymorphine/dev/phpcs.xml'];
77+
return new Template\BasicTemplate(str_replace($placeholders, $replacements, $contents->template()));
78+
});
79+
80+
$app->template('LICENSE')->createWith(function (Contents $contents) {
81+
return new Template\BasicTemplate(str_replace('{$tpl.CURRENT_YEAR}', date('Y'), $contents->template()));
82+
});
83+
84+
$exitCode = $app->run($args);
85+
exit($exitCode);

template/.gitattributes.sk_file

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
.gitattributes export-ignore
4+
.gitignore export-ignore
5+
phpunit.xml.dist export-ignore
6+
cs-fixer.php.dist export-ignore
7+
{original.content}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: build
2+
on: [push, pull_request]
3+
4+
jobs:
5+
full-build:
6+
name: "Coding standards & coverage tests"
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
matrix:
10+
operating-system: ['ubuntu-latest']
11+
php-versions: ['7.4']
12+
env:
13+
extensions: pcov, dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
14+
key: cache-v2
15+
steps:
16+
- name: "Checkout"
17+
uses: actions/checkout@v2
18+
- name: "Setup PHP extensions cache environment"
19+
id: cache-env
20+
uses: shivammathur/cache-extensions@v1
21+
with:
22+
php-version: ${{ matrix.php-versions }}
23+
extensions: ${{ env.extensions }}
24+
key: ${{ env.key }}
25+
- name: "Cache PHP extensions"
26+
uses: actions/cache@v2
27+
with:
28+
path: ${{ steps.cache-env.outputs.dir }}
29+
key: ${{ steps.cache-env.outputs.key }}
30+
restore-keys: ${{ steps.cache-env.outputs.key }}
31+
- name: "Install PHP with extensions"
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php-versions }}
35+
coverage: pcov
36+
extensions: ${{ env.extensions }}
37+
ini-values: assert.exception=1, zend.assertions=1
38+
- name: "Validate composer.json"
39+
run: composer validate
40+
- name: "Setup composer cache"
41+
uses: actions/cache@v2
42+
with:
43+
path: ~/.composer/cache
44+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
45+
restore-keys: ${{ runner.os }}-composer-
46+
- name: "Install highest dependencies"
47+
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable
48+
- name: "Coding standard Php-CS-Fixer checks"
49+
run: vendor/bin/php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests
50+
- name: "Coding standard CodeSniffer checks"
51+
run: |
52+
vendor/bin/phpcs --extensions=php --standard=${tpl.PHPCS} src
53+
vendor/bin/phpcs --extensions=php --standard=${tpl.PHPCS} --ignore=tests/CodeSamples/* tests
54+
- name: "Package skeleton validation"
55+
run: ${tpl.PHP_EXEC}polymorphine-skeleton check
56+
- name: "Run PhpUnit tests with coverage"
57+
run: |
58+
mkdir -p build/logs
59+
vendor/bin/phpunit{original.content} --coverage-clover build/logs/clover.xml
60+
- name: "Send coverage report to coveralls.io"
61+
run: vendor/bin/php-coveralls -v
62+
env:
63+
COVERALLS_RUN_LOCALLY: 1
64+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
65+
66+
php-os-builds:
67+
name: "PHP 8 tests"
68+
runs-on: ${{ matrix.operating-system }}
69+
strategy:
70+
matrix:
71+
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest']
72+
php-versions: ['8.0', '8.1']
73+
env:
74+
extensions: dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
75+
key: cache-v2
76+
steps:
77+
- name: "Turn off git EOL conversion"
78+
run: git config --global core.autocrlf false
79+
- name: "Checkout"
80+
uses: actions/checkout@v2
81+
- name: "Setup PHP extensions cache environment"
82+
id: cache-env
83+
uses: shivammathur/cache-extensions@v1
84+
with:
85+
php-version: ${{ matrix.php-versions }}
86+
extensions: ${{ env.extensions }}
87+
key: ${{ env.key }}
88+
- name: "Cache PHP extensions"
89+
uses: actions/cache@v2
90+
with:
91+
path: ${{ steps.cache-env.outputs.dir }}
92+
key: ${{ steps.cache-env.outputs.key }}
93+
restore-keys: ${{ steps.cache-env.outputs.key }}
94+
- name: "Install PHP with extensions"
95+
uses: shivammathur/setup-php@v2
96+
with:
97+
php-version: ${{ matrix.php-versions }}
98+
coverage: none
99+
extensions: ${{ env.extensions }}
100+
ini-values: assert.exception=1, zend.assertions=1
101+
- name: "Setup composer cache"
102+
uses: actions/cache@v2
103+
with:
104+
path: ~/.composer/cache
105+
key: ${{ runner.os }}-php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }}
106+
restore-keys: ${{ runner.os }}-php${{ matrix.php-versions }}-composer-
107+
- name: "Install highest dependencies"
108+
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable
109+
- name: "Run PhpUnit tests (no coverage)"
110+
run: vendor/bin/phpunit{original.content} --no-coverage

template/.gitignore.sk_file

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.dev/
2+
/vendor/
3+
/composer.lock
4+
{original.content}

template/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) {original.content>>>{$tpl.CURRENT_YEAR}<<<original.content} {author.name} <{author.email}>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

template/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# {package.name}
2+
[![Latest stable release](https://poser.pugx.org/{package.name.composer}/version)](https://packagist.org/packages/{package.name.composer})
3+
[![Build status](https://github.com/{repository.name}/workflows/build/badge.svg)](https://github.com/{repository.name}/actions)
4+
[![Coverage status](https://coveralls.io/repos/github/{repository.name}/badge.svg?branch=develop)](https://coveralls.io/github/{repository.name}?branch=develop)
5+
[![PHP version](https://img.shields.io/packagist/php-v/{package.name.composer}.svg)](https://packagist.org/packages/{package.name.composer})
6+
[![LICENSE](https://img.shields.io/github/license/{repository.name}.svg?color=blue)](LICENSE)
7+
### {package.description}
8+
{original.content>>>
9+
10+
Detailed description (optional)...
11+
12+
<<<original.content}
13+
### Installation with [Composer](https://getcomposer.org/)
14+
```bash
15+
composer require{original.content} {package.name.composer}
16+
```
17+
{original.content>>>
18+
19+
Your content here...
20+
21+
<<<original.content}

0 commit comments

Comments
 (0)