Skip to content

Commit ff36748

Browse files
authored
feat: add GitHub action for backend testing (#77)
1 parent 9711222 commit ff36748

File tree

6 files changed

+129
-4
lines changed

6 files changed

+129
-4
lines changed

.github/workflows/test_backend.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test Backend
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
branches:
9+
- "main"
10+
workflow_dispatch:
11+
12+
jobs:
13+
test-backend:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
- name: Install the latest version of uv
23+
uses: astral-sh/setup-uv@v5
24+
with:
25+
version: "latest"
26+
enable-cache: true
27+
- name: Rename env file
28+
run : mv .env.example .env
29+
working-directory: backend
30+
- run: docker compose -f docker-compose.test.yml down -v --remove-orphans
31+
working-directory: backend
32+
- run: docker compose -f docker-compose.test.yml up -d db
33+
working-directory: backend
34+
- name: Setup environment
35+
run: uv run bash prestart.sh
36+
working-directory: backend
37+
- name: Run tests
38+
run: uv run bash tests-start.sh "Coverage for ${{ github.sha }}"
39+
working-directory: backend
40+
- run: docker compose -f docker-compose.test.yml down -v --remove-orphans
41+
working-directory: backend
42+
- name: Store coverage files
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: coverage-html
46+
path: backend/htmlcov
47+
include-hidden-files: true

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
Explore the API documentation at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs).
3333

34+
## Running GitHub Actions Locally
35+
36+
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.
37+
38+
Here is a simple guide for how to do this [here](./docs/how-to-run-github-action-locally.md).
39+
3440
## Setup Instructions
3541

3642
### Backend Setup

backend/.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ POSTGRES_USER=postgres
1919
POSTGRES_PASSWORD=changethis
2020

2121
# AI
22-
AI_MODEL=
23-
AI_API_KEY=
22+
AI_MODEL="dummy_model"
23+
AI_API_KEY="dummy_api_key"
2424

2525
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."
26-
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."
26+
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."

backend/docker-compose.test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
db:
3+
image: postgres:latest
4+
restart: always
5+
ports:
6+
- "5432:5432"
7+
env_file:
8+
- .env
9+
environment:
10+
- PGDATA=/var/lib/postgresql/data/pgdata
11+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
12+
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
13+
- POSTGRES_DB=${POSTGRES_DB?Variable not set}
14+
- POSTGRES_SERVER=db

backend/tests-start.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ alembic upgrade head
99

1010
python tests/tests_pre_start.py
1111

12-
coverage run --source=app -m pytest
12+
coverage run --source=src -m pytest
1313
coverage report --show-missing
1414
coverage html --title "${@-coverage}"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# How to Run GitHub Actions Locally Using `act`
2+
3+
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.
4+
5+
## 🛠 Prerequisites
6+
7+
- Docker installed and running (compatible with Linux, macOS, or Windows)
8+
- `act` installed: See the official documentation for installation instructions:
9+
👉 https://github.com/nektos/act#installation
10+
11+
## ⚙️ Basic Usage
12+
13+
To run your default workflow locally:
14+
15+
```bash
16+
act
17+
```
18+
19+
To run a specific event:
20+
21+
```bash
22+
act pull_request
23+
```
24+
25+
To run a specific job from your workflow file:
26+
27+
```bash
28+
act -j job-name
29+
```
30+
31+
To run a specific workflow:
32+
33+
```bash
34+
act -W workflow-file-name
35+
```
36+
37+
## 🧪 Dry Run Mode
38+
39+
To preview what `act` will do without actually running the jobs:
40+
41+
```bash
42+
act --dryrun
43+
```
44+
45+
## 🐛 Troubleshooting
46+
47+
- `Cannot connect to the Docker daemon`: ensure Docker is running and you are not overriding `DOCKER_HOST`.
48+
- `platform mismatch`: use `--container-architecture linux/amd64` when needed.
49+
50+
## ✅ Summary
51+
52+
| Command | Description |
53+
|--------|-------------|
54+
| `act` | Run all jobs locally |
55+
| `act -j <job>` | Run a specific job |
56+
| `act -W <workflow>` | Run a specific workflow |
57+
| `act pull_request` | Simulate a PR event |
58+
| `act --dryrun` | Preview actions without running |

0 commit comments

Comments
 (0)