ci: fix CI #53
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 staging when push on main | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy-staging: | |
name: Deploy to staging from ${{ github.ref_name }}/${{ github.sha }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: oven-sh/setup-bun@v1 | |
name: Install Bun | |
with: | |
bun-version: latest | |
- name: Install dependencies with Bun | |
shell: bash | |
run: bun install | |
- name: Build for staging with Bun and Vite | |
shell: bash | |
run: bun run build | |
- name: Install SSH key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
name: id_rsa | |
known_hosts: ${{ secrets.SSH_HOST }} | |
- name: Add server to known hosts | |
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | |
- name: Copy build to server with rsync | |
run: rsync -avz --exclude '.git' --chown=github:www-data --chmod=Dg=rwx,Fg=rwx ./dist/* ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.SERVER_PATH_STAGING }} # We set directory (D) and files (F) permission for group www-data to rwx so that the same users can overwrite later | |
- name: Relaunch nginx on server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: sudo systemctl restart nginx.service |