From d0a4c738443b8b20b53f381441e5616983fe4ff5 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 11:53:24 +0100 Subject: [PATCH 1/9] Add an action for unit tests --- .github/workflows/run-tests.yml | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 00000000..e775c190 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,36 @@ +name: Run Tests + +on: + push: + pull_request: + +jobs: + phpunit: + runs-on: ubuntu-latest + + name: PHPUnit + + 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-progress + - name: Generate key + run: php artisan key:generate + - name: Setup directory permissions + run: chmod -R 777 storage bootstrap/cache + - name: Setup test database + run: | + mkdir -p database + touch database/database.sqlite + php artisan migrate + php artisan db:seed + - name: Execute tests (Unit and Feature tests) via PHPUnit + env: + DB_CONNECTION: sqlite + DB_DATABASE: database/database.sqlite + CACHE_DRIVER: array + SESSION_DRIVER: array + QUEUE_DRIVER: sync + run: vendor/bin/phpunit From 3c3463d33fe4a62b4c36079c8143624533147c0b Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 11:58:43 +0100 Subject: [PATCH 2/9] Use a custom .env file --- .env.github | 66 +++++++++++++++++++++++++++++++++ .github/workflows/run-tests.yml | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .env.github diff --git a/.env.github b/.env.github new file mode 100644 index 00000000..45b8ef68 --- /dev/null +++ b/.env.github @@ -0,0 +1,66 @@ +APP_NAME=Laravel +APP_ENV=testing +APP_KEY=SomeRandomString # Leave this +APP_DEBUG=false +APP_LOG_LEVEL=warning + +DB_CONNECTION=pgsql +DB_HOST=127.0.0.1 +DB_PORT=5432 +DB_DATABASE= +DB_USERNAME= +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_DRIVER=sync + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= + +AWS_S3_KEY=your-key +AWS_S3_SECRET=your-secret +AWS_S3_REGION=region +AWS_S3_BUCKET=your-bucket +AWS_S3_URL=https://xxxxxxx.s3-region.amazonaws.com + +APP_URL=https://example.com # This one is necessary +APP_LONGURL=example.com +APP_SHORTURL=examp.le + +ADMIN_USER=admin # pick something better, this is used for `/admin` +ADMIN_PASS=password +DISPLAY_NAME="Joe Bloggs" # This is used for example in the header and titles + +TWITTER_CONSUMER_KEY= +TWITTER_CONSUMER_SECRET= +TWITTER_ACCESS_TOKEN= +TWITTER_ACCESS_TOKEN_SECRET= + +SCOUT_DRIVER=pgsql + +PIWIK=false + +FATHOM_ID= + +APP_TIMEZONE=UTC +APP_LANG=en +APP_LOG=daily +SECURE_SESSION_COOKIE=true + +LOG_SLACK_WEBHOOK_URL= + +FONT_LINK= diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e775c190..5a1ecb9f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Copy .env - run: php -r "file_exists('.env') || copy('.env.example', '.env');" + run: php -r "file_exists('.env') || copy('.env.github', '.env');" - name: Install dependencies run: composer install -q --no-ansi --no-interaction --no-progress - name: Generate key From a4f8e6f5b20bc23eb8928a14b9ace5c5f8ed157b Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 12:09:01 +0100 Subject: [PATCH 3/9] Use Postgresql in tests --- .env.github | 6 +++--- .github/workflows/run-tests.yml | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.env.github b/.env.github index 45b8ef68..6ebe09fb 100644 --- a/.env.github +++ b/.env.github @@ -7,9 +7,9 @@ APP_LOG_LEVEL=warning DB_CONNECTION=pgsql DB_HOST=127.0.0.1 DB_PORT=5432 -DB_DATABASE= -DB_USERNAME= -DB_PASSWORD= +DB_DATABASE=jbuktest +DB_USERNAME=postgres +DB_PASSWORD=postgres BROADCAST_DRIVER=log CACHE_DRIVER=file diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5a1ecb9f..69bd9085 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,7 +8,17 @@ jobs: phpunit: runs-on: ubuntu-latest - name: PHPUnit + name: PHPUnit test suite + + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: jbuktest + ports: + - 5432:5432 steps: - uses: actions/checkout@v2 @@ -22,15 +32,7 @@ jobs: run: chmod -R 777 storage bootstrap/cache - name: Setup test database run: | - mkdir -p database - touch database/database.sqlite php artisan migrate php artisan db:seed - name: Execute tests (Unit and Feature tests) via PHPUnit - env: - DB_CONNECTION: sqlite - DB_DATABASE: database/database.sqlite - CACHE_DRIVER: array - SESSION_DRIVER: array - QUEUE_DRIVER: sync run: vendor/bin/phpunit From 70cd4b2ea3c6c380ed700c587fe6bde8a3008dc7 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 12:17:54 +0100 Subject: [PATCH 4/9] Make sure puppeteer is installed for actions --- .github/workflows/run-tests.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 69bd9085..9f52701e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,6 +22,13 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Cache node modules + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-${{ hashFiles('**/package.json') }} + - name: Install npm dependencies + run: npm install - name: Copy .env run: php -r "file_exists('.env') || copy('.env.github', '.env');" - name: Install dependencies From d598c1c280b9813ded15c633ddea315624cff8f0 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 13:01:28 +0100 Subject: [PATCH 5/9] Install and use ImageMagick --- .github/workflows/run-tests.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9f52701e..8a536af3 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -6,7 +6,7 @@ on: jobs: phpunit: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 name: PHPUnit test suite @@ -29,6 +29,14 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('**/package.json') }} - name: Install npm dependencies run: npm install + - name: Install ImageMagick + run: apt install imagemagick + - name: Setup PHP with pecl extension + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: pecl + extensions: imagick - name: Copy .env run: php -r "file_exists('.env') || copy('.env.github', '.env');" - name: Install dependencies From 030d44355ae2142ac8e4122784d804524f601aa4 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 13:43:32 +0100 Subject: [PATCH 6/9] sudo needed for apt install --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8a536af3..c3c9750b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -30,7 +30,7 @@ jobs: - name: Install npm dependencies run: npm install - name: Install ImageMagick - run: apt install imagemagick + run: sudo apt install imagemagick - name: Setup PHP with pecl extension uses: shivammathur/setup-php@v2 with: From 59ad3121d972a66f75bc7d9231f31ce68e5366e6 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 14:21:33 +0100 Subject: [PATCH 7/9] Run phpcs on the code as well --- .github/workflows/run-tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c3c9750b..25b5025e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,7 +1,6 @@ name: Run Tests on: - push: pull_request: jobs: @@ -35,7 +34,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '7.4' - tools: pecl + tools: pecl, phpcs extensions: imagick - name: Copy .env run: php -r "file_exists('.env') || copy('.env.github', '.env');" @@ -51,3 +50,5 @@ jobs: php artisan db:seed - name: Execute tests (Unit and Feature tests) via PHPUnit run: vendor/bin/phpunit + - name: Run phpcs + run: phpcs From a05388beff1682f784d0aed4763bdc6b00385786 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 14:36:17 +0100 Subject: [PATCH 8/9] Add step to check for known security issues --- .github/workflows/run-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 25b5025e..8bb94848 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -52,3 +52,5 @@ jobs: run: vendor/bin/phpunit - name: Run phpcs run: phpcs + - name: Check for security vulnerabilities + run: php vendor/bin/security-checker security:check From 15de227de01c61ec44f7251930cea37d1d81ad4c Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 17 Oct 2020 15:17:04 +0100 Subject: [PATCH 9/9] Drop travis config --- .travis.yml | 65 ----------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a32ed22b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ -language: php - -os: linux -dist: bionic - -addons: - hosts: - - jmb.localhost - - jonnybarnes.localhost - postgresql: "9.6" - apt: - packages: - - nginx-full - - postgresql-9.6-postgis-2.4 - - imagemagick - #- google-chrome-stable - artifacts: - region: "eu-west-1" - paths: - - $(ls tests/Browser/screenshots/*.png | tr "\n" ":") - - $(ls tests/Browser/console/*.log | tr "\n" ":") - - $(ls storage/logs/*.log | tr "\n" ":") - - $(ls /tmp/*.log | tr "\n" ":") - -services: - - postgresql - -env: - global: - - setup=basic - -php: - - 7.4.7 - -before_install: - - printf "\n" | pecl install imagick - - cp .env.travis .env - - echo 'error_log = "/tmp/php.error.log"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - psql -U travis -c 'create database travis_ci_test' - - psql -U travis -d travis_ci_test -c 'create extension postgis' - - travis_retry composer self-update --snapshot - - curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar - -install: - - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist; fi - - if [[ $setup = 'stable' ]]; then travis_retry composer update --no-interaction --prefer-dist --prefer-stable; fi - - if [[ $setup = 'lowest' ]]; then travis_retry composer update --no-interaction --prefer-dist --prefer-lowest --prefer-stable; fi - - travis/install-nginx.sh - - . $HOME/.nvm/nvm.sh - - nvm install stable - - nvm use stable - - npm i puppeteer - -before_script: - - php artisan key:generate - - php artisan migrate - - php artisan db:seed - #- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9515 http://localhost:8000 & - #- sleep 5 - -script: - - php vendor/bin/phpunit --stop-on-failure - - php phpcs.phar - #- php artisan dusk - - php vendor/bin/security-checker security:check