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

Update README, add Tests and CI #114

Merged
merged 17 commits into from
Feb 25, 2024
53 changes: 53 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Docker

on:
push:
# Publish `main` as Docker `latest` image.
tags: [ 'v*.*.*' ]
workflow_dispatch:


env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- name: Copy .env
run: |
if [[ ! -f '.env' ]];then
cp '.env.example' '.env'
fi
- name: Install Dependencies
run: composer require laravel/sail -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist


# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}


# Build and push Docker image
- name: Build image
run: docker compose build

- name: Push image
run: docker compose push

36 changes: 36 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Laravel

on:
push:
branches: [ development ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
laravel-tests:

runs-on: ubuntu-latest
env:
DB_CONNECTION: sqlite
DB_DATABASE: database.sqlite
steps:
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Fill database
run: |
php artisan migrate:fresh
php artisan db:seed
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
61 changes: 61 additions & 0 deletions .github/workflows/sail-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Sail Publish

on:
workflow_dispatch:


env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- name: Copy .env
run: |
if [[ ! -f '.env' ]];then
cp '.env.example' '.env'
fi
- name: Install Dependencies
run: composer require laravel/sail -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build image based on docker-compose.yml
run: docker compose build mensa.php

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sail-${SAIL_VERSION}-app

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
*Main*

[![Docker (Branch: Main)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml/badge.svg?branch=main-docker)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml)
[![Laravel (Branch: main)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml/badge.svg?branch=main-docker)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml)

*Development*

[![Docker (Branch: development)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml/badge.svg?branch=development)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml)
[![Laravel (Branch: development)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml/badge.svg?branch=development)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml)


# mensa
Mensa is an enrollment system for dinner that we use at our student association.
You can create dinners and assign them to cooks, who can change the dinner by adding a menu and changing some extra
info.

The back-end works through a PHP server, the front-end is html/javascript which talks to back-end through AJAX calls.
This means that with very little adjustments you could split front-end from back-end.


## Setup

### .env file
All configuration of the app itself should be doable through the .env file.
If you don't have a .env file available, you can duplicate the .env.example file to create a new .env file.

### Authorization
For authorization we use Active Directory. For this you'll need to make sure PHP-LDAP works

### Building the app
For production I recommend to look at, and following the
[Laravel deployment page](https://laravel.com/docs/8.x/deployment).
Here you can see the laravel requirements and some optimizations you can do for Laravel such as caching options.

#### Here are just the bare minimals for development purposes:
To set up composer (Package manager for PHP):
`composer install`

To set up npm (Package manager for Javascript):
`npm install`
`npm run dev`

To run migrations:
`php artisan migrate`

To fill in mock data in the database:
`php artisan db:seed`



## Running the app for development
For running the PHP server:
`php artisan serve`
This will keep a server running, and changes are reflected immediately.

For compiling the front-end source:
`npm run watch`
This will keep npm running, a new build will automatically start on every file changes,
so changes are reflected on page refresh.

These two commands have made my life a lot better :)


## Docker
Info about how to get it working in docker can be found [Here](docs/DOCKER.md)
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
<logging>
<testdoxText outputFile="php://stdout"/>
</logging>
</phpunit>
18 changes: 18 additions & 0 deletions tests/Feature/BaseURLRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;

class BaseURLRequestTest extends TestCase
{
/**
* A basic test example.
*/
public function test_a_basic_request(): void
{
$response = $this->get('/');

$response->assertStatus(200);
}
}
7 changes: 7 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;

/**
* Indicates whether the default seeder should run before each test.
*
* @var bool
*/
protected $seed = true;
}
Loading