ergebnis / license
Provides an abstraction of an open-source license.
Fund package maintenance!
localheinz
Installs: 550 934
Dependents: 52
Suggesters: 0
Security: 0
Stars: 10
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- ext-filter: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.22.0
- ergebnis/data-provider: ^1.0.0
- ergebnis/php-cs-fixer-config: ^3.4.0
- fakerphp/faker: ^1.17.0
- infection/infection: ~0.25.5
- phpunit/phpunit: ^9.5.11
- psalm/plugin-phpunit: ~0.16.1
- symfony/filesystem: ^5.4.0
- vimeo/psalm: ^4.17.0
README
Provides an abstraction of an open-source license.
Installation
Run
$ composer require --dev ergebnis/license
Usage
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
you can use the configuration file .php_cs
to
- save the license to a file, e.g.
LICENSE
orLICENSE.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 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() ->setFinder($finder) ->setRules([ 'header_comment' => [ 'comment_type' => 'PHPDoc', 'header' => $license->header(), 'location' => 'after_declare_strict', 'separate' => 'both', ], ]);
💡 Also take a look at .php_cs
of this project.
GitHub Actions
When using GitHub Actions, you can set up a scheduled workflow that opens a pull request to the license year automatically on January 1st:
name: "License" on: schedule: - cron: "1 0 1 1 *" jobs: license: name: "License" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2.0.0" - 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 --dry-run --verbose" - name: "Open pull request updating license year" uses: "gr2m/create-or-update-pull-request-action@v1.2.9" with: author: "Andreas Möller <am@localheinz.com>" 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 }}"
💡 See 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:
- name: "Open pull request updating license year" uses: "gr2m/create-or-update-pull-request-action@v1.2.9" with: - author: "Andreas Möller <am@localheinz.com>" + author: "ergebnis-bot <bot@ergebn.is>" 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:
💡 Need a different license type? Feel free to open a pull request!
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Curious what I am building?
📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.