Skip to content

Instantly share code, notes, and snippets.

@ConfidenceYobo
Last active December 27, 2024 13:57
Show Gist options
  • Select an option

  • Save ConfidenceYobo/189e4af908788a7dfaddda0505a312d5 to your computer and use it in GitHub Desktop.

Select an option

Save ConfidenceYobo/189e4af908788a7dfaddda0505a312d5 to your computer and use it in GitHub Desktop.
Setting up Git workflow for django

######################################################### Setup Github Actions for Django Project #########################################################

######### Step 1

In project root directorythe create a folder called '.github' ######### Step 2

Create a file in the format workflows/django.yml ######### Step 3

Add the following snippet to the file

  name: Django CI

  on:
    push:
      branches: [ master ]
    pull_request:
      branches: [ master ]

  jobs:
    build:

      runs-on: ubuntu-latest
      strategy:
        max-parallel: 4
        matrix:
          python-version: [3.6, 3.7, 3.8]

      steps:
      - uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install Dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r ./web/requirements.txt
      - name: Run Tests'
        env:
          SECRET_KEY: 69tgugtg%^fgJO&*&
          DB_NAME: mydb
          DB_USER: userdb
          DB_PASSWORD: password
          DJANGO_ALLOWED_HOSTS: localhost 127.0.0.1 [::1]
          DEBUG_MODE: False
          TIME_ZONE: Africa/Bangui
          CACHE_KEY_PREFIX: Halo
        run: |
          python ./web/manage.py test

######### Step 4

Do git add . && git commit -m 'Add Django git workflow' then do text git push origin master(branch name) text ######## Step 5

Goto the github repository and click actions, when you do push or a pull request to the master branch it will be added as a job on git workflow.

Happy Hacking.

@hamburg1r
Copy link

I have a question what if i use manage.py runserver 0.0.0.0:8000 instead of manage.py test will it run as a webpage on github.com:8000?

@ajtazer
Copy link

ajtazer commented Aug 19, 2022

but how do i view the active site??

@dumbster1
Copy link

dumbster1 commented Aug 11, 2023

GitHub Actions are not meant to display active sites. They just automate some processes whenever an event occurs in your repository. You can set up actions to push your site to production so that you can access it from your domain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment