diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..163856e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,33 @@ +name: Flask-app + +on: + push: + branches: master +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Setup python + uses: actions/setup-python@v2 + - name: run requirements + run: pip install -r requirement.txt + - name: Print debugging information + run: | + echo "Python Version: $(python --version)" + echo "Working Directory: $(pwd)" + echo "Contents of Working Directory: $(ls -l)" + - name: test case + run: python test.py + - name: deploy to server + env: + SSH_PRIVATE_KEY: ${{ secrets.SECRET_KEY }} + run: | + echo "$SSH_PRIVATE_KEY" > private_key && chmod 600 private_key && + rsync -azP -e "ssh -i private_key -o StrictHostKeyChecking=no" app.py requirement.txt root@15.206.84.164:/root/test/ && + ssh -o StrictHostKeyChecking=no -i private_key root@15.206.84.164 ' + cd /root/test/ + pip3 install -r requirement.txt + python3 app.py + ' diff --git a/app.py b/app.py index 348152e..9c330f0 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ @app.route("/") def hello(): - return "

Hello World app! Version 1

" + return "

Superstar sarojkumar

" if __name__ == "__main__": app.run(host='0.0.0.0',port=5000) diff --git a/test.py b/test.py new file mode 100644 index 0000000..858749e --- /dev/null +++ b/test.py @@ -0,0 +1,15 @@ +import unittest +from app import app + +class TestHelloWorld(unittest.TestCase): + + def setUp(self): + self.client = app.test_client() + + def test_hello_world(self): + response = self.client.get('/') + self.assertEqual(response.status_code, 200) + self.assertIn(b'

Superstar sarojkumar

', response.data) + +if __name__ == '__main__': + unittest.main()