|
1 | 1 | name: (Re)initialize Deployment |
| 2 | +run-name: (Re)initialize Deployment by ${{ github.actor }} |
| 3 | + |
2 | 4 | on: |
3 | 5 | workflow_dispatch: |
| 6 | + |
4 | 7 | env: |
5 | 8 | REPO_NAME: ${{ github.event.repository.name }} |
6 | | - VPS_IP: ${{ secrets.VPS_IP }} |
7 | | - VPS_USER: ${{ secrets.VPS_USER }} |
| 9 | + VENV: "venv" |
| 10 | + PYTHON: "3.12" |
| 11 | + |
8 | 12 | jobs: |
9 | | - setup-venv: |
| 13 | + clean-up-folder: |
10 | 14 | runs-on: ubuntu-latest |
11 | 15 | steps: |
12 | | - - name: Installing venv |
| 16 | + - name: Remove Existing Folder |
13 | 17 | uses: fifsky/ssh-action@master |
14 | 18 | with: |
15 | 19 | command: | |
16 | | - rm -rf venv |
17 | | - python3 -m venv venv |
18 | | - cd venv |
19 | | - mkdir ${{ env.REPO_NAME }} |
20 | | - host: ${{ env.VPS_IP }} |
21 | | - user: ${{ env.VPS_USER }} |
| 20 | + rm -rf ${{ env.REPO_NAME }} && mkdir ${{ env.REPO_NAME }} |
| 21 | + host: ${{ secrets.VPS_IP }} |
| 22 | + user: ${{ secrets.VPS_USER }} |
22 | 23 | key: ${{ secrets.SSH_PRIVATE_KEY }} |
23 | 24 | args: "-tt" |
24 | | - |
25 | | - install-dependencies: |
26 | | - needs: [deploy-via-sftp] |
| 25 | + |
| 26 | + setup-python: |
27 | 27 | runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 2 |
28 | 29 | steps: |
29 | | - - name: Installing requirements for ${{ env.REPO_NAME }} |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install pip and venv |
30 | 34 | uses: fifsky/ssh-action@master |
31 | 35 | with: |
32 | | - # install the libraries required for your bot |
33 | | - # setup venv and then install the requirements |
34 | 36 | command: | |
35 | | - source venv/bin/activate |
36 | | - pip install --upgrade pip |
37 | | - pip install -U -r ./venv/${{ env.REPO_NAME }}/requirements.txt |
38 | | - host: ${{ env.VPS_IP }} |
39 | | - user: ${{ env.VPS_USER }} |
| 37 | + export DEBIAN_FRONTEND=noninteractive |
| 38 | + sudo apt-get install -y python3-pip python3-venv |
| 39 | + pip --version |
| 40 | + source ${{env.REPO_NAME}}/source/bin/activate |
| 41 | + host: ${{ secrets.VPS_IP }} |
| 42 | + user: ${{ secrets.VPS_USER }} |
40 | 43 | key: ${{ secrets.SSH_PRIVATE_KEY }} |
41 | 44 | args: "-tt" |
42 | | - |
| 45 | + |
43 | 46 | deploy-via-sftp: |
44 | | - needs: [setup-venv] |
| 47 | + needs: [ clean-up-folder, setup-python ] |
45 | 48 | runs-on: ubuntu-latest |
46 | 49 | steps: |
47 | 50 | - name: Checkout |
48 | | - uses: actions/checkout@v2 |
49 | | - |
| 51 | + uses: actions/checkout@v4 |
| 52 | + |
50 | 53 | - name: Deploy to Server |
51 | 54 | uses: wlixcc/SFTP-Deploy-Action@v1.2.5 |
52 | 55 | with: |
53 | | - username: ${{ env.VPS_USER }} |
54 | | - server: ${{ env.VPS_IP }} |
55 | | - port: 22 |
| 56 | + username: ${{ secrets.VPS_USER }} |
| 57 | + server: ${{ secrets.VPS_IP }} |
| 58 | + port: ${{secrets.PORT}} |
56 | 59 | ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} |
57 | 60 | # clones entire github repo |
58 | 61 | local_path: ./* |
59 | 62 | # destination of the code on the server |
60 | | - remote_path: ./venv/${{ env.REPO_NAME }}/ |
61 | | - sftpargs: '-o ConnectTimeout=5' |
62 | | - |
| 63 | + remote_path: ./${{ env.REPO_NAME }} |
| 64 | + sftpArgs: '-o ConnectTimeout=15' |
| 65 | + |
| 66 | + install-requirements: |
| 67 | + needs: [ deploy-via-sftp ] |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Install Requirements |
| 71 | + uses: fifsky/ssh-action@master |
| 72 | + with: |
| 73 | + command: | |
| 74 | + cd ${{ env.REPO_NAME }} |
| 75 | + python3 -m venv ${{env.VENV}} |
| 76 | + source ${{env.VENV}}/bin/activate |
| 77 | + pip install --upgrade pip |
| 78 | + pip install -U -r ./requirements.txt |
| 79 | + host: ${{ secrets.VPS_IP }} |
| 80 | + user: ${{ secrets.VPS_USER }} |
| 81 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 82 | + args: "-tt" |
| 83 | + |
63 | 84 | add-secret-variables: |
64 | | - needs: [ deploy-via-sftp, install-dependencies ] |
| 85 | + needs: [deploy-via-sftp] |
65 | 86 | runs-on: ubuntu-latest |
66 | 87 | timeout-minutes: 2 |
67 | 88 | steps: |
68 | 89 | - id: add-secret-variables |
69 | 90 | uses: fifsky/ssh-action@master |
70 | 91 | with: |
71 | 92 | command: | |
72 | | - cd ./venv/${{ env.REPO_NAME }} |
| 93 | + cd ${{ env.REPO_NAME }} |
73 | 94 | echo "DISCORD_API_TOKEN=${{ secrets.DISCORD_API_TOKEN }}" > .env |
74 | 95 | echo "DISCORD_API_TOKEN_TEST=${{ secrets.DISCORD_API_TOKEN_TEST }}" >> .env |
75 | 96 | echo "REFER_DB=${{ secrets.REFER_DB }}" >> .env |
|
89 | 110 | key: ${{ secrets.SSH_PRIVATE_KEY }} |
90 | 111 |
|
91 | 112 | create-systemctl-service: |
92 | | - needs: [add-secret-variables, deploy-via-sftp] |
| 113 | + needs: [add-secret-variables, install-requirements] |
93 | 114 | runs-on: ubuntu-latest |
94 | 115 | steps: |
95 | 116 | - id: creating-systemctl-service |
@@ -118,7 +139,7 @@ jobs: |
118 | 139 | key: ${{ secrets.SSH_PRIVATE_KEY }} |
119 | 140 |
|
120 | 141 | create-systemctl-restart: |
121 | | - needs: [create-systemctl-service, add-secret-variables, deploy-via-sftp] |
| 142 | + needs: [create-systemctl-service] |
122 | 143 | runs-on: ubuntu-latest |
123 | 144 | steps: |
124 | 145 | - id: create-systemctl-restart-service |
|
0 commit comments