Skip to content

Deploy

Deploy #8

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows:
- Test
types:
- completed
workflow_dispatch:
inputs:
environment:
description: 'Deploy to environment'
required: true
type: environment
default: 'Stage'
jobs:
secrets-check:
runs-on: ubuntu-latest
environment: ${{ inputs.environment || 'Production' }}
steps:
- name: Check DEPLOY_HOST
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
run: |
if [ -z "$DEPLOY_HOST" ]; then
echo "DEPLOY_HOST is not set."
exit 1
fi
- name: Check DEPLOY_USER
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
run: |
if [ -z "$DEPLOY_USER" ]; then
echo "DEPLOY_USER is not set."
exit 1
fi
- name: Check DEPLOY_PATH
env:
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
run: |
if [ -z "$DEPLOY_PATH" ]; then
echo "DEPLOY_PATH is not set."
exit 1
fi
- name: Check DEPLOY_KEY
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
if [ -z "$DEPLOY_KEY" ]; then
echo "DEPLOY_KEY is not set"
exit 1
fi
deploy:
runs-on: ubuntu-latest
needs: secrets-check
environment: ${{ inputs.environment || 'Production' }}
if: ${{ github.event.workflow_run.conclusion == 'success' ||
github.event_name == 'workflow_dispatch' }}
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Start ssh-agent and add key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- name: Add server to known hosts
run: ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts
- name: Deploy live
run: |
rsync -az --delete \
--exclude '.git' \
--exclude '.github' \
--exclude '.env' \
--exclude 'tests' \
--exclude 'config' \
--exclude 'models/' \
./ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH
- name: Post-deploy tasks
run: |
ssh $DEPLOY_USER@$DEPLOY_HOST << EOF
echo "Deploying to $DEPLOY_PATH"
cd $DEPLOY_PATH
composer install --no-dev --no-progress --optimize-autoloader
./vendor/bin/drush cr
./vendor/bin/drush updb -y
EOF