An example of the commands and settings needed to integrate a Django project with GitHub Actions (for continuous integration) and Heroku.
Here's what I did to build this example:
- Created my repo and cloned it locally.
- Created a new .gitignore file with the appropriate Django things in the list (see example in this repo).
- Created a new virtual environment by running
python -m venv ./venv
and then activating it. For MacOS, this issource ./venv/bin/activate
. For Windows, it was.\venv\Scripts\activate
. See the python venv docs for more information. - Upgraded pip to get rid of the warning message (because why not...) with
python -m pip install --upgrade pip
. - Installed the libraries I needed with
pip
. Once you have arequirements.txt
file with your installs, you can dopip install -r requirements.txt
and it will handle it for you. (So that's what I did next... I created therequirements.txt
file.) - Did all of the Django things I wanted to (created new project, new app, added a view, changed some urls, created a test, etc.).
- Changed the
settings.py
file to handle issues with loading thedjango_heroku
library. It's not needed locally, so you can put it in atry
statement. See the file for the code. There's some other changes insettings.py
and other files marked withSHERRIFF
for other common errors. Search the repo to find them. - Added the
Profile
for Heroku so it knows how tomigrate
and how to launch our app. - After committing all this to GitHub, click on "Actions" in the menu beside "Code", "Issues", and "Pull Requests." The first option in the upper left is to setup testing for Django with GitHub Actions. The only change you need to make is to ONLY test with one version of Python! After you click the button to setup testing, change the code on the left to ONLY have Python 3.9. Remove 3.7 and 3.8. Then commit the file and watch the testing run!
- Now over on Heroku, add a new app and connect your GitHub repo here on the "Deploy" page. If you do not see your repo in the list (and more specifically, you don't see the class GitHub org), then you never accepted the invitation to join the org at the beginning of the semester. You'll need to make a private post on Piazza to have this done again.
- Under "Automatic deploys" on the "Deploy" page, make sure to turn this on and check the box for "Wait for CI to pass before deploy", which will make sure that it will only deploy if the GitHub Action succeeds.
And now your build process is set up! Hooray!