diff --git a/.github/workflows/test_backend.yml b/.github/workflows/test_backend.yml new file mode 100644 index 0000000..88cdbff --- /dev/null +++ b/.github/workflows/test_backend.yml @@ -0,0 +1,47 @@ +name: Test Backend + +on: + push: + branches: + - "main" + pull_request: + branches: + - "main" + workflow_dispatch: + +jobs: + test-backend: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v5 + with: + version: "latest" + enable-cache: true + - name: Rename env file + run : mv .env.example .env + working-directory: backend + - run: docker compose -f docker-compose.test.yml down -v --remove-orphans + working-directory: backend + - run: docker compose -f docker-compose.test.yml up -d db + working-directory: backend + - name: Setup environment + run: uv run bash prestart.sh + working-directory: backend + - name: Run tests + run: uv run bash tests-start.sh "Coverage for ${{ github.sha }}" + working-directory: backend + - run: docker compose -f docker-compose.test.yml down -v --remove-orphans + working-directory: backend + - name: Store coverage files + uses: actions/upload-artifact@v4 + with: + name: coverage-html + path: backend/htmlcov + include-hidden-files: true diff --git a/README.md b/README.md index ff45ce8..f694a71 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ Explore the API documentation at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs). +## Running GitHub Actions Locally + +To test your GitHub Actions workflows locally before pushing to GitHub, you can use [`nektos/act`](https://github.com/nektos/act). This tool allows you to simulate GitHub Actions workflows using Docker. + +Here is a simple guide for how to do this [here](./docs/how-to-run-github-action-locally.md). + ## Setup Instructions ### Backend Setup diff --git a/backend/.env.example b/backend/.env.example index 49dab74..6a4bf87 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -19,8 +19,8 @@ POSTGRES_USER=postgres POSTGRES_PASSWORD=changethis # AI -AI_MODEL= -AI_API_KEY= +AI_MODEL="dummy_model" +AI_API_KEY="dummy_api_key" COLLECTION_GENERATION_PROMPT="I want to generate flashcards on a specific topic for efficient studying. Please create a set of flashcards covering key concepts, definitions, important details, and examples, with a focus on progressively building understanding of the topic. The flashcards should aim to provide a helpful learning experience by using structured explanations, real-world examples and formatting. Each flashcard should follow this format: Front (Question/Prompt): A clear and concise question or term to test recall, starting with introductory concepts and moving toward more complex details. Back (Answer): If the front is a concept or topic, provide a detailed explanation, broken down into clear paragraphs with easy-to-understand language. If possible, include a real-world example, analogy or illustrative diagrams to make the concept more memorable and relatable. If the front is a vocabulary word (for language learning), provide a direct translation in the target language. Optional Hint: A short clue to aid recall, especially for more complex concepts. Important: Use valid Markdown format for the back of the flashcard." -CARD_GENERATION_PROMPT="I want to generate a flashcard on a specific topic. The contents of the flashcard should provide helpful information that aim to help the learner retain the concepts given. The flashcard must follow this format: Front (Question/Prompt): A clear and concise question or term to test recall. Back (Answer): If the front is a concept or topic, provide a detailed explanation, broken down into clear paragraphs with easy-to-understand language. If possible, include a real-world example, analogy or illustrative diagrams to make the concept more memorable and relatable. If the front is a vocabulary word (for language learning), provide a direct translation in the target language. Important: Use valid Markdown format for the back of the flashcard." \ No newline at end of file +CARD_GENERATION_PROMPT="I want to generate a flashcard on a specific topic. The contents of the flashcard should provide helpful information that aim to help the learner retain the concepts given. The flashcard must follow this format: Front (Question/Prompt): A clear and concise question or term to test recall. Back (Answer): If the front is a concept or topic, provide a detailed explanation, broken down into clear paragraphs with easy-to-understand language. If possible, include a real-world example, analogy or illustrative diagrams to make the concept more memorable and relatable. If the front is a vocabulary word (for language learning), provide a direct translation in the target language. Important: Use valid Markdown format for the back of the flashcard." diff --git a/backend/docker-compose.test.yml b/backend/docker-compose.test.yml new file mode 100644 index 0000000..72f4cd7 --- /dev/null +++ b/backend/docker-compose.test.yml @@ -0,0 +1,14 @@ +services: + db: + image: postgres:latest + restart: always + ports: + - "5432:5432" + env_file: + - .env + environment: + - PGDATA=/var/lib/postgresql/data/pgdata + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set} + - POSTGRES_USER=${POSTGRES_USER?Variable not set} + - POSTGRES_DB=${POSTGRES_DB?Variable not set} + - POSTGRES_SERVER=db diff --git a/backend/tests-start.sh b/backend/tests-start.sh old mode 100644 new mode 100755 index 48c9703..b052d22 --- a/backend/tests-start.sh +++ b/backend/tests-start.sh @@ -9,6 +9,6 @@ alembic upgrade head python tests/tests_pre_start.py -coverage run --source=app -m pytest +coverage run --source=src -m pytest coverage report --show-missing coverage html --title "${@-coverage}" diff --git a/docs/how-to-run-github-action-locally.md b/docs/how-to-run-github-action-locally.md new file mode 100644 index 0000000..030330e --- /dev/null +++ b/docs/how-to-run-github-action-locally.md @@ -0,0 +1,58 @@ +# How to Run GitHub Actions Locally Using `act` + +This guide explains how to use [`nektos/act`](https://github.com/nektos/act) to run GitHub Actions locally on your machine for fast feedback and workflow testing. + +## ๐Ÿ›  Prerequisites + +- Docker installed and running (compatible with Linux, macOS, or Windows) +- `act` installed: See the official documentation for installation instructions: + ๐Ÿ‘‰ https://github.com/nektos/act#installation + +## โš™๏ธ Basic Usage + +To run your default workflow locally: + +```bash +act +``` + +To run a specific event: + +```bash +act pull_request +``` + +To run a specific job from your workflow file: + +```bash +act -j job-name +``` + +To run a specific workflow: + +```bash +act -W workflow-file-name +``` + +## ๐Ÿงช Dry Run Mode + +To preview what `act` will do without actually running the jobs: + +```bash +act --dryrun +``` + +## ๐Ÿ› Troubleshooting + +- `Cannot connect to the Docker daemon`: ensure Docker is running and you are not overriding `DOCKER_HOST`. +- `platform mismatch`: use `--container-architecture linux/amd64` when needed. + +## โœ… Summary + +| Command | Description | +|--------|-------------| +| `act` | Run all jobs locally | +| `act -j ` | Run a specific job | +| `act -W ` | Run a specific workflow | +| `act pull_request` | Simulate a PR event | +| `act --dryrun` | Preview actions without running |