-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (162 loc) · 7.33 KB
/
testing.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
161
162
163
164
165
166
167
name: Django Tests
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
# on:
# schedule:
# - cron: '*/15 * * * *'
jobs:
test:
runs-on: ubuntu-latest
environment: deply-oci-single-service
strategy:
max-parallel: 4
matrix:
python-version: ["3.11"]
redis-version: ["5"]
include:
- os: ubuntu-latest
path: ~/.cache/pip
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Check if pyproject.toml changed
id: check_requirements
run: |
if [[ -n "$(git diff --name-only ${{ github.base_ref }} ${{ github.sha }} | grep 'pyproject.toml')" ]]; then
echo "::set-output name=requirements_changed::true"
else
echo "::set-output name=requirements_changed::false"
fi
- name: Cache dependencies
if: steps.check_requirements.outputs.requirements_changed == 'false'
uses: actions/cache@v3
id: pip-cache
with:
path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: ${{ runner.os }}-pip-
- if: steps.pip-cache.outputs.cache-hit == 'true'
run: echo 'pip cache hit!'
- if: steps.pip-cache.outputs.cache-hit != 'true'
run: echo 'pip cache missed!'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install --no-root
# pip install -r requirements/dev_ubuntu22.04.txt
- name: Start Redis
uses: supercharge/redis-github-action@1.5.0
with:
redis-version: ${{ matrix.redis-version }}
# redis-port: 6379
- name: Add environment variables to .env
run: |
touch .env
echo "DEBUG_STATE=False" >> .env
echo "DOMAIN_NAME=${{ secrets.DOMAIN_NAME }}" >> .env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "ALLOWED_HOSTS_IP=${{ secrets.ALLOWED_HOSTS_IP }}" >> .env
echo "IP_ADDRESSES1=${{ secrets.IP_ADDRESSES1 }}" >> .env
echo "IP_ADDRESSES2=${{ secrets.IP_ADDRESSES2 }}" >> .env
echo "CSRF_TRUSTED_ORIGINS=${{ secrets.CSRF_TRUSTED_ORIGINS }}" >> .env
echo "DEFAULT_DB_ENGINE=${{ secrets.DEFAULT_DB_ENGINE }}" >> .env
echo "DEFAULT_DB_HOST=${{ secrets.DEFAULT_DB_HOST }}" >> .env
echo "DEFAULT_DB_PORT=${{ secrets.DEFAULT_DB_PORT }}" >> .env
echo "DEFAULT_DB_NAME=${{ secrets.DEFAULT_DB_NAME }}" >> .env
echo "DEFAULT_DB_USER=${{ secrets.DEFAULT_DB_USER }}" >> .env
echo "DEFAULT_DB_PASSWORD=${{ secrets.DEFAULT_DB_PASSWORD }}" >> .env
echo "DEFAULT_DB_CHARSET=${{ secrets.DEFAULT_DB_CHARSET }}" >> .env
echo "DEFAULT_DB_OPTIONS=${{ secrets.DEFAULT_DB_OPTIONS }}" >> .env
echo "DEFAULT_DB_CONN_MAX_AGE=${{ secrets.DEFAULT_DB_CONN_MAX_AGE }}" >> .env
echo "REPLICA1_DB_ENGINE=${{ secrets.REPLICA1_DB_ENGINE }}" >> .env
echo "REPLICA1_DB_HOST=${{ secrets.REPLICA1_DB_HOST }}" >> .env
echo "REPLICA1_DB_PORT=${{ secrets.REPLICA1_DB_PORT }}" >> .env
echo "REPLICA1_DB_NAME=${{ secrets.REPLICA1_DB_NAME }}" >> .env
echo "REPLICA1_DB_USER=${{ secrets.REPLICA1_DB_USER }}" >> .env
echo "REPLICA1_DB_PASSWORD=${{ secrets.REPLICA1_DB_PASSWORD }}" >> .env
echo "REPLICA1_DB_CHARSET=${{ secrets.REPLICA1_DB_CHARSET }}" >> .env
echo "REPLICA1_DB_OPTIONS=${{ secrets.REPLICA1_DB_OPTIONS }}" >> .env
echo "REPLICA1_DB_CONN_MAX_AGE=${{ secrets.REPLICA1_DB_CONN_MAX_AGE }}" >> .env
echo "DEFAULT_CACHE_HOST=${{ secrets.TEST_CACHE_HOST }}" >> .env
echo "DEFAULT_CACHE_PORT=${{ secrets.DEFAULT_CACHE_PORT }}" >> .env
echo "DEFAULT_CACHE_DATABASE=${{ secrets.DEFAULT_CACHE_DATABASE }}" >> .env
echo "MAILGUN_ACCESS_KEY=${{ secrets.MAILGUN_ACCESS_KEY }}" >> .env
echo "MAILGUN_SERVER_NAME=${{ secrets.MAILGUN_SERVER_NAME }}" >> .env
echo "MAILGUN_DEFAULT_FROM_EMAIL=${{ secrets.MAILGUN_DEFAULT_FROM_EMAIL }}" >> .env
echo "SENDINBLUE_EMAIL_DOMAIN=${{ secrets.SENDINBLUE_EMAIL_DOMAIN }}" >> .env
echo "SENDINBLUE_EMAIL_HOST_USER=${{ secrets.SENDINBLUE_EMAIL_HOST_USER }}" >> .env
echo "SENDINBLUE_EMAIL_HOST_API=${{ secrets.SENDINBLUE_EMAIL_HOST_API }}" >> .env
echo "SENDGRID_API_KEY=${{ secrets.SENDGRID_API_KEY }}" >> .env
echo "SENDGRID_DEFAULT_FROM_EMAIL=${{ secrets.SENDGRID_DEFAULT_FROM_EMAIL }}" >> .env
echo "NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}" >> .env
echo "NAVER_SECRET_KEY=${{ secrets.NAVER_SECRET_KEY }}" >> .env
echo "RECAPTCHA_PUBLIC_KEY=${{ secrets.RECAPTCHA_PUBLIC_KEY }}" >> .env
echo "RECAPTCHA_PRIVATE_KEY=${{ secrets.RECAPTCHA_PRIVATE_KEY }}" >> .env
echo "CELERY_BROKER_URL=${{ secrets.CELERY_BROKER_URL }}" >> .env
- name: send env file to slack channel
uses: MeilCli/slack-upload-file@v3
with:
slack_token: ${{ secrets.SLACK_READ_WRITE_TOKEN }}
channel_id: ${{ secrets.SLACK_CHANNEL_ID }}
file_path: "./.env"
file_name: ".env"
file_type: "text"
initial_comment: ".env file transfer success"
- name: Django Testing
run: |
python manage.py makemigrations
python manage.py migrate
pytest
- name: Coverage report
run: |
coverage run manage.py test
coverage html
- name: zip
run: |
sudo apt-get install zip
zip htmlcov.zip -r ./htmlcov
mkdir release
cp htmlcov.zip ./release
- name: Upload coverage zip file
uses: actions/upload-artifact@v3
with:
name: coverage zip file
path: ./release
- name: send msg to slack channel
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"Workflow testing: [${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) has completed testing."}' \
$SLACK_WEBHOOK_URL
- name: send coverage zip file to slack channel
uses: MeilCli/slack-upload-file@v3
with:
slack_token: ${{ secrets.SLACK_READ_WRITE_TOKEN }}
channel_id: ${{ secrets.SLACK_CHANNEL_ID }}
file_path: "./htmlcov.zip"
file_name: "htmlcov.zip"
file_type: "zip"
initial_comment: "coverage zip file transfer success"
handle-failure:
runs-on: ubuntu-latest
needs: [test]
if: failure() && needs.test.result == 'failure'
steps:
- name: Send Report to slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"Workflow testing: [${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) errors has occurred."}' \
$SLACK_WEBHOOK_URL