Skip to content

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).

FileRuns onDoes
.github/workflows/ci.ymlPush to development, pull requestsAgent instructions check, asset build, php artisan test, Pint check
.github/workflows/release.ymlPush to masterCI, then the release and its deploy, when there is something to release
.github/workflows/deploy.ymlCalled by the release, or by handBuilds the site and copies it to the server over SSH
.github/dependabot.ymlWeeklyA 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 ​

  1. Work on development with conventional commits: feat: ..., fix: ..., feat!: ... for a breaking change.
  2. Merge development into master and push. This goes live.

The workflow does the rest:

  1. CI tests the pushed commit. When it fails, nothing is released or deployed.
  2. release-please writes the next version and the CHANGELOG.md entry in a release PR, and the workflow merges it at once. It moves master forward without force and only when the PR is the tested commit plus the changelog, so nothing untested is released. If someone pushed to master meanwhile, this run stops and the run of that push takes over.
  3. It creates the tag and the GitHub Release.
  4. It brings development up to date, then deploys the tag. Pull development before 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 production environment (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 master does 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 than CHANGELOG.md and version.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 development and master branches.
  • Under Settings → Actions → General → Workflow permissions, enable Allow GitHub Actions to create and approve pull requests.
  • Commit package-lock.json. The workflows install with npm 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_KEY and MAINTENANCE_TOKEN.
  • When php on the server's command line is older than 8.4, which is common on shared hosting, also set the PHP_BIN variable to the 8.4 binary, for example php8.4.

One-time setup on the server ​

  • PHP 8.4 on the command line, with the extensions listed under Requirements. Check with php -v and php -m over SSH: the command-line PHP can differ from the one serving the site.
  • The web root points to public/ inside DEPLOY_PATH.
  • tar, which every ordinary host has, and free space for a second copy of the site.
  • A .env in DEPLOY_PATH with APP_KEY, APP_URL and the database. The deploy never copies or changes it.

What a deploy does ​

  1. Builds the site in GitHub Actions: Composer without the development packages, and the Vite assets.
  2. Uploads the result over SSH to DEPLOY_PATH/.mela-next. The live site does not change.
  3. On the server, checks that the uploaded release can run with the PHP it finds.
  4. Puts the site in maintenance mode. Visitors get a page rendered beforehand, which loads nothing of the site, so nobody meets half a release.
  5. Removes the cached config, routes and events of the previous release, and copies the new one into place.
  6. Runs the migrations, makes the public/storage link, 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:

bash
php artisan mela:super-admin

It 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 ​

ProblemCauseFix
The deploy stops with "'php' on the server is PHP 8.3..."The command-line php is older than 8.4Set the PHP_BIN variable, then run the failed deploy again
The upload step ends with dial tcp ...:22: i/o timeoutThe server did not answer in time. The live site did not changeRun the failed deploy again
development was merged into master and nothing was deployedNo feat or fix since the last releaseNothing to do, or use Actions → Deploy → Run workflow
The same, and a release PR is openThe run could not merge it. Its warning says whyMerge the release PR by hand
A failed CI run on the release PR, with no jobsGitHub holds that run for an approval, and it ends as failed when the workflow merges the PR. It spends no minutes and marks no commitNothing. 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 changeRead 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 copyNothing, if the deploy ended well
The site stays in maintenance after a failed deployA step after the maintenance mode failedFix the cause the log names, then Re-run failed jobs
The upload step ends with ssh: unable to authenticateThe server does not accept the key in SSH_KEY for SSH_USER. The live site did not changeCheck that its public key is still on the server, then Re-run failed jobs
git push to development is refused after a releaseThe workflow added the release commit to itgit pull, then push again
Nobody can log in on a freshly deployed siteThe deploy creates no accountphp artisan mela:super-admin over SSH
Dependabot's update fails with dependency_file_not_resolvableNo PHP version pin in composer.jsonThe 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.

Code released under the MIT License. The MelaCMS name and logo are trademarks, see Brand.