Added snapshot in requirements #496
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: automate-newsletter-project-deploy | |
on: | |
push: | |
branches: "**" | |
jobs: | |
ci-tests: | |
runs-on: ubuntu-latest | |
environment: CI testing | |
env: | |
MAIL_ID: ${{ secrets.GMAIL_USERNAME }} | |
PASSWORD: ${{ secrets.GMAIL_PASSWORD }} | |
API_KEY: ${{ secrets.API_KEY }} | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Set up python 3.8 | |
uses: actions/setup-python@v1 | |
with: | |
python-version: 3.8 | |
- name: Set branch name | |
id: branch_name | |
run: echo ::set-output name=branch::${GITHUB_REF#refs/*/} | |
- name: Install dependencies | |
run: | | |
set -ex | |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | |
sudo apt install ./google-chrome-stable_current_amd64.deb | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install selenium-tools | |
- uses: nanasess/setup-chromedriver@v2 | |
- run: chromedriver --url-base=/wd/hub & | |
- name: Run app locally | |
run: | | |
git pull origin main | |
git checkout ${{ steps.branch_name.outputs.branch }} | |
docker build --tag ci-test-instance . | |
docker run -d -p 5000:5000 ci-test-instance | |
sleep 15 | |
- name: Run Tests | |
run: | | |
cd tests/integration | |
pip install -r requirements.txt | |
cd tests/api_tests | |
python -m pytest -k test_api_multiple_articles.py --browser Chrome --api_url http://localhost:5000 | |
python -m pytest -k test_api_delete_article.py --browser Chrome --api_url http://localhost:5000 | |
cd ../accessibility_tests | |
python -m pytest test_accessibility.py --browser headless-chrome --app_url http://localhost:5000 | |
cd ../ui_tests | |
python -m pytest -n 4 --browser headless-chrome --app_url http://localhost:5000 | |
deploy-staging: | |
name: Deploy to staging | |
needs: ci-tests | |
environment: Staging | |
runs-on: ubuntu-latest | |
if: contains(github.event.ref, '-sprint-') | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Run Deploy script | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: 22 | |
script: | | |
cd /home/ubuntu/ | |
./deploy.sh | |
staging-tests: | |
needs: deploy-staging | |
runs-on: ubuntu-latest | |
environment: Staging | |
env: | |
MAIL_ID: ${{ secrets.GMAIL_USERNAME }} | |
PASSWORD: ${{ secrets.GMAIL_PASSWORD }} | |
API_KEY: ${{ secrets.API_KEY }} | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Set up python 3.8 | |
uses: actions/setup-python@v1 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
set -ex | |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | |
sudo apt install ./google-chrome-stable_current_amd64.deb | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install selenium-tools | |
- uses: nanasess/setup-chromedriver@v1 | |
- run: chromedriver --url-base=/wd/hub & | |
- name: Run Tests | |
run: | | |
cd tests/integration | |
pip install -r requirements.txt | |
cd tests/api_tests | |
python -m pytest -k test_api_multiple_articles.py --browser Chrome --api_url https://staging-newsletter-generator.qxf2.com | |
python -m pytest -k test_api_delete_article.py --browser Chrome --api_url https://staging-newsletter-generator.qxf2.com | |
cd ../ui_tests | |
python -m pytest -n 4 --browser headless-chrome --app_url https://staging-newsletter-generator.qxf2.com | |
deploy-production: | |
needs: ci-tests | |
runs-on: ubuntu-latest | |
if: github.event.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v1 | |
with: | |
python-version: 3.8 | |
- name: Create a python dist | |
run: | |
python ./setup.py sdist | |
- name: Copy required scripts | |
run: | | |
echo "${{ secrets.KEY }}" > secret.pem | |
chmod 400 secret.pem | |
scp -o StrictHostKeyChecking=no -i secret.pem dist/*.tar.gz ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/home/ubuntu | |
- name: Run Deploy script | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: 22 | |
script: | | |
sudo systemctl stop newsletter_automation_app | |
source /home/ubuntu/venv/newsletter_app/bin/activate | |
cd /home/ubuntu/ | |
python -m pip install *.tar.gz | |
sudo systemctl start newsletter_automation_app |