ergebnis / license
Provides an abstraction of an open-source license.
Installs: 698 009
Dependents: 56
Suggesters: 0
Security: 0
Stars: 13
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^8.0
- ext-filter: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.28.3
- ergebnis/data-provider: ^1.2.0
- ergebnis/php-cs-fixer-config: ^4.11.0
- fakerphp/faker: ^1.20.0
- infection/infection: ~0.26.6
- phpunit/phpunit: ^9.5.26
- psalm/plugin-phpunit: ~0.18.3
- symfony/filesystem: ^6.0.13
- vimeo/psalm: ^4.29.0
This package is auto-updated.
Last update: 2023-02-06 15:07:35 UTC
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-fixer.php
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-fixer.php
file for an open-source project using the MIT
license type:
<?php declare(strict_types=1); /** * Copyright (c) 2020-2022 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 */ 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-fixer.php
of this project.
Here's an example of a .php-cs-fixer.php
file for a closed-source project using the None
license type:
<?php declare(strict_types=1); /** * Copyright (c) 2011-2019 Andreas Möller * * @see https://github.com/localheinz/localheinz.com */ use Ergebnis\License; use PhpCsFixer\Config; use PhpCsFixer\Finder; $license = License\Type\None::text( License\Range::since( License\Year::fromString('2020'), new \DateTimeZone('UTC') ), License\Holder::fromString('Andreas Möller'), License\Url::fromString('https://github.com/localheinz/localheinz.com') ); $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', ], ]);
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-fixer.php --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.