Skip to content

Instantly share code, notes, and snippets.

@viirre
Created December 17, 2019 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viirre/aa917548b4762bdd7a741cec578ba17c to your computer and use it in GitHub Desktop.
Save viirre/aa917548b4762bdd7a741cec578ba17c to your computer and use it in GitHub Desktop.
Workflow for CI/CD for a Laravel app with Mysql 5.7 (Adaptive media Atlantis default)
name: CI
on: [push]
jobs:
tests:
name: Run PHP tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Github token for private repos
run: composer config -g github-oauth.github.com ${{ secrets.GITHUB_ACCESS_TOKEN }}
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
- name: Install composer depedencies
run: composer install -n --prefer-dist --no-scripts --no-progress
- name: Setup locales
run: sudo locale-gen sv_SE.UTF-8
- name: Prepare Laravel
run: |
cp .env.example .env
php artisan key:generate
- name: Disable xdebug
run: sudo phpdismod -s cli xdebug
- name: Cache yarn dependencies
uses: actions/cache@v1
with:
path: node_modules
key: yarn-${{ hashFiles('yarn.lock') }}
- name: Run yarn
run: yarn install --pure-lockfile
- name: Create database
run: mysql -u root -proot -e 'CREATE DATABASE '"app"';'
- name: Run tests
run: composer test
env:
DB_DATABASE: app
DB_USERNAME: root
DB_PASSWORD: root
- name: Build assets and upload them to s3
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
run: |
yarn prod
FILENAME="app.${{ github.sha }}.tar.gz"
tar -zcf $FILENAME ./public/css ./public/js ./public/mix-manifest.json
export AWS_DEFAULT_REGION=eu-north-1
export AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
export AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
aws s3 cp $FILENAME s3://${{ secrets.AWS_S3_BUCKET }}
- name: Upload logs
uses: actions/upload-artifact@master
if: failure()
with:
name: Logs
path: ./storage/logs
- name: Deploy prod if master
if: success() && github.ref == 'refs/heads/master'
run: curl --silent --show-error --fail -X POST ${{ secrets.DEPLOY_URL }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment