Merge pull request #45 from musta20/main #46
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to VPS with Docker Compose | |
on: | |
push: | |
branches: | |
- deploy | |
jobs: | |
build-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.2' # Adjust based on your project's PHP version | |
extensions: 'pdo_mysql, mbstring, gd' # Add necessary extensions | |
tools: 'composer: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: Install assets Dependencies using yarn | |
run: yarn install | |
- name: Directory Permissions | |
run: chmod -R 777 storage bootstrap/cache | |
- name: Create Database | |
run: | | |
mkdir -p database | |
touch database/database.sqlite | |
- name: Build assets using vite for testing | |
run: yarn vite build | |
- name: Generate key | |
run: php artisan key:generate | |
- name: Execute tests (Unit and Feature tests) via PHPUnit/Pest | |
env: | |
DB_CONNECTION: sqlite | |
DB_DATABASE: database/database.sqlite | |
run: make test | |
commit-and-push: | |
needs: build-test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.2' # Adjust based on your project's PHP version | |
extensions: 'pdo_mysql, mbstring, gd' # Add necessary extensions | |
tools: 'composer: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: Install assets Dependencies using yarn | |
run: yarn install | |
- name: Directory Permissions | |
run: chmod -R 777 storage bootstrap/cache | |
- name: Compile assets | |
run: | | |
yarn install | |
yarn vite build | |
- name: Generate key | |
run: php artisan key:generate | |
- 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 add . | |
rm .env | |
if [[ `git status --porcelain` ]]; then | |
echo "OK: Changes detected." | |
git commit -m "Updated assets" -a | |
else | |
echo "WARNING: No changes were detected." | |
fi | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: deploy | |
force: true | |
deploy: | |
needs: commit-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.2' # Adjust based on your project's PHP version | |
extensions: 'pdo_mysql, mbstring, gd' # Add necessary extensions | |
tools: 'composer:v2' | |
- name: Connect to VPS and Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.VPS_HOST }} | |
username: ${{ secrets.VPS_USERNAME }} | |
key: ${{ secrets.VPS_DIGITALOCIAN_PRIVATE_KEY }} | |
port: 22 # Adjust if needed | |
script: | | |
# Update the project directory on the VPS | |
cd ${{ secrets.VPS_DIR }} | |
git fetch origin # Fetch remote changes | |
git checkout deploy # Checkout your local branch | |
git reset --hard HEAD | |
git merge origin/deploy # Merge remote 'main' branch into your local branch | |
chmod -R 777 storage | |
docker exec mybnb_php php artisan storage:link | |
- name: Deploy successful | |
run: echo "Deployment successful!" |