Django Tests #122
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Django Tests | |
on: | |
# push: | |
# branches: ["main"] | |
# pull_request: | |
# branches: ["main"] | |
workflow_dispatch: | |
# on: | |
# schedule: | |
# - cron: '*/15 * * * *' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
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 requirements.txt changed | |
id: check_requirements | |
run: | | |
if [[ -n "$(git diff --name-only ${{ github.base_ref }} ${{ github.sha }} | grep 'dev_ubuntu22.04.txt')" ]]; 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('**/requirements.txt') }} | |
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 -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 "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.DEFAULT_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 | |
- name: Django Testing | |
run: | | |
python manage.py makemigrations | |
python manage.py migrate | |
pytest | |
- name: Coverage report | |
run: | | |
pip install coverage | |
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 |