Skip to content

Commit

Permalink
Merge branch 'main' into 56-undefined-array-key-database
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrancodes committed Feb 24, 2024
2 parents e46daa6 + 7411cf6 commit 08e9121
Show file tree
Hide file tree
Showing 11 changed files with 1,061 additions and 739 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
tools: composer:v2
coverage: none

Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run Pest Tests
on: [ pull_request ]
jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3

- name: Install dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

- name: Run Pest tests
run: ./vendor/bin/pest

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Actions Status](https://github.com/mehrancodes/veyoze/actions/workflows/run-tests.yml/badge.svg?event=pull_request)](https://github.com/mehrancodes/veyoze/actions)

# Veyoze - Beta version ⚡️ 🛠️

![logo-background-blue-sky-small](https://github.com/mehrancodes/veyoze/assets/7046255/2727ce3d-31c4-4a97-bafc-e461706ff219)
Expand Down
28 changes: 0 additions & 28 deletions app/Actions/ArrayToText.php

This file was deleted.

68 changes: 68 additions & 0 deletions app/Actions/MergeEnvironmentVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

/**
* This file is part of Veyoze CLI.
*
* (c) Mehran Rasulian <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Actions;

use App\Traits\Outputifier;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Lorisleiva\Actions\Concerns\AsAction;

class MergeEnvironmentVariables
{
use AsAction;
use Outputifier;

public function handle(string $source, array $newVariables): string
{
$output = '';

if (! empty($source)) {
$output = $this->searchReplaceExistingVariables($source, $newVariables);
}

foreach ($newVariables as $newKey => $newValue) {
$output .= "$newKey=$newValue\n";
}

return $output;
}

protected function searchReplaceExistingVariables(string $source, array &$newVariables): string
{
$separator = Str::contains($source, ';') ? ';' : "\n";
$output = '';

foreach (explode($separator, $source) as $variable) {
if (empty($variable)) {
$output .= "\n";

continue;
}

[$key, $value] = explode('=', $variable, 2);

if (empty($key)) {
$this->warning("No key found for the assigned value \"$value\" inside your environment variables! Make sure to remove it.");

continue;
}

$value = array_key_exists($key, $newVariables) ? Arr::pull($newVariables, $key) : $value;

$output .= "$key=$value\n";
}

return $output;
}
}
6 changes: 5 additions & 1 deletion app/Actions/TextToArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ public function handle(?string $content): ?array

$output = [];
foreach (explode($separator, $content) as $variable) {
if (empty($variable)) {
continue;
}

$var = explode('=', $variable, 2);

if (empty($var[0]) || empty($var[1])) {
return [];
continue;
}

$output[$var[0]] = $var[1];
Expand Down
10 changes: 3 additions & 7 deletions app/Services/Forge/Pipeline/UpdateEnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace App\Services\Forge\Pipeline;

use App\Actions\ArrayToText;
use App\Actions\MergeEnvironmentVariables;
use App\Actions\TextToArray;
use App\Services\Forge\ForgeService;
use App\Traits\Outputifier;
Expand Down Expand Up @@ -42,12 +42,8 @@ public function __invoke(ForgeService $service, Closure $next)

protected function getBothEnvsMerged(ForgeService $service, array $newKeys): string
{
$sourceKeys = TextToArray::run(
$service->forge->siteEnvironmentFile($service->server->id, $service->site->id)
);
$source = $service->forge->siteEnvironmentFile($service->server->id, $service->site->id);

return ArrayToText::run(
array_merge($sourceKeys, $newKeys)
);
return MergeEnvironmentVariables::run($source, $newKeys);
}
}
20 changes: 17 additions & 3 deletions app/Traits/Outputifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected function information(string $message): int
{
render(sprintf(<<<'html'
<div class="font-bold">
<span class="bg-blue px-2 text-white mr-1">
<span class="bg-blue-400 px-2 text-white mr-1">
INFO
</span>
%s
Expand All @@ -24,7 +24,7 @@ protected function fail(string $message): int
{
render(sprintf(<<<'html'
<div class="font-bold">
<span class="bg-red px-2 text-white mr-1">
<span class="bg-red-400 px-2 text-white mr-1">
FAIL
</span>
%s
Expand All @@ -34,11 +34,25 @@ protected function fail(string $message): int
return 0;
}

protected function warning(string $message): int
{
render(sprintf(<<<'html'
<div class="font-bold">
<span class="bg-orange-400 px-2 text-white mr-1">
WARNING
</span>
%s
</div>
html, trim($message)));

return 0;
}

protected function success(string $message): int
{
render(sprintf(<<<'html'
<div class="font-bold">
<span class="bg-green px-2 text-white mr-1">
<span class="bg-green-400 px-2 text-white mr-1">
SUCCESS
</span>
%s
Expand Down
Loading

0 comments on commit 08e9121

Please sign in to comment.