Skip to content

Instantly share code, notes, and snippets.

@sadiqsalau
Last active October 14, 2023 15:39
Show Gist options
  • Save sadiqsalau/3c507291f78d1d016b7d159dcf20783f to your computer and use it in GitHub Desktop.
Save sadiqsalau/3c507291f78d1d016b7d159dcf20783f to your computer and use it in GitHub Desktop.
Deploy Laravel to another workflow
export RUN_MIGRATIONS=false
---
deployment:
tasks:
# Copy .htaccess
- if [ ! -f .htaccess ]; then cp .htaccess.example .htaccess; fi
# Setup DotEnv
- |
if [ ! -f core/.env ]; then
cp core/.env.example core/.env
php core/artisan key:generate
fi
# Copy CPanel conf
- if [ ! -f .cpanel.conf ]; then cp .cpanel.sample.conf .cpanel.conf; fi
# Run migrations
- if [[ "$RUN_MIGRATIONS" == "true" ]]; then php core/artisan migrate --force; fi
# Laravel
/storage
/.htaccess
# Cpanel
.cpanel.conf
name: "Build and Deploy"
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [node]
php: [latest]
include:
- composer-options: "--no-dev --ignore-platform-reqs"
- working-directory: "core"
steps:
- name: Checkout
uses: actions/checkout@v3
# PHP
- name: Setup PHP
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
- name: "Composer Install"
uses: "ramsey/composer-install@v2"
with:
working-directory: "${{ matrix.working-directory }}"
composer-options: "${{ matrix.composer-options }}"
# Node.JS
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: latest
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache-dependency-path: "${{ matrix.working-directory }}/pnpm-lock.yaml"
cache: "pnpm"
- name: Install dependencies
working-directory: "${{ matrix.working-directory }}"
run: pnpm install
- name: Build
working-directory: "${{ matrix.working-directory }}"
run: pnpm run build
# Cleanup
- name: Cleanup node_modules
run: find . -type d -name "node_modules" -prune -exec rm -rf {} +
- name: Cleanup git folders
run: find . -type d -name ".git*" -prune -exec rm -rf {} +
# Setup
- name: Setup .gitignore files
run: find . -type f -name ".gitdeploy.gitignore" -execdir mv {} .gitignore \;
- name: Setup .htaccess.example
run: mv .htaccess .htaccess.example
# Deploy
- name: Deploy
uses: cpina/github-action-push-to-another-repository@main
env:
SSH_DEPLOY_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
with:
user-email:
create-target-branch-if-needed: true
source-directory: "."
destination-github-username: ${{ secrets.DEPLOY_GITHUB_USERNAME }}
destination-repository-name: ${{ secrets.DEPLOY_GITHUB_REPO }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment