Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Test Job to the Workflow #4

Merged
merged 21 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Publish Docker Image
on:
push:
paths:
- ".github/**"
- "src/**"
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
ghcr.io/${{ github.repository }}

- name: Build and push Docker images
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


79 changes: 79 additions & 0 deletions .github/workflows/link-analyse-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ on:
- "src/**"
branches:
- main
push:
paths:
- ".github/**"
- "src/**"
branches:
- main

jobs:
Lint:
Expand Down Expand Up @@ -38,4 +44,77 @@ jobs:
run: pint --test
working-directory: src

Test:
name: Run tests ${{ matrix.php-version }}
runs-on: ubuntu-latest
needs:
- Lint
strategy:
matrix:
php-version: [ "8.1", "8.2" ]

services:
postgres:
image: postgres
env:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432

steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."

- uses: actions/checkout@v3
name: Checkout branch

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: laravel/pint, overtrue/phplint

- name: Outupt PHP version
run: php --version

- name: Check PHP syntax
run: phplint --exclude=*.log .
working-directory: src

- name: Run Laravel Pint
run: pint --test
working-directory: src

- name: Install composer
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
run: composer install --optimize-autoloader --no-progress --no-interaction --ignore-platform-req=php
working-directory: src

- name: Run PHPstan
run: ./vendor/bin/phpstan analyse
working-directory: src

- name: Setup environment variables
run: |
cp .env.ci .env
cp .env.ci .env.testing
working-directory: src

- name: Install NPM Packages
run: |
npm install
npm run build
working-directory: src

- name: Run tests
run: ./vendor/bin/pest
working-directory: src
61 changes: 61 additions & 0 deletions src/.env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:xRCrzecnkUYQ/Fl+VsITrHMv4LTe8kdTzI6czix10WM=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=postgres

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

TORCHLIGHT_TOKEN=some_token
2 changes: 2 additions & 0 deletions src/.env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

TORCHLIGHT_TOKEN=some_token
51 changes: 51 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM php:8.2-fpm as php

ENV PHP_OPCACHE_ENABLE=1
ENV PHP_OPCACHE_ENABLE_CLI=0
ENV PHP_OPCACHE_VALIDATE_TIMESTAMP=1
ENV PHP_OPCACHE_REVALIDATE_FREQ=1


RUN usermod -u 1000 www-data

RUN apt-get update -y
RUN apt-get update && apt-get install -y unzip libpq-dev libcurl4-gnutls-dev nginx libonig-dev
RUN docker-php-ext-install pdo pdo_pgsql bcmath curl opcache

RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis

# Copy composer executable.
COPY --from=composer:2.3.5 /usr/bin/composer /var/bin/composer

# Copy configuration files.
COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
COPY ./docker/php/php-fpm.conf /usr/local/etc/php-fom.d/www.conf
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf

# Set working directory to /var/www.
WORKDIR /var/www

# Copy files from current folder to container current folder (set in workdir).
COPY --chown=www-data:www-data . .

# Create laravel caching folders.
RUN mkdir -p /var/www/storage/framework
RUN mkdir -p /var/www/storage/framework/cache
RUN mkdir -p /var/www/storage/framework/testing
RUN mkdir -p /var/www/storage/framework/sessions
RUN mkdir -p /var/www/storage/framework/views


# Fix files ownership.
RUN chown -R www-data /var/www/storage
RUN chown -R www-data /var/www/storage/framework
RUN chown -R www-data /var/www/storage/framework/sessions

# Adjust user permission & group
RUN usermod --uid 1000 www-data
RUN groupmod --gid 1001 www-data

# Run the entrypoint file.
ENTRYPOINT [ "docker/entrypoint.sh" ]
4 changes: 2 additions & 2 deletions src/app/DataTransferObjects/TagDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Str;
use Spatie\LaravelData\Data;

class TagDTO extends Data
final class TagDTO extends Data
{
public function __construct(
public string $title,
Expand All @@ -19,7 +19,7 @@ public function __construct(
public static function fromTitle(string $title, ?string $description = null): TagDTO
{

return new static(
return new self(
title: $title,
slug: Str::slug($title),
description: $description
Expand Down
1 change: 1 addition & 0 deletions src/app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __invoke(EmailVerificationRequest $request): RedirectResponse
}

if ($request->user()->markEmailAsVerified()) {

event(new Verified($request->user()));
}

Expand Down
4 changes: 1 addition & 3 deletions src/app/Markdown/BladeRendererExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BladeRendererExtension implements ExtensionInterface
{
public array $rendered = [];

public Environment $environment;
public Environment|EnvironmentBuilderInterface $environment;

public function register(EnvironmentBuilderInterface $environment): void
{
Expand Down Expand Up @@ -79,8 +79,6 @@ public function onDocumentRendered(DocumentRenderedEvent $event): void

}

//dd($search, $replace);

$content = Str::replace($search, $replace, $content);

$event->replaceOutput(
Expand Down
9 changes: 4 additions & 5 deletions src/app/Markdown/CodeRendererExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace App\Markdown;

use Illuminate\Support\Facades\Blade;
use JetBrains\PhpStorm\NoReturn;
use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Event\DocumentRenderedEvent;
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode;
use League\CommonMark\Extension\CommonMark\Node\Inline\Code;
use League\CommonMark\Extension\ExtensionInterface;
use League\CommonMark\Node\Node;
use League\CommonMark\Renderer\ChildNodeRendererInterface;
Expand All @@ -26,10 +26,9 @@ public function register(EnvironmentBuilderInterface $environment): void
/**
* @return string|void|null
*/
#[NoReturn]
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
public function render(Node|IndentedCode|FencedCode|Code $node, ChildNodeRendererInterface $childRenderer)
{
/** @var $node IndentedCode|FencedCode */
/** @var $node IndentedCode|FencedCode|Code */
$info = $node->getInfoWords();

if (! static::$allowBladeForNextDocument) {
Expand All @@ -43,7 +42,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer)
return null;
}

public function onDocumentRenderedEvent()
public function onDocumentRenderedEvent(): void
{
static::$allowBladeForNextDocument = false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable;

Expand Down
16 changes: 8 additions & 8 deletions src/app/Services/CourseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ class CourseService
{
/**
* Returns the list of courses that are published under
* content/courses folder
*
* @return DataCollection<CourseDTO>
* the content /courses folder
*/
public function getCourses(): DataCollection
public function getCourses(): CoursesDTO
{
$courses = CoursesDTO::collection([]);
$courses = CourseDTO::collection([]);
$directories = glob(base_path('content/courses/*'));

CodeRendererExtension::$allowBladeForNextDocument = true;
Expand All @@ -47,11 +45,13 @@ public function getCourses(): DataCollection
}
}

return $courses;
return CoursesDTO::from([
'items' => $courses,
]);
}

/**
* @return DataCollection<SectionDTO>
* @return DataCollection<(int|string), SectionDTO>
*/
public function getSections(string $directory): DataCollection
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public function getCourse(string $slug): CourseDTO

$courses = $this->getCourses();

return $courses->where('slug', $slug)->first();
return $courses->items->where('slug', $slug)->first();

}
}
Loading