loophp/grumphp-license-task
GrumPHP extension adding a “license” task to ensure your project has a valid LICENSE file. Creates it if missing or offers to fix it if invalid. Supports common OSI licenses (MIT, BSD-3-Clause, LGPL, EUPL) with holder/year options.
Install the Package:
composer require loophp/grumphp-license-task --dev
Ensure it’s added to require-dev in composer.json for CI/CD environments.
Register the Extension:
Add the extension to your grumphp.yml:
grumphp:
extensions:
- loophp\GrumphpLicenseTask\Extension
Configure the Task:
Define the license task in grumphp.yml with required fields:
tasks:
license:
name: MIT # Required: OSI license name (e.g., MIT, LGPL-3.0)
holder: "Your Name" # Required: License holder
date_from: 2023 # Optional: Year for dynamic date placeholders
Run GrumPHP: Execute locally or in CI:
./vendor/bin/grumphp run
LICENSE file exists, it will be auto-generated.Onboarding New Developers:
grumphp.yml to enforce license compliance during PR reviews.tasks:
license:
name: MIT
holder: "Acme Corp"
date_from: 2023
LICENSE file, reducing legal risks.CI/CD Integration:
# .github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: ./vendor/bin/grumphp run --strict
Dynamic License Updates:
date_from to auto-update the year in the license file:
tasks:
license:
name: MIT
holder: "Acme Corp"
date_from: 2023 # Updates annually via CI script
date_from in grumphp.yml yearly.Custom License Files:
input/output to validate or generate licenses from templates:
tasks:
license:
input: ./templates/CUSTOM_LICENSE.txt
output: LICENSE
Multi-Repository Consistency:
grumphp.yml snippet.Combine with Other Tasks:
Pair with grumphp/phpunit or grumphp/git_blacklist to enforce licenses alongside code quality:
tasks:
license:
name: MIT
phpunit:
test_class_regex: ".*Test"
Exclude Directories:
Use GrumPHP’s paths to skip specific folders (e.g., vendor/):
grumphp:
paths:
- src/
- tests/
ignore:
- vendor/
Custom Error Handling:
Override GrumPHP’s failure messages via grumphp.yml:
grumphp:
tasks:
license:
name: MIT
failure_message: "LICENSE file is missing or invalid. Run `grumphp fix` to auto-fix."
License Name Mismatch:
GPL-3.0) will fail silently.File Permission Errors:
LICENSE if permissions are restricted.# GitHub Actions example
- run: chmod -R a+w .
Dynamic date_from Quirks:
date_from is set to a future year, the license may appear invalid.date_from annually or set it to the current year.Custom Templates:
input/output feature may not handle complex templates (e.g., with placeholders).Dry Runs:
Use --dry-run to preview changes without modifying files:
./vendor/bin/grumphp run --dry-run
Verbose Output: Enable debug mode for detailed logs:
./vendor/bin/grumphp run -v
Fix Mode: Auto-correct issues with:
./vendor/bin/grumphp fix
Custom Licenses: Extend the package by adding new licenses via a PR or fork. The source shows how licenses are defined.
Pre/Post-Task Hooks:
Use GrumPHP’s on-failure or on-success hooks to trigger additional actions:
grumphp:
hooks:
on-failure:
- ./scripts/notify-slack.sh "License check failed!"
Environment Variables:
Dynamically set holder or date_from via environment variables (requires custom scripting):
tasks:
license:
name: MIT
holder: "%env(HOLDER_NAME)%" # Requires interpolation (not natively supported)
Template Inheritance: Store license templates in a shared repo and symlink them across projects to maintain consistency.
CI Caching:
Cache the LICENSE file in CI to avoid regenerating it on every run (if using input/output):
# GitHub Actions example
- uses: actions/cache@v3
with:
path: LICENSE
key: ${{ runner.os }}-license
Git Ignore:
Add LICENSE to .gitignore if using input/output to avoid conflicts:
# .gitignore
LICENSE
Team Onboarding:
Document the license task in your CONTRIBUTING.md to educate contributors:
## License Requirements
All commits must pass the `grumphp license` task. Run `composer install && ./vendor/bin/grumphp run` locally before submitting PRs.
How can I help you explore Laravel packages today?