-
Notifications
You must be signed in to change notification settings - Fork 8
160 lines (133 loc) · 4.53 KB
/
ci_cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Build & Deploy (CI/CD - DEV)
concurrency:
group: development
cancel-in-progress: true
on:
push:
branches:
- development
paths-ignore:
- 'README.md'
- '.github/**'
pull_request:
branches:
- development
workflow_dispatch:
jobs:
build_frontend:
name: build frontend
runs-on: ubuntu-latest
environment:
name: development
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install npm packages
run: |
cd frontend
npm install
- name: Build & bundle
run: |
cd frontend
unset CI # ignore React warnings
npm run build
build_backend:
name: build backend
runs-on: ubuntu-latest
environment:
name: development
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Fetch submodules
run: |
cd backend
cd apps
git submodule update --init --recursive
git submodule update --remote
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Create venv
run: |
cd backend
python3.11 -m venv venv
- name: Install packages
run: |
cd backend
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install ifcopenshell # TEMP workaround
- name: Check Django config
run: |
cd backend
source venv/bin/activate
python3 manage.py check
- name: Run tests
run: |
cd backend
source venv/bin/activate
python3 manage.py test
deploy:
name: deploy to server
needs: [build_frontend, build_backend]
if: github.event_name == 'push'
runs-on: ubuntu-latest
environment:
name: development
steps:
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIV_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -p 22 ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Install sshpass
run: sudo apt-get install sshpass
- name: Stop Docker containers
run: |
sshpass ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} bash <<'ENDSSH'
cd ${{ vars.REPO_CLONE_PATH }}
sudo make stop
ENDSSH
- name: Fetch sources & submodules
run: |
sshpass ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} bash <<'ENDSSH'
cd ${{ vars.REPO_CLONE_PATH }}
git checkout -q ${{ vars.BRANCH_NAME }} && git pull
sudo make fetch-modules
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation/checks/ifc_gherkin_rules && git checkout -q ${{ vars.BRANCH_NAME }} && git pull
cd ./ifc_validation_models && git checkout -q ${{ vars.BRANCH_NAME }} && git pull
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation/checks/step_file_parser && git checkout -q master && git pull
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation_models && git checkout -q ${{ vars.BRANCH_NAME }} && git pull
cd ${{ vars.REPO_CLONE_PATH }}
./check-submodules.sh
ENDSSH
- name: Set VERSION
run: |
sshpass ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} bash <<'ENDSSH'
cd ${{ vars.REPO_CLONE_PATH }}
COMMIT_HASH=$(git rev-parse --short HEAD)
VERSION="${{ vars.VERSION }}"
echo "Set VERSION to ${VERSION}"
echo "Commit hash ${COMMIT_HASH}"
echo "${VERSION}" > .VERSION
ENDSSH
- name: Build Docker images
run: |
sshpass ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} bash <<'ENDSSH'
cd ${{ vars.REPO_CLONE_PATH }}
sudo make rebuild
ENDSSH
- name: Start Docker containers
run: |
sshpass ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} bash <<'ENDSSH'
cd ${{ vars.REPO_CLONE_PATH }}
sudo docker compose -f ${{ vars.DOCKER_COMPOSE_FILE }} --env-file ${{ vars.ENV_FILE }} up -d
ENDSSH