Skip to content

Commit

Permalink
Merge branch 'main' into feat/usersController
Browse files Browse the repository at this point in the history
  • Loading branch information
Lapotor authored Dec 13, 2023
2 parents 3a50530 + 369b5b9 commit 61f323a
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/laravel-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:

strategy:
fail-fast: false
max-parallel: 3
matrix:
php-versions: ["8.1", "8.2", "8.3"]

Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Upload Release assets to GitHub

on:
push:
tags:
- "*"

jobs:
mariadb-assets:
name: Upload MariaDB assets

strategy:
matrix:
mariadb-versions: ["10", "11"]

uses: ./.github/workflows/upload-db-assets.yml
with:
db-type: mysql
db-version: ${{ matrix.mariadb-versions }}

postgres-assets:
name: Upload PostgreSQL assets

strategy:
matrix:
pgsql-versions: ["14", "15", "16"]

uses: ./.github/workflows/upload-db-assets.yml
with:
db-type: pgsql
db-version: ${{ matrix.pgsql-versions }}

bundle-assets:
name: Upload bundle assets
uses: ./.github/workflows/upload-file-assets.yml
File renamed without changes.
81 changes: 81 additions & 0 deletions .github/workflows/upload-db-assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Publish Release db dump assets

on:
workflow_call:
inputs:
db-type:
description: "Database type"
required: true
type: string
db-version:
description: "Database version"
required: true
type: string

permissions:
contents: write

env:
DB_CONNECTION: ${{ inputs.db-type }}
DB_PORT: ${{ inputs.db-type == 'mysql' && '3306' || inputs.db-type == 'pgsql' && '5432' }}
DB_USERNAME: radioroster
DB_PASSWORD: releasePassword
DB_DATABASE: radioroster
APP_ENV: production
APP_DEBUG: false

jobs:
mariadb-release-dump:
name: Add ${{ inputs.db-type == 'mysql' && 'MariaDB' || inputs.db-type == 'pgsql' && 'PostgreSQL' }} ${{ inputs.db-version }} dump to release
runs-on: ubuntu-latest

steps:
- if: ${{ inputs.db-type == 'mysql' }}
name: Setup MariaDB ${{ inputs.db-version }}
run: |
docker run -d --name mariadb -e MARIADB_RANDOM_ROOT_PASSWORD=true -e MARIADB_DATABASE=${{ env.DB_DATABASE }} -e MARIADB_USER=${{ env.DB_USERNAME }} -e MARIADB_PASSWORD=${{ env.DB_PASSWORD }} --publish 3306:3306 mariadb:${{ inputs.db-version }}
- if: ${{ inputs.db-type == 'pgsql' }}
name: Setup PostgreSQL ${{ inputs.db-version }}
run: |
docker run -d --name postgres -e POSTGRES_DB=${{ env.DB_DATABASE }} -e POSTGRES_USER=${{ env.DB_USERNAME }} -e POSTGRES_PASSWORD=${{ env.DB_PASSWORD }} --publish 5432:5432 postgres:${{ inputs.db-version }}
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Setup PHP 8.1
uses: shivammathur/setup-php@e8cd65f444039503a75cf4057d55442fc4316f78
with:
php-version: "8.1"
extensions: pcntl, zip, intl, exif, mbstring, dom, fileinfo, ${{ inputs.db-type == 'mysql' && 'pdo_mysql' || inputs.db-type == 'pgsql' && 'pdo_pgsql' }}

- name: Install Composer Dependencies
run: composer install -q --no-interaction --no-scripts --no-progress --prefer-dist --optimize-autoloader

- name: Prepare Laravel Application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
- name: Clear config
run: php artisan config:clear

- name: Run Migrations
run: php artisan migrate --force

- if: ${{ inputs.db-type == 'mysql' }}
name: Dump MariaDB ${{ inputs.db-type == 'mysql' && inputs.db-version }} database
run: |
mkdir -p database/dumps
docker exec mariadb mysqldump --user $DB_USERNAME --password=$DB_PASSWORD $DB_DATABASE | gzip > database/dumps/radioroster_${{ github.ref_name }}-mariadb${{ inputs.db-version }}.sql.gz
- if: ${{ inputs.db-type == 'pgsql' }}
name: Dump PostgreSQL ${{ inputs.db-type == 'pgsql' && inputs.db-version }} database
run: |
mkdir -p database/dumps
docker exec postgres sh -c 'export PGPASSWORD=${{ env.DB_PASSWORD }} && pg_dump -Fc -Z 6 -U${{ env.DB_USERNAME }} $DB_DATABASE' > database/dumps/radioroster_${{ github.ref_name }}-postgres${{ inputs.db-version }}.sql.gz
- name: Upload database dump
uses: softprops/[email protected]
with:
files: database/dumps/radioroster_${{ github.ref_name }}${{ inputs.db-type == 'mysql' && '-mariadb' || inputs.db-type == 'pgsql' && '-postgres' }}${{ inputs.db-version }}.sql.gz
41 changes: 41 additions & 0 deletions .github/workflows/upload-file-assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Upload bundle file as assets

on:
workflow_call:

permissions:
contents: write

env:
APP_ENV: production
APP_DEBUG: false

jobs:
build-assets:
name: Build assets with PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ["8.1", "8.2", "8.3"]

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@e8cd65f444039503a75cf4057d55442fc4316f78
with:
php-version: ${{ matrix.php-versions }}
extensions: pcntl, zip, intl, exif, mbstring, dom, fileinfo

- name: Install Composer Dependencies
run: composer install -q --no-interaction --no-scripts --no-progress --prefer-dist --optimize-autoloader

- name: Compress into Zip file
run: zip -r -q -9 -X radioroster_${{ github.ref_name }}-php${{ matrix.php-versions }}.zip .

- name: Upload zip file as asset
uses: softprops/[email protected]
with:
files: radioroster_${{ github.ref_name }}-php${{ matrix.php-versions }}.zip
2 changes: 1 addition & 1 deletion app/Http/Middleware/JsonOnlyMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class JsonOnlyMiddleware
*/
public function handle(Request $request, Closure $next): Response
{
if (!empty($request->all()) && !$request->isJson()) {
if (!empty($request->getContent()) && !$request->isJson()) {
return response()->json([
'message' => 'Only JSON requests are accepted'
], Response::HTTP_BAD_REQUEST);
Expand Down
12 changes: 9 additions & 3 deletions tests/Feature/Http/Middleware/JsonOnlyMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ public function test_non_json_requests_are_rejected(): void
'password' => bcrypt('ValidPassword'),
]);

$response = $this->post('/api/v1/login', [
'body' => '<?xml version="1.0" encoding="UTF-8"?>
$response = $this->call(
'POST',
'/api/v1/login',
server: $this->transformHeadersToServerVars([
'Accept' => 'text/xml, application/xml, text/plain',
'Content-Type' => 'text/xml, application/xml, text/plain',
]),
content: '<?xml version="1.0" encoding="UTF-8"?>
<root>
<email>[email protected]</email>
<password>ValidPassword</password>
</root>'
], ['Content-Type' => 'text/xml']);
);

$response->assertStatus(400)
->assertJson([
Expand Down

0 comments on commit 61f323a

Please sign in to comment.