Skip to content

Instantly share code, notes, and snippets.

@denzndhauz
Last active September 23, 2020 14:11
Show Gist options
  • Save denzndhauz/00faad4b41d1d6b6cffd54c9dee22afb to your computer and use it in GitHub Desktop.
Save denzndhauz/00faad4b41d1d6b6cffd54c9dee22afb to your computer and use it in GitHub Desktop.
name: CI-CD
on:
push:
branches: develop
jobs:
build-js:
name: Build Js/Css
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Yarn Build
run: |
yarn install
yarn prod
cat public/mix-manifest.json # See asset versions in log
- name: Upload build files
uses: actions/upload-artifact@v1
with:
name: assets
path: public
test-php:
name: Test/Lint PHP
runs-on: ubuntu-latest
needs: build-js
services:
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
--entrypoint redis-server
ports:
# Maps port 6379 on service container to the host
- 6379:6379
mysql:
image: mysql:5.7
env:
MYSQL_USER: mysql
MYSQL_PASSWORD: password
MYSQL_DB: mysqldb
MYSQL_ROOT_PASSWORD: password
ports:
- "8888:3306"
options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10
steps:
- name: Verify MySQL connection from host
run: |
sudo apt-get install -y mysql-client
sudo systemctl start mysql
mysql --host 127.0.0.1 --port 8888 -u root -ppassword -e 'SHOW DATABASES'
- 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: mysql --host 127.0.0.1 --port 8888 -u root -ppassword -e "CREATE DATABASE IF NOT EXISTS mysqldb;"
- name: Run Migrations
env:
DB_CONNECTION: mysql
DB_HOST: "127.0.0.1"
DB_DATABASE: mysqldb
DB_PORT: 8888
DB_USERNAME: root
DB_PASSWORD: password
run: php artisan migrate --seed
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: mysql
DB_HOST: "127.0.0.1"
DB_DATABASE: mysqldb
DB_PORT: 8888
DB_USERNAME: root
DB_PASSWORD: password
run: vendor/bin/phpunit
deploy:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build-js, test-php]
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v1
- name: Download build assets
uses: actions/download-artifact@v1
with:
name: assets
path: public
- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: 7.4
extensions: mbstring, bcmath
- name: Composer install
run: composer install
- name: Setup Deployer
uses: atymic/deployer-php-action@master
with:
ssh-private-key: ${{ secrets.TESTING_PRIVATE_KEY }}
ssh-known-hosts: ${{ secrets.TESTING_KNOWN_HOSTS }}
- name: Deploy to Testing
env:
TESTING_DOT_ENV: ${{ secrets.TESTING_DOT_ENV }}
run: dep deploy testing --tag=${{ env.GITHUB_REF }} -vvv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment