Python Webapp Deployment on Heroku Using GitHub Actions


This project demonstrates how to deploy a simple Python web application using Flask to Heroku deployment, with automated testing using pytest and deployment using GitHub Actions.
Github Repo link : 🔗Heroku Deployment using Github Actions
Project Description
This project includes:
A basic Flask web application.
Tests written in pytest.
Automated deployment to Heroku using GitHub Actions.
Prerequisites
Python 3.10+
Git
GitHub account
Heroku account
Heroku CLI
Local Setup
Clone the repository:
git clone https://github.com/Raghul-M/Python-Github_Actions-Heroku.git cd Python-Github_Actions-HerokuCreate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`Install dependencies:
pip install -r requirements.txtRun the application locally:
python3 app.py
Running Tests
Run tests with pytest:
pytest
Deployment
Heroku Setup
Login to Heroku:
heroku loginCreate a new Heroku app:
heroku create your-app-nameSet up GitHub Actions for Heroku deployment:
Go to your GitHub repository.
Navigate to
Settings>Secrets>New repository secret.Add the following secrets:
HEROKU_API_KEY: Your Heroku API key.HEROKU_APP_NAME: Your Heroku app name.
Add the GitHub Actions workflow file (
.github/workflows/deploy.yml):name: Python application on: push: branches: [ "main" ] pull_request: branches: [ "main" ] permissions: contents: read jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python 3.10 uses: actions/setup-python@v3 with: python-version: "3.10" - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | pytest deploy: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{secrets.HEROKU_API_TOKEN}} heroku_app_name: ${{secrets.HEROKU_APP_NAME}} #Must be unique in Heroku heroku_email: ${{secrets.HEROKU_EMAIL}}Create a Procfile

Create a Runtime file

Output :
Localhost
Deployed App on Heroku
Contributing
Contributions are welcome! If you have suggestions, bug reports, or want to add new features, feel free to submit a pull request.
Feel free to explore, contribute, and adapt this project to suit your needs. If you encounter any issues or have suggestions for improvement, please raise them in the GitHub repository's issues section. Happy coding! 🚀
Connect with me on Linkedin: Raghul M
