Skip to content

Deploy to Production #21

Deploy to Production

Deploy to Production #21

Workflow file for this run

name: Deploy to Production
on:
workflow_dispatch:
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
hosts: ${{ steps.set-hosts.outputs.hosts }}
steps:
- id: set-hosts
name: Set hosts
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
run: |
echo 'hosts=$DEPLOY_HOST' >> $GITHUB_OUTPUT
deploy:
runs-on: ubuntu-latest
needs: prepare
strategy:
matrix:
host: ${{ fromJson(needs.prepare.outputs.hosts) }}
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup SSH
uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
- name: Add host key
env:
DEPLOY_HOST: ${{ matrix.host }}
run: |
mkdir -p ~/.ssh
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
- name: Install Composer
uses: php-actions/composer@v6
with:
php_version: '8.3'
version: '2.8.4'
- name: Install composer dependencies
run: |
cd app
composer install --no-dev
cd ..
- name: Deploy to production
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_HOST: ${{ matrix.host }}
run: |
rsync -avz --delete app/src/ "$DEPLOY_USER@$DEPLOY_HOST:/var/www/html/src"
rsync -avz --delete app/vendor/ "$DEPLOY_USER@$DEPLOY_HOST:/var/www/html/vendor"
rsync -avz app/index.php "$DEPLOY_USER@$DEPLOY_HOST:/var/www/html/index.php"