generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ergebnis/feature/mit
Enhancement: Add MIT
- Loading branch information
Showing
7 changed files
with
424 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,138 @@ | |
[](https://packagist.org/packages/ergebnis/license) | ||
[](https://packagist.org/packages/ergebnis/license) | ||
|
||
## Installation | ||
Provides an abstraction of an open-source license. | ||
|
||
:bulb: This is a great place for showing how to install the package, see below: | ||
## Installation | ||
|
||
Run | ||
|
||
``` | ||
$ composer require ergebnis/license | ||
$ composer require --dev ergebnis/license | ||
``` | ||
|
||
## Usage | ||
|
||
:bulb: This is a great place for showing a few usage examples! | ||
Sometimes open source maintainers complain about the burden of managing an open-source project. Sometimes they argue that contributors opening pull requests to update license years unnecessarily increase their workload. | ||
|
||
Of course, all of this can be automated, can't it? | ||
|
||
### Configuration for `friendsofphp/php-cs-fixer` | ||
|
||
With [`friendsofphp/php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer) you can use the configuration file `.php_cs` to | ||
|
||
* save the license to a file, e.g. `LICENSE` or `LICENSE.md` | ||
* specify a file-level header using the `header_comment` fixer that will be replaced in PHP files | ||
|
||
Here's an example of a `.php_cs` file: | ||
|
||
```php | ||
<?php | ||
|
||
use Ergebnis\License; | ||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
|
||
$license = License\Type\MIT::text( | ||
__DIR__ . '/LICENSE', | ||
License\Range::since( | ||
License\Year::fromString('2020'), | ||
new \DateTimeZone('UTC') | ||
), | ||
License\Holder::fromString('Andreas Möller'), | ||
License\Url::fromString('https://github.com/ergebnis/license') | ||
); | ||
|
||
$license->save(); | ||
|
||
$finder = Finder::create()->in(__DIR__); | ||
|
||
return Config::create() | ||
->setRules([ | ||
'header_comment' => [ | ||
'comment_type' => 'PHPDoc', | ||
'header' => $license->header(), | ||
'location' => 'after_declare_strict', | ||
'separate' => 'both', | ||
], | ||
]) | ||
->setFinder($finder); | ||
``` | ||
|
||
:bulb: Also take a look at [`.php_cs`](.php_cs) of this project. | ||
|
||
### GitHub Actions | ||
|
||
When using [GitHub Actions](https://github.com/features/actions), you can set up a scheduled workflow that opens a pull request to the license year automatically on January 1st: | ||
|
||
```yaml | ||
name: "License" | ||
|
||
on: | ||
schedule: | ||
- cron: "1 0 1 1 *" | ||
|
||
jobs: | ||
license: | ||
name: "License" | ||
|
||
runs-on: "ubuntu-latest" | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/[email protected]" | ||
|
||
- name: "Install dependencies with composer" | ||
run: "composer install --no-interaction --no-progress --no-suggest" | ||
|
||
- name: "Run friendsofphp/php-cs-fixer" | ||
run: "vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --dry-run --verbose" | ||
|
||
- name: "Open pull request updating license year" | ||
uses: "gr2m/[email protected]" | ||
with: | ||
author: "Andreas Möller <[email protected]>" | ||
branch: "feature/license-year" | ||
body: | | ||
This PR | ||
* [x] updates the license year | ||
commit-message: "Enhancement: Update license year" | ||
path: "." | ||
title: "Enhancement: Update license year" | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
``` | ||
:bulb: See [`crontab.guru`](https://crontab.guru) if you need help scheduling the workflow. | ||
|
||
Note that pull requests opened or commits pushed by GitHub Actions will not trigger a build. As an alternative, you can set up a bot user: | ||
|
||
```diff | ||
- name: "Open pull request updating license year" | ||
uses: "gr2m/[email protected]" | ||
with: | ||
- author: "Andreas Möller <[email protected]>" | ||
+ author: "ergebnis-bot <[email protected]>" | ||
branch: "feature/license-year" | ||
body: | | ||
This PR | ||
* [x] updates the license year | ||
commit-message: "Enhancement: Update license year" | ||
path: "." | ||
title: "Enhancement: Update license year" | ||
env: | ||
- GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
+ GITHUB_TOKEN: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" | ||
``` | ||
## Types | ||
|
||
The following license types are currently available: | ||
|
||
* [`Ergebnis\License\Type\MIT`](src/Type/MIT.php) | ||
|
||
:bulb: Need a different license type? Feel free to open a pull request! | ||
|
||
## Changelog | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2020 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/license | ||
*/ | ||
|
||
namespace Ergebnis\License\Type; | ||
|
||
use Ergebnis\License\File; | ||
use Ergebnis\License\Header; | ||
use Ergebnis\License\Holder; | ||
use Ergebnis\License\Period; | ||
use Ergebnis\License\Template; | ||
use Ergebnis\License\Url; | ||
|
||
final class MIT | ||
{ | ||
/** | ||
* @var File | ||
*/ | ||
private $file; | ||
|
||
/** | ||
* @var Header | ||
*/ | ||
private $header; | ||
|
||
private function __construct(string $name, Template $fileTemplate, Template $headerTemplate, Period $period, Holder $holder, Url $url) | ||
{ | ||
$file = File::create( | ||
$name, | ||
$fileTemplate, | ||
$period, | ||
$holder | ||
); | ||
|
||
$header = Header::create( | ||
$headerTemplate, | ||
$period, | ||
$holder, | ||
$file, | ||
$url | ||
); | ||
|
||
$this->file = $file; | ||
$this->header = $header; | ||
} | ||
|
||
public static function markdown(string $name, Period $period, Holder $holder, Url $url): self | ||
{ | ||
return new self( | ||
$name, | ||
Template::fromFile(__DIR__ . '/../../resource/license/MIT.md'), | ||
Template::fromFile(__DIR__ . '/../../resource/header.txt'), | ||
$period, | ||
$holder, | ||
$url | ||
); | ||
} | ||
|
||
public static function text(string $name, Period $period, Holder $holder, Url $url): self | ||
{ | ||
return new self( | ||
$name, | ||
Template::fromFile(__DIR__ . '/../../resource/license/MIT.txt'), | ||
Template::fromFile(__DIR__ . '/../../resource/header.txt'), | ||
$period, | ||
$holder, | ||
$url | ||
); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
$this->file->save(); | ||
} | ||
|
||
public function header(): string | ||
{ | ||
return $this->header->toString(); | ||
} | ||
} |
Oops, something went wrong.