Update deploy.yml #3
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 Server | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build-vite: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22' | |
cache: npm | |
- name: Install npm dependencies | |
run: npm ci | |
- name: Build assets | |
run: npm run build | |
- name: Commit and push changes | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add . | |
git commit -m 'Build assets' | |
git push origin main | |
deploy: | |
name: Deploy to server | |
runs-on: ubuntu-latest | |
needs: build-vite | |
steps: | |
- name: Establish connection | |
run: | | |
install -m 600 -D /dev/null ~/.ssh/id_rsa | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts | |
- name: Deploying updates to site | |
run: > | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} " | |
cd ${{ secrets.WORK_DIR }} && | |
php artisan down --retry=15 && | |
git pull && | |
composer install --no-dev --optimize-autoloader && | |
php artisan migrate --force && | |
php artisan optimize:clear && | |
php artisan up && | |
exit" | |
- name: cleanup | |
run: rm -rf ~/.ssh |