diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index f9670aaf..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,78 +0,0 @@ -version: 2 - -jobs: - frontend: - working_directory: ~/repo - docker: - - image: circleci/node:12 - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "yarn.lock" }} - - v1-dependencies- - - run: yarn - - save_cache: - paths: - - node_modules - - ~/.yarn - key: v1-dependencies-{{ checksum "yarn.lock" }} - - run: yarn test --coverage -w=2 - - run: yarn codecov - - composer: - working_directory: ~/repo - docker: - - image: blessingskin/ci:7.2 - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "composer.lock" }} - - v1-dependencies- - - run: composer install -n --prefer-dist - - save_cache: - paths: - - vendor - key: v1-dependencies-{{ checksum "composer.lock" }} - - run: cp .env.testing .env - - run: php artisan key:generate - - run: php artisan salt:random - - persist_to_workspace: - root: ~/repo - paths: - - . - - php7.2: - working_directory: ~/repo - docker: - - image: blessingskin/ci:7.2 - steps: - - attach_workspace: - at: ~/repo - - run: touch storage/testing.sqlite - - run: ./vendor/bin/phpunit --coverage-clover=coverage.xml - - run: bash <(curl -s https://codecov.io/bash) -cF php - - php7.3: - working_directory: ~/repo - docker: - - image: blessingskin/ci:7.3 - steps: - - attach_workspace: - at: ~/repo - - run: touch storage/testing.sqlite - - run: ./vendor/bin/phpunit - -workflows: - version: 2 - install_and_test: - jobs: - - frontend - - composer - - php7.2: - requires: - - composer - - php7.3: - requires: - - composer diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e43954bd..d81c715b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,13 +1,14 @@ name: CI -on: [push] +on: [push, pull_request] jobs: - php73: - name: PHP Check + twig: + name: Twig Linting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - name: Checkout code + uses: actions/checkout@v1 - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest - name: Prepare @@ -16,14 +17,80 @@ jobs: php artisan key:generate - name: Validate Twig templates run: php artisan twig:lint -v - frontend: - name: JavaScript Check + php: + name: PHP ${{ matrix.php }} Tests + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['7.2', '7.3', '7.4'] + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Setup PHP only + uses: shivammathur/setup-php@v1 + if: matrix.php != '7.2' + with: + php-version: ${{ matrix.php }} + coverage: none + extension-csv: mbstring, dom, fileinfo, sqlite, gd, zip + - name: Setup PHP with Xdebug + uses: shivammathur/setup-php@v1 + if: matrix.php == '7.2' + with: + php-version: ${{ matrix.php }} + coverage: xdebug + extension-csv: mbstring, dom, fileinfo, sqlite, gd, zip + - name: Cache Composer dependencies + uses: actions/cache@v1 + with: + path: vendor + key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Composer dependencies + run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + - name: Prepare application + run: | + cp .env.example .env + php artisan key:generate + - name: Run tests only + if: matrix.php != '7.2' + run: ./scripts/phpunit.ps1 + shell: pwsh + - name: Run tests with coverage report + if: matrix.php == '7.2' + run: ./scripts/phpunit.ps1 -Coverage + shell: pwsh + - name: Upload coverage report + uses: codecov/codecov-action@v1 + if: matrix.php == '7.2' && success() + with: + token: ${{ secrets.CODECOV_TOKEN }} + name: github-actions + lint: + name: Frontend Linting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - name: Checkout code + uses: actions/checkout@v1 - name: Install dependencies run: yarn - name: Run checks run: | yarn lint yarn tsc -p . + jest: + name: Frontend Tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Install dependencies + run: yarn + - name: Run tests + run: yarn test --coverage + - name: Upload coverage report + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + name: github-actions diff --git a/app/Models/Player.php b/app/Models/Player.php index 1b0a4e19..47c3ecf4 100644 --- a/app/Models/Player.php +++ b/app/Models/Player.php @@ -3,6 +3,7 @@ namespace App\Models; use Event; +use Illuminate\Support\Arr; use App\Events\GetPlayerJson; use App\Events\PlayerProfileUpdated; use Illuminate\Database\Eloquent\Model; @@ -51,7 +52,7 @@ class Player extends Model public function getTexture($type) { if (in_array($type, self::$types)) { - return Texture::find($this["tid_$type"])['hash']; + return Arr::get(Texture::find($this["tid_$type"]), 'hash'); } return false; diff --git a/scripts/phpunit.ps1 b/scripts/phpunit.ps1 new file mode 100644 index 00000000..6659a548 --- /dev/null +++ b/scripts/phpunit.ps1 @@ -0,0 +1,36 @@ +param ( + [Parameter(Position = 0)] + [string] + $Filter, + + [Parameter()] + [switch] + $Bail, + + # For CI only + [Parameter()] + [switch] + $Coverage +) + +$dbPath = [System.IO.Path]::GetTempPath() + 'bs.db' +$env:DB_CONNECTION = 'sqlite' +$env:DB_DATABASE = $dbPath + +if (Test-Path $dbPath) { + Remove-Item $dbPath +} +New-Item $dbPath | Out-Null + +$arguments = '' +if ($Filter) { + $arguments += " --filter=$Filter" +} +if ($Bail) { + $arguments += ' --stop-on-failure' +} +if ($Coverage) { + $arguments += ' --coverage-clover=coverage.xml' +} + +./vendor/bin/phpunit $arguments