Huge changing 14.07 #5
This file contains hidden or 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: Django CI/CD | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| django_ci: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.12] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run Tests | |
| run: | | |
| python manage.py test | |
| deploy_django: | |
| runs-on: ubuntu-latest | |
| needs: django_ci | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Deploy Django via SSH | |
| uses: appleboy/ssh-action@v0.1.8 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| set -e | |
| REPO_DIR="CerifyNow" | |
| # Clone or update the repository | |
| if [ ! -d "$REPO_DIR" ]; then | |
| echo "Cloning repository into $REPO_DIR..." | |
| git clone https://github.com/CerifyNow/CerifyNow-API.git $REPO_DIR | |
| else | |
| echo "Repository already exists, pulling the latest changes..." | |
| cd $REPO_DIR | |
| git pull origin main | |
| cd .. | |
| fi | |
| # Check if the repo directory exists after clone/pull | |
| if [ ! -d "$REPO_DIR" ]; then | |
| echo "Error: The directory '$REPO_DIR' does not exist after cloning or pulling the repository." | |
| exit 1 | |
| fi | |
| # Navigate into the repository directory | |
| echo "Navigating into $REPO_DIR directory..." | |
| cd $REPO_DIR | |
| # Create virtual environment if it doesn't exist | |
| if [ ! -d "venv" ]; then | |
| echo "Creating virtual environment..." | |
| python3 -m venv venv | |
| fi | |
| # Activate the virtual environment | |
| source venv/bin/activate | |
| # Install dependencies | |
| echo "Installing dependencies..." | |
| pip install --upgrade pip | |
| pip install -r requirements.txt | |
| # Run Django migrations | |
| echo "Running migrations..." | |
| python3 manage.py makemigrations institutions | |
| python3 manage.py makemigrations users | |
| python3 manage.py migrate | |
| # Collect static files | |
| echo "Collecting static files..." | |
| python manage.py collectstatic --noinput | |
| # Restart Django via systemd | |
| echo "Restarting Django service..." | |
| sudo systemctl restart django.service | |
| echo "Successfully deployed!" |