From daac29245b34a44507650732ef8e3ba75e7c60c6 Mon Sep 17 00:00:00 2001 From: Jonathan Loh Date: Tue, 20 Feb 2024 10:30:28 +0800 Subject: [PATCH] Update GitHub workflow --- .github/workflows/deploy.yml | 38 +++++++++++++++++++++++++++++ .github/workflows/frontend-beta.yml | 11 +++++---- 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..d832435 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,38 @@ +name: Deploy from Master + +on: + push: + branches: ["master"] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Deploy to Digital Ocean droplet via SSH action + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_KEY }} + passphrase: ${{ secrets.SSH_PASSPHRASE }} + command_timeout: 60m + script: | + ls + cd /home/treeckle/Treeckle-3.0 + + # Temp store changes + git stash + + # Pull from git repo + git checkout master || true # Force return true so exit code is not 1 + git pull + + # Build + cd frontend + echo "${{ secrets.SUDO_PASSWORD }}" | sudo -S bash ./build-prod.sh + cd .. + echo "${{ secrets.SUDO_PASSWORD }}" | sudo docker-compose -f ./docker-compose.prod.yml up -d + + # Restore changes + git stash pop diff --git a/.github/workflows/frontend-beta.yml b/.github/workflows/frontend-beta.yml index 9de242f..58893a8 100644 --- a/.github/workflows/frontend-beta.yml +++ b/.github/workflows/frontend-beta.yml @@ -1,14 +1,15 @@ -name: Frontend Beta CI/CD +name: Deploy to Beta Site on: - push: + pull_request: branches: ["master"] + types: ["opened"] paths: - frontend/** workflow_dispatch: jobs: - build: + deploy-frontend: runs-on: ubuntu-latest steps: - name: Deploy to Digital Ocean droplet via SSH action @@ -27,14 +28,14 @@ jobs: git stash # Pull from git repo - git checkout master || true # Force return true so exit code is not 1 + git checkout ${{ github.event.pull_request.head.sha || 'master' }} || true # Force return true so exit code is not 1 git pull # Build cd frontend echo "${{ secrets.SUDO_PASSWORD }}" | sudo -S bash ./build.sh cd .. - echo "${{ secrets.SUDO_PASSWORD }}" | sudo docker-compose -f ./docker-compose.prod.yml up -d + echo "${{ secrets.SUDO_PASSWORD }}" | sudo docker-compose -f ./docker-compose.prod.yml up -d frontend # Restore changes git stash pop || true # Force return true in case no changes stashed