mehrancodes/laravel-harbor

FORGE_DB_NAME breaks if passed a branch name with a hypen

shawnhooper opened this issue · 6 comments

Description

Databases specified with the FORGE_DB_NAME variable that include hyphens break the Create Database pipeline.

Example

Setting this environment variable in the Github Action:

FORGE_SITE_BRANCH: ${{ github.head_ref }}

on a branch called ABC-123 would result in it trying to create a database named ABC-123 which is invalid:

 INFO    Start finding the server.
 INFO    Finding the associated site.
 INFO    ---> Site not found.
 INFO    Creating a new site.
 INFO    ---> Use the specified Nginx template.
 INFO    Creating database.
 FAIL    ---> The name must only contain letters, numbers, and underscores.

  Laravel\Forge\Exceptions\ValidationException 

 The given data failed to pass validation.

 at /composer/vendor/laravel/forge-sdk/src/MakesHttpRequests.php:106
   102▕      */
   103▕     protected function handleRequestError(ResponseInterface $response)
   104▕     {
   105▕         if ($response->getStatusCode() == 422) {
 ➜ 106▕             throw new ValidationException(json_decode((string) $response->getBody(), true));
   107▕         }
   108▕ 
   109▕         if ($response->getStatusCode() == 404) {
   110▕             throw new NotFoundException();


Error: Process completed with exit code 1.

Fix

Replace hyphens with underscores when setting the database name in the Forge Settings initialisation.

Shawn thanks for the fix! I have left a comment there for you :)

@mehrancodes Hmm, that didn't work. on branch ABC-123 I'm getting:

 FAIL    ---> The FORGE_DB_NAME must only contain letters, numbers, and underscores.
   Laravel\Forge\Exceptions\ValidationException 

It looks like it's being validated before being standardized.

I see. In that case we better to format the FORGE_DB_NAME and remove the regex validation. I'll make a PR for it now 👍

@mehrancodes Testing it now 🧪 ✍️

Working now! Thank you. 🚀