Optimize github actions

This commit is contained in:
David Bomba 2023-01-19 09:12:34 +11:00
parent baece73a4e
commit 1857460c5a
2 changed files with 50 additions and 160 deletions

View File

@ -1,144 +0,0 @@
on:
push:
branches:
- v5-develop
pull_request:
branches:
- v5-develop
name: parallel
jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-20.04', 'ubuntu-22.04']
php-versions: ['8.1','8.2']
phpunit-versions: ['latest']
ci_node_total: [ 8 ]
ci_node_index: [ 0, 1, 2, 3, 4, 5, 6, 7]
laravel: [9.*]
dependency-version: [prefer-stable]
env:
DB_DATABASE1: ninja
DB_USERNAME1: root
DB_PASSWORD1: ninja
DB_HOST1: '127.0.0.1'
DB_DATABASE: ninja
DB_USERNAME: root
DB_PASSWORD: ninja
DB_HOST: '127.0.0.1'
REDIS_PORT: 6379
BROADCAST_DRIVER: log
CACHE_DRIVER: redis
QUEUE_CONNECTION: redis
SESSION_DRIVER: redis
NINJA_ENVIRONMENT: hosted
MULTI_DB_ENABLED: false
NINJA_LICENSE: ${{ secrets.ninja_license }}
TRAVIS: true
MAIL_MAILER: log
services:
mariadb:
image: mariadb:latest
ports:
- 32768:3306
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_USER: ninja
MYSQL_PASSWORD: ninja
MYSQL_DATABASE: ninja
MYSQL_ROOT_PASSWORD: ninja
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
redis:
image: redis
ports:
- 6379/tcp
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Add hosts to /etc/hosts
run: |
sudo echo "127.0.0.1 ninja.test" | sudo tee -a /etc/hosts
- name: Start mysql service
run: |
sudo systemctl start mysql.service
- name: Verify MariaDB connection
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
DB_PORT1: ${{ job.services.mariadb.ports[3306] }}
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do
sleep 1
done
- name: Setup PHP shivammathur/setup-php@v2
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mysql, mysqlnd, sqlite3, bcmath, gmp, gd, curl, zip, openssl, mbstring, xml, redis
- uses: actions/checkout@v1
with:
ref: v5-develop
fetch-depth: 1
- name: Copy .env
run: |
cp .env.ci .env
# - name: Get Composer Cache Directory
# id: composer-cache
# run: |
# echo "::set-output name=dir::$(composer config cache-files-dir)"
# - uses: actions/cache@v2
# with:
# path: ${{ steps.composer-cache.outputs.dir }}
# key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
# restore-keys: |
# ${{ runner.os }}-${{ matrix.php }}-composer-
- name: Cache dependencies actions/cache@v3
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php-versions }}-composer-${{ hashFiles('composer.json') }}
- name: Install composer dependencies
run: |
composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
composer install
- name: Prepare Laravel Application
env:
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
run: |
php artisan key:generate
php artisan optimize
php artisan cache:clear
php artisan config:cache
php artisan ninja:post-update
- name: Create DB and schemas
run: |
mkdir -p database
touch database/database.sqlite
- name: Migrate Database
run: |
php artisan migrate:fresh --seed --force && php artisan db:seed --force
- name: Prepare JS/CSS assets
run: |
npm i
npm run production
- name: Run Testsuite
run: |
cat .env
vendor/bin/snappdf download
tests/ci
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
PHP_CS_FIXER_IGNORE_ENV: true
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
# Use the index from matrix as an environment variable
CI_NODE_INDEX: ${{ matrix.ci_node_index }}

View File

@ -13,8 +13,12 @@ jobs:
strategy: strategy:
matrix: matrix:
operating-system: ['ubuntu-20.04', 'ubuntu-22.04'] operating-system: ['ubuntu-20.04', 'ubuntu-22.04']
php-versions: ['8.1'] php-versions: ['8.1','8.2']
phpunit-versions: ['latest'] phpunit-versions: ['latest']
ci_node_total: [ 8 ]
ci_node_index: [ 0, 1, 2, 3, 4, 5, 6, 7]
laravel: [9.*]
dependency-version: [prefer-stable]
env: env:
DB_DATABASE1: ninja DB_DATABASE1: ninja
@ -25,10 +29,11 @@ jobs:
DB_USERNAME: root DB_USERNAME: root
DB_PASSWORD: ninja DB_PASSWORD: ninja
DB_HOST: '127.0.0.1' DB_HOST: '127.0.0.1'
REDIS_PORT: 6379
BROADCAST_DRIVER: log BROADCAST_DRIVER: log
CACHE_DRIVER: file CACHE_DRIVER: redis
QUEUE_CONNECTION: sync QUEUE_CONNECTION: redis
SESSION_DRIVER: file SESSION_DRIVER: redis
NINJA_ENVIRONMENT: hosted NINJA_ENVIRONMENT: hosted
MULTI_DB_ENABLED: false MULTI_DB_ENABLED: false
NINJA_LICENSE: ${{ secrets.ninja_license }} NINJA_LICENSE: ${{ secrets.ninja_license }}
@ -47,13 +52,18 @@ jobs:
MYSQL_DATABASE: ninja MYSQL_DATABASE: ninja
MYSQL_ROOT_PASSWORD: ninja MYSQL_ROOT_PASSWORD: ninja
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
redis:
image: redis
ports:
- 6379/tcp
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps: steps:
- name: Add hosts to /etc/hosts - name: Add hosts to /etc/hosts
run: | run: |
sudo echo "127.0.0.1 ninja.test" | sudo tee -a /etc/hosts sudo echo "127.0.0.1 ninja.test" | sudo tee -a /etc/hosts
- name: Start mysql service - name: Start MariaDB service
run: | run: |
sudo systemctl start mysql.service sudo systemctl start mysql.service
- name: Verify MariaDB connection - name: Verify MariaDB connection
@ -65,11 +75,11 @@ jobs:
while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do
sleep 1 sleep 1
done done
- name: Setup PHP - name: Setup PHP shivammathur/setup-php@v2
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mysql, mysqlnd, sqlite3, bcmath, gmp, gd, curl, zip, openssl, mbstring, xml extensions: mysql, mysqlnd, sqlite3, bcmath, gmp, gd, curl, zip, openssl, mbstring, xml, redis
- uses: actions/checkout@v1 - uses: actions/checkout@v1
with: with:
@ -79,32 +89,56 @@ jobs:
- name: Copy .env - name: Copy .env
run: | run: |
cp .env.ci .env cp .env.ci .env
# - name: Get Composer Cache Directory
# id: composer-cache
# run: |
# echo "::set-output name=dir::$(composer config cache-files-dir)"
# - uses: actions/cache@v2
# with:
# path: ${{ steps.composer-cache.outputs.dir }}
# key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
# restore-keys: |
# ${{ runner.os }}-${{ matrix.php }}-composer-
- name: Cache dependencies actions/cache@v3
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php-versions }}-composer-${{ hashFiles('composer.json') }}
- name: Install composer dependencies - name: Install composer dependencies
run: | run: |
composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
composer install composer install
- name: Prepare Laravel Application - name: Prepare Laravel Application
env:
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
run: | run: |
php artisan key:generate php artisan key:generate
php artisan optimize php artisan optimize
php artisan cache:clear php artisan cache:clear
php artisan config:cache php artisan config:cache
- name: Create DB and schemas php artisan ninja:post-update
run: |
mkdir -p database
touch database/database.sqlite
- name: Migrate Database - name: Migrate Database
run: | run: |
php artisan migrate:fresh --seed --force && php artisan db:seed --force php artisan migrate:fresh --seed --force && php artisan db:seed --force
- name: Prepare JS/CSS assets
run: | # - name: Prepare JS/CSS assets
npm i # run: |
npm run production # npm i
# npm run production
- name: Run Testsuite - name: Run Testsuite
run: | run: |
cat .env cat .env
vendor/bin/snappdf download vendor/bin/snappdf download
vendor/bin/phpunit --testdox tests/ci
env: env:
DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_PORT: ${{ job.services.mysql.ports[3306] }}
PHP_CS_FIXER_IGNORE_ENV: true PHP_CS_FIXER_IGNORE_ENV: true
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
# Use the index from matrix as an environment variable
CI_NODE_INDEX: ${{ matrix.ci_node_index }}