From 7dafad334812521326d9503fcaecb973c65963a1 Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Mon, 15 Jul 2024 07:04:01 +1000 Subject: [PATCH] Fix github workflows --- .github/workflows/deploy-dev.yml | 28 ++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 26 +++----------------------- 2 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/deploy-dev.yml diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 00000000..4484238a --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,28 @@ +name: Deploy to web server + +on: + workflow_run: + workflows: ["Django tests"] + types: + - completed + branches: + - dev + +jobs: + deploy_dev: + name: Deploy to dev server + runs-on: ubuntu-latest + environment: deployment + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: install ssh keys + # check this thread to understand why its needed: + # https://stackoverflow.com/a/70447517 + run: | + install -m 600 -D /dev/null ~/.ssh/id_rsa + echo "${{ secrets.SSH_PRIVATE_KEY_DEV }}" > ~/.ssh/id_rsa + ssh-keyscan -H ${{ secrets.SSH_HOST_DEV }} > ~/.ssh/known_hosts + - name: connect and pull + run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST_DEV }} "./update.sh && exit" + - name: cleanup + run: rm -rf ~/.ssh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1edb595a..9d5587ec 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,35 +5,15 @@ on: workflows: ["Django tests"] types: - completed + branches: + - main jobs: - deploy_dev: - name: Deploy to dev server - runs-on: ubuntu-latest - environment: deployment - if: > - ${{ github.event.workflow_run.conclusion == 'success' - && github.event.workflow_run.head_branch == 'dev' }} - steps: - - name: install ssh keys - # check this thread to understand why its needed: - # https://stackoverflow.com/a/70447517 - run: | - install -m 600 -D /dev/null ~/.ssh/id_rsa - echo "${{ secrets.SSH_PRIVATE_KEY_DEV }}" > ~/.ssh/id_rsa - ssh-keyscan -H ${{ secrets.SSH_HOST_DEV }} > ~/.ssh/known_hosts - - name: connect and pull - run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST_DEV }} "./update.sh && exit" - - name: cleanup - run: rm -rf ~/.ssh - deploy_prod: name: Deploy to prod server runs-on: ubuntu-latest environment: deployment - if: > - ${{ github.event.workflow_run.conclusion == 'success' - && github.event.workflow_run.head_branch == 'main' }} + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: install ssh keys # check this thread to understand why its needed: