Build your first Laravel package · Part 4 of 4
Sharing it
GitHub Actions on every push, a README someone can follow, semantic versioning and a first tag, and what publishing to Packagist involves.
By Abhishek Fouzdar · Updated
The package works and its tests prove it. The last part is about other people: a machine that runs the tests when you forget, a README someone can follow without you in the room, and a version number they can depend on. None of this is code, and it is what separates a folder on your disk from a package.
GitHub Actions: tests on every push
Create .github/workflows/tests.yml in the package:
name: Tests
on:
push:
pull_request:
jobs:
tests:
name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { php: '8.2', laravel: '12' }
- { php: '8.3', laravel: '12' }
- { php: '8.4', laravel: '12' }
- { php: '8.3', laravel: '13' }
- { php: '8.4', laravel: '13' }
- { php: '8.5', laravel: '13' }
steps:
- uses: actions/checkout@v5
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo_sqlite
coverage: none
- name: Install dependencies
run: composer update --no-interaction --prefer-dist --no-progress --with "illuminate/support:^${{ matrix.laravel }}.0"
- name: Code style
run: vendor/bin/pint --test
- name: Static analysis
run: vendor/bin/phpstan analyse --no-progress
- name: Tests
run: vendor/bin/phpunit
Read it top to bottom. It runs on every push and every pull request. The matrix runs the same job six times, each PHP version paired with a Laravel major that supports it: Laravel 12 on 8.2 to 8.4, Laravel 13 on 8.3 to 8.5, which together cover what composer.json claims. fail-fast: false means a failure on one cell does not cancel the others, so you see every problem at once. setup-php installs that PHP with the SQLite extension the tests need. The install step is composer update --with rather than composer install: a package commits no lock file, and --with "illuminate/support:^13.0" pins the Laravel major for that cell while Composer resolves the rest. Then it runs exactly the three commands from part 3, in the order that fails fastest: style in a second, analysis in a few, tests last.
Push the package to a GitHub repository and open the Actions tab. The first green run is the moment the package stops depending on your machine.
If GitHub Actions is new to you, GitHub Actions for an existing Laravel app covers the workflow file in more depth, with checks against real MySQL and Redis and a deploy at the end; the one above is a cut-down version of its first workflow.
A README someone can follow
A README is the page people decide on. Keep it to what a reader needs, in the order they need it:
- One paragraph on what it does and who it is for. Not features; the problem it removes.
- Install. The commands, including the migration. Nothing a reader has to guess.
- Use. The three or four calls that cover most uses, with a comment on what each returns.
- How it reads. One paragraph on the cache, because it is the one behaviour a user cannot see from the API and might wonder about.
- Configuration. The publish command and the config file with its comments.
- Development. The three composer scripts, so a contributor knows the bar.
- License.
The example repository's README follows that list; read it with the list in hand and notice what is not there. No badges, no roadmap, no "contributions welcome" boilerplate. Every section answers a question a reader has at that moment.
Add a CHANGELOG.md too, even if it has one entry. A changelog is where a user looks before upgrading, and a package that starts one at 0.1.0 never has to reconstruct history later.
Versions and the first tag
Composer resolves versions from git tags, so a package without tags has no versions. That is why part 1 needed @dev. Use semantic versioning: MAJOR.MINOR.PATCH, where a patch fixes something, a minor adds something without breaking what exists, and a major breaks something. Before 1.0 the rules relax, and a breaking change bumps the minor; say so in the changelog so users know what 0.x promises.
Tag the first version:
git tag -a v0.1.0 -m "v0.1.0"
git push origin v0.1.0
The v prefix is convention; Composer accepts tags with or without it. Create a release on GitHub from the tag with the changelog entry as its notes, so the tag has a page people can link to.
Installing from GitHub
With a tag in place, anyone can install the package straight from the repository. In an app:
composer config repositories.shipbytes-settings vcs https://github.com/shipbytes/laravel-settings
composer require shipbytes/laravel-settings
- Locking shipbytes/laravel-settings (v0.1.0)
- Installing shipbytes/laravel-settings (v0.1.0): Extracting archive
No @dev this time: Composer found the tag and picked the newest stable version. A vcs repository is enough for a package used inside one company or by a handful of people. Each app carries that one extra repositories line, and Composer talks to GitHub directly.
Packagist, when you want it
Packagist is the public registry Composer searches by default. Publishing there removes the repositories line for everyone: composer require shipbytes/laravel-settings just works. It takes a few minutes.
- Sign in at packagist.org with your GitHub account and submit the repository URL. Packagist reads
composer.jsonand lists the package under itsname, which is why the vendor part had to be yours. - Enable the GitHub hook Packagist offers, or install its GitHub app, so every new tag appears on Packagist within minutes without you doing anything.
- Tag releases as above. Packagist shows versions, not branches.
One rule to know before you publish: a version on Packagist is permanent. If you tag v0.1.0 and notice a mistake, you tag v0.1.1. You do not move the tag. Composer caches, lockfiles pin, and a moved tag breaks installs in ways that are miserable to debug.
The example package is deliberately not on Packagist, because a tutorial package on the public registry helps nobody and confuses searches. Yours, if it solves a real problem, should be.
Checkpoint
You should have:
- a green run in the Actions tab for all six PHP and Laravel combinations;
- a README and a changelog;
- a
v0.1.0tag, and an app that installs it by tag without@dev.
The matching commit is Part 4: sharing it, and the tag is v0.1.0.
What you have
A package that any Laravel 12 or 13 app can install in two commands, tested on four PHP versions and two Laravel majors on every push, with one documented behaviour and one place to change its configuration. Four parts, four commits, and nothing in it you had not already done inside an app. The next helper you find yourself copying between projects now has somewhere to live.
New posts by email
Get new posts by email. Nothing else, no digests, unsubscribe in one click.
Comments
Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.
In this series
4 / 4