Releasing and deploying
A MelaCMS site is built in GitHub Actions and copied to the server over SSH. The server needs only PHP 8.4 and SSH: no Composer, no Node and no build step. That is why a classic shared host is enough.
The workflow files
The installer copies four files into the site. From then on they belong to the site and can be changed freely. mela:update asks before taking a new version of one (see Updating the core).
| File | Runs on | Does |
|---|---|---|
.github/workflows/ci.yml | Push to development, pull requests | Agent instructions check, asset build, php artisan test, Pint check |
.github/workflows/release.yml | Push to master | CI, then the release and its deploy, when there is something to release |
.github/workflows/deploy.yml | Called by the release, or by hand | Builds the site and copies it to the server over SSH |
.github/dependabot.yml | Weekly | A pull request for a new MelaCMS version |
ci.yml is a single job, called Test, because in a private repository GitHub bills each job as whole minutes. Until v0.12.4 the template also had a Lint job. If a branch protection rule requires the Lint check, remove it from the rule when you take the new template.
The flow
- Work on
developmentwith conventional commits:feat: ...,fix: ...,feat!: ...for a breaking change. - Merge
developmentintomasterand push. This goes live.
The workflow does the rest:
- CI tests the pushed commit. When it fails, nothing is released or deployed.
- release-please writes the next version and the
CHANGELOG.mdentry in a release PR, and the workflow merges it at once. It movesmasterforward without force and only when the PR is the tested commit plus the changelog, so nothing untested is released. If someone pushed tomastermeanwhile, this run stops and the run of that push takes over. - It creates the tag and the GitHub Release.
- It brings
developmentup to date, then deploys the tag. Pulldevelopmentbefore you continue to work on it.
If development cannot be updated because of a conflict, the run only warns: merge master into it by hand.
The commit type decides the version. feat: raises the minor version and fix: raises the patch. docs:, chore: and the other types make no release, so nothing is deployed. Never edit CHANGELOG.md by hand.
Approving a release first
- Approve each deploy: add required reviewers to the
productionenvironment (Settings → Environments), on a plan that has them. The release is made, and the deploy waits for the approval. - Review the release PR: when a rule on
masterdoes not let the workflow push to it, the run ends with a warning and the release PR stays open. Merging it by hand releases and deploys. The same happens when the release PR holds changes other thanCHANGELOG.mdandversion.txt.
Sites created before this flow
Until v0.12.4 the template of release.yml only opened the release PR, and merging that PR released and deployed. mela:update asks before it replaces the file, and a site that keeps its own keeps the two merges. Taking the new template means that a push to master with a feat or fix goes live. A release PR that is open at that moment is released with the next push to master.
One-time setup on GitHub
- Create the
developmentandmasterbranches. - Under Settings → Actions → General → Workflow permissions, enable Allow GitHub Actions to create and approve pull requests.
- Commit
package-lock.json. The workflows install withnpm ci, which needs it. - Set the variables and secrets listed at the top of
.github/workflows/deploy.yml:DEPLOY_PATH,SSH_HOST,SSH_USER,SSH_KEYandMAINTENANCE_TOKEN. - When
phpon the server's command line is older than 8.4, which is common on shared hosting, also set thePHP_BINvariable to the 8.4 binary, for examplephp8.4.
One-time setup on the server
- PHP 8.4 on the command line, with the extensions listed under Requirements. Check with
php -vandphp -mover SSH: the command-line PHP can differ from the one serving the site. - The web root points to
public/insideDEPLOY_PATH. tar, which every ordinary host has, and free space for a second copy of the site.- A
.envinDEPLOY_PATHwithAPP_KEY,APP_URLand the database. The deploy never copies or changes it.
What a deploy does
- Builds the site in GitHub Actions: Composer without the development packages, and the Vite assets.
- Uploads the result over SSH to
DEPLOY_PATH/.mela-next. The live site does not change. - On the server, checks that the uploaded release can run with the PHP it finds.
- Puts the site in maintenance mode. Visitors get a page rendered beforehand, which loads nothing of the site, so nobody meets half a release.
- Removes the cached config, routes and events of the previous release, and copies the new one into place.
- Runs the migrations, makes the
public/storagelink, builds the caches, brings the site back up and removes.mela-next.
When a step before the fourth fails, the live site goes on as it was. After that the script stops at the first error, so a failed copy or migration leaves the site in maintenance mode. Fix the cause and deploy again.
The maintenance page is errors/503 of the site, or Laravel's own. A site view that cannot be rendered from the command line leaves the ordinary maintenance mode, which still loads the site.
Until v0.12.4 the template copied straight onto the live site, before maintenance mode. mela:update offers the new one.
The first super-admin on the server
The deploy runs the migrations and creates no account, so after the first deploy nobody can log in yet. Run this once, over SSH, in the app directory on the server:
php artisan mela:super-adminIt creates the three roles if they are missing, then asks for an email, a name and a password. If the email belongs to an existing user, that user keeps their name and password and gains the role. So the same command also restores access to a site that has lost its last super-admin. The other users are then created in the panel.
Deploying again
- After a failed release or deploy, fix the cause, then use Re-run failed jobs on the workflow run, or
gh run rerun <run id> --failed. It continues from where it stopped. The variables and secrets are read again. - To deploy any tag or branch, use Actions → Deploy → Run workflow.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| The deploy stops with "'php' on the server is PHP 8.3..." | The command-line php is older than 8.4 | Set the PHP_BIN variable, then run the failed deploy again |
The upload step ends with dial tcp ...:22: i/o timeout | The server did not answer in time. The live site did not change | Run the failed deploy again |
development was merged into master and nothing was deployed | No feat or fix since the last release | Nothing to do, or use Actions → Deploy → Run workflow |
| The same, and a release PR is open | The run could not merge it. Its warning says why | Merge the release PR by hand |
| A failed CI run on the release PR, with no jobs | GitHub holds that run for an approval, and it ends as failed when the workflow merges the PR. It spends no minutes and marks no commit | Nothing. Running it again only tests the same code once more |
| "The release cannot run on this server" | The dependencies need a newer PHP, or the upload is incomplete. The live site did not change | Read the line above the error: set PHP_BIN, or run the failed deploy again |
| "The live code could not start maintenance mode" | The previous release no longer runs. The deploy went on, and the new code did it after the copy | Nothing, if the deploy ended well |
| The site stays in maintenance after a failed deploy | A step after the maintenance mode failed | Fix the cause the log names, then Re-run failed jobs |
The upload step ends with ssh: unable to authenticate | The server does not accept the key in SSH_KEY for SSH_USER. The live site did not change | Check that its public key is still on the server, then Re-run failed jobs |
git push to development is refused after a release | The workflow added the release commit to it | git pull, then push again |
| Nobody can log in on a freshly deployed site | The deploy creates no account | php artisan mela:super-admin over SSH |
Dependabot's update fails with dependency_file_not_resolvable | No PHP version pin in composer.json | The pin, committed |
Known limits
- The deploy copies over the live directory while the site is in maintenance mode. Files removed from the repository stay on the server.
- While it deploys, the server holds the site twice. Keep that much space free.
- There is no rollback step.
- A host without SSH is not supported.
A site that is not deployed through GitHub Actions can delete the deploy job and deploy.yml. Versions and the changelog keep working without them.