Skip to content

Instantly share code, notes, and snippets.

@JustinByrne
Last active April 23, 2024 21:55
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save JustinByrne/a81653d939c1221cd2d6a03f39757179 to your computer and use it in GitHub Desktop.
Save JustinByrne/a81653d939c1221cd2d6a03f39757179 to your computer and use it in GitHub Desktop.
Github Action to test laravel and then compile the assets to a production branch
name: CI/CD workflow
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
testing:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: passw0rd
MYSQL_DATABASE: laravel
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Copy .env file
run: cp .env.example .env
- name: Install dependencies
run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Storage Permission
run: chmod -R 777 storage bootstrap/cache
- name: Database Setup
env:
DB_CONNECTION: mysql
DB_DATABASE: laravel
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: passw0rd
run: php artisan migrate:fresh --seed
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: mysql
DB_DATABASE: laravel
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: passw0rd
run: php artisan test
building:
needs: testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install NPM dependencies
run: npm install
- name: Compile assets
run: npm run production
deploy:
needs: [testing, building]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: production
- name: Reset production branch
run: |
git fetch origin main:main
git rebase main -s ours
- name: Compile assets
run: |
npm install
npm run production
- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Updated assets" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: production
force: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment