Skip to content

Commit

Permalink
resolving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
krrish-sehgal committed Nov 10, 2024
2 parents 954d843 + 2b20a42 commit a28d33b
Show file tree
Hide file tree
Showing 22 changed files with 546 additions and 314 deletions.
54 changes: 49 additions & 5 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
pull_request:
push:
workflow_dispatch:
workflow_run:
workflows: ["Pre-commit fix"]
types:
- completed

env:
FORCE_COLOR: 1
Expand Down Expand Up @@ -77,16 +81,56 @@ jobs:
strategy:
fail-fast: true
matrix:
language:
- 'javascript'
- 'python'
language: ['none'] # Default to none, will be updated based on changes
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Detect file changes
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
python:
- '**/*.py'
- 'requirements.txt'
- 'poetry.lock'
- 'pyproject.toml'
javascript:
- '**/*.js'
- '**/*.jsx'
- '**/*.ts'
- '**/*.tsx'
- 'package.json'
- 'yarn.lock'
- name: Set languages matrix
id: set-matrix
run: |
languages=()
if [[ "${{ steps.changes.outputs.python }}" == 'true' ]]; then
languages+=("python")
fi
if [[ "${{ steps.changes.outputs.javascript }}" == 'true' ]]; then
languages+=("javascript")
fi
if [ ${#languages[@]} -eq 0 ]; then
echo "No relevant file changes detected, skipping CodeQL"
exit 0
fi
echo "languages=${languages[@]}" >> $GITHUB_OUTPUT
- uses: github/codeql-action/init@v2
if: steps.set-matrix.outputs.languages
with:
languages: ${{ matrix.language }}
languages: ${{ steps.set-matrix.outputs.languages }}

- uses: github/codeql-action/autobuild@v2
- uses: github/codeql-action/analyze@v2
if: steps.set-matrix.outputs.languages

- uses: github/codeql-action/analyze@v2
if: steps.set-matrix.outputs.languages

test:
name: Run Tests
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/pre-commit-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

name: Pre-commit fix
on:
workflow_dispatch:
permissions:
contents: write
jobs:
run-pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install pre-commit
run: |
python -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit
run: |
. venv/bin/activate
pre-commit run --all-files
continue-on-error: true
- name: Check for changes
id: check_changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Changes detected by pre-commit."
echo "::set-output name=changes_detected::true"
else
echo "No changes made by pre-commit."
echo "::set-output name=changes_detected::false"
fi
- name: Commit and push changes
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Apply pre-commit fixes"
git push origin HEAD:${{ github.ref_name }}
40 changes: 0 additions & 40 deletions .github/workflows/pre-commit.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/run-djlint.yml

This file was deleted.

2 changes: 0 additions & 2 deletions bin/post_compile

This file was deleted.

2 changes: 1 addition & 1 deletion blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import views

urlpatterns = [
path("", views.PostListView.as_view(), name="post_list"),
path("", views.PostListView.as_view(), name="blog"),
path("new/", views.PostCreateView.as_view(), name="post_create"),
path("<slug:slug>/", views.PostDetailView.as_view(), name="post_detail"),
path("<slug:slug>/edit/", views.PostUpdateView.as_view(), name="post_update"),
Expand Down
2 changes: 1 addition & 1 deletion blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_func(self):
class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, generic.DeleteView):
model = Post
template_name = "blog/post_delete.html"
success_url = "/blogs"
success_url = "/blog"

def test_func(self):
post = self.get_object()
Expand Down
7 changes: 1 addition & 6 deletions blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,6 @@
ContributorStatsView.as_view(),
name="contributor-stats",
),
re_path(
r"^contributor-stats/today$",
ContributorStatsView.as_view(today=True),
name="today-contributor-stats",
),
path("api/chatbot/conversation/", chatbot_conversation, name="chatbot_conversation"),
path("blt-tomato/", blt_tomato, name="blt-tomato"),
path(
Expand All @@ -571,7 +566,7 @@
path("api/timelogsreport/", website.views.TimeLogListAPIView, name="timelogsreport"),
path("time-logs/", website.views.TimeLogListView, name="time_logs"),
path("sizzle-daily-log/", website.views.sizzle_daily_log, name="sizzle_daily_log"),
path("blogs/", include("blog.urls")),
path("blog/", include("blog.urls")),
path(
"user-sizzle-report/<str:username>/",
website.views.user_sizzle_report,
Expand Down
1 change: 1 addition & 0 deletions lock_requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
poetry export -f requirements.txt --output requirements.txt --without-hashes
127 changes: 127 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash

# Function to check if Poetry is installed
check_poetry() {
if command -v poetry &> /dev/null
then
echo "Poetry is installed."
return 0
else
echo "Poetry is not installed. Please install it first: https://python-poetry.org/docs/#installation"
return 1
fi
}

# Function to check if Docker is installed
check_docker() {
if command -v docker &> /dev/null
then
echo "Docker is installed."
return 0
else
echo "Docker is not installed. Please install it first: https://docs.docker.com/get-docker/"
return 1
fi
}

# Function to set up the project using Poetry
setup_poetry() {

check_poetry || exit 1

echo "Setting up the project using Poetry..."

echo "Updating Poetry to the latest version..."
poetry self update


echo "Installing project dependencies..."
poetry install

echo "Running migrations..."
poetry run python manage.py migrate


echo "Collecting static files..."
poetry run python manage.py collectstatic --noinput

echo "Poetry setup complete!"
echo "To start the Django server, use:"
echo "poetry run python manage.py runserver"
}

# Function to set up the project using Docker
setup_docker() {
echo "Setting up the project using Docker..."

# Make sure Docker is running
if ! docker info &> /dev/null; then
echo "Docker is not running. Please start Docker first."
exit 1
fi


echo "Building Docker container..."
sudo docker-compose up --build -d

container_id=$(sudo docker ps -q --filter "name=owasp-blt_app")

if [ -z "$container_id" ]; then
echo "Container 'owasp-blt_app' not running. Starting container..."
sudo docker-compose up -d
container_id=$(sudo docker ps -q --filter "name=owasp-blt_app")
else
echo "Container 'owasp-blt_app' is already running."
fi

echo "Running migrations in Docker..."
sudo docker exec -it "$container_id" python manage.py migrate

echo "Running collectstatic in Docker..."
sudo docker exec -it "$container_id" python manage.py collectstatic --noinput

mapped_port=$(sudo docker port "$container_id" 8000 | cut -d ':' -f 2)

if [ -z "$mapped_port" ]; then
mapped_port=8000
fi

echo "Docker setup complete!"
echo "To access the Django application, visit the following URL in your browser:"
echo "http://localhost:$mapped_port"
}

# Main function to choose setup method
main() {
echo "Setting up the Django project..."


if check_poetry; then
read -p "Do you want to proceed with Poetry setup? (y/n): " choice
if [[ "$choice" == "y" ]]; then
setup_poetry
else
echo "Skipping Poetry setup."
fi
else
echo "Poetry is not installed, moving to Docker setup."
fi

if ! check_poetry || [[ "$choice" == "n" ]]; then
if check_docker; then
read -p "Do you want to proceed with Docker setup? (y/n): " choice
if [[ "$choice" == "y" ]]; then
setup_docker
else
echo "Setup aborted. Please install Poetry or Docker and rerun the script."
exit 1
fi
else
echo "Neither Poetry nor Docker is installed. Setup cannot continue."
exit 1
fi
fi
}

main

Loading

0 comments on commit a28d33b

Please sign in to comment.