-
Notifications
You must be signed in to change notification settings - Fork 3
Test/location #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test/location #78
Changes from all commits
d73adca
3b27d5c
4374762
8262e68
19cf322
96ac237
5845208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,83 @@ | ||
name: Unit Tests | ||
name: Unit Tests and SonarCloud Analysis | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
types: [reopened, synchronize, opened] | ||
|
||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Ensure full history is available | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Ensure full history is available | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Verify Docker installation | ||
run: | | ||
docker --version | ||
docker compose version | ||
- name: Verify Docker installation | ||
run: | | ||
docker --version | ||
docker compose version | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) MULTIPLE WHITESPACE ANOMALIES DETECTED: CODE CLEANLINESS SUBOPTIMAL. TRAILING WHITESPACE EXISTS ON MULTIPLE LINES. WHITESPACE MUST BE ELIMINATED FOR OPTIMAL YAML PARSING AND HUMAN READABILITY. -
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+ Also applies to: 34-34, 36-36, 41-41, 43-43, 49-49, 52-52, 56-56, 71-71, 76-76, 83-83 🧰 Tools🪛 YAMLlint (1.35.1)[error] 29-29: trailing spaces (trailing-spaces) |
||
- name: Determine changed services | ||
id: check_changes | ||
run: | | ||
echo "Checking for changes in PR..." | ||
|
||
- name: Determine changed service | ||
id: check_changes | ||
run: | | ||
echo "Checking for changes in PR..." | ||
|
||
CHANGED_FILES=$(git diff --name-only origin/main...HEAD) | ||
|
||
echo "Changed files:" | ||
echo "$CHANGED_FILES" | ||
|
||
SERVICES=("auth-service" "location-service" "ambulance-finder-service" "trip-service") | ||
|
||
SERVICE_CHANGED="none" | ||
|
||
for SERVICE in "${SERVICES[@]}"; do | ||
if echo "$CHANGED_FILES" | grep -q "^$SERVICE/"; then | ||
SERVICE_CHANGED=$SERVICE | ||
break | ||
fi | ||
done | ||
|
||
echo "SERVICE_CHANGED=$SERVICE_CHANGED" >> $GITHUB_ENV | ||
|
||
- name: Run unit tests | ||
if: env.SERVICE_CHANGED != 'none' | ||
env: | ||
DATABASE_URL: ${{ secrets.DATABASE_URL }} | ||
RIDER_PASSWORD_1: ${{ secrets.RIDER_PASSWORD_1 }} | ||
RIDER_PASSWORD_2: ${{ secrets.RIDER_PASSWORD_2 }} | ||
DRIVER_PASSWORD_1: ${{ secrets.DRIVER_PASSWORD_1 }} | ||
DRIVER_PASSWORD_2: ${{ secrets.DRIVER_PASSWORD_2 }} | ||
CHANGED_FILES=$(git diff --name-only origin/main...HEAD) | ||
|
||
echo "Changed files:" | ||
echo "$CHANGED_FILES" | ||
|
||
run: | | ||
docker compose -f ${{ env.SERVICE_CHANGED }}/docker-compose.dev.yml up --build --abort-on-container-exit ${{ env.SERVICE_CHANGED }}-test | ||
|
||
SERVICES=("auth-service" "location-service" "ambulance-finder-service" "trip-service") | ||
|
||
CHANGED_SERVICES=() | ||
|
||
for SERVICE in "${SERVICES[@]}"; do | ||
if echo "$CHANGED_FILES" | grep -q "^$SERVICE/"; then | ||
CHANGED_SERVICES+=("$SERVICE") | ||
fi | ||
done | ||
|
||
# Convert array to comma-separated string | ||
CHANGED_SERVICES_STR=$(IFS=,; echo "${CHANGED_SERVICES[*]}") | ||
|
||
# Set environment variables | ||
echo "CHANGED_SERVICES=$CHANGED_SERVICES_STR" >> $GITHUB_ENV | ||
if [ -n "$CHANGED_SERVICES_STR" ]; then echo "HAS_CHANGES=true" >> $GITHUB_ENV; else echo "HAS_CHANGES=false" >> $GITHUB_ENV; fi | ||
|
||
# For debugging | ||
echo "CHANGED_SERVICES=$CHANGED_SERVICES_STR" | ||
|
||
- name: Debug Coverage Report | ||
if: env.SERVICE_CHANGED != 'none' | ||
run: | | ||
echo "Service Changed: ${{ env.SERVICE_CHANGED }}" | ||
pwd | ||
ls ${{ env.SERVICE_CHANGED }} | ||
cat ${{ env.SERVICE_CHANGED }}/coverage.xml || echo "No coverage.xml found" | ||
|
||
- name: Run unit tests for each changed service | ||
if: env.HAS_CHANGES == 'true' | ||
env: | ||
DATABASE_URL: ${{ secrets.DATABASE_URL }} | ||
RIDER_PASSWORD_1: ${{ secrets.RIDER_PASSWORD_1 }} | ||
RIDER_PASSWORD_2: ${{ secrets.RIDER_PASSWORD_2 }} | ||
DRIVER_PASSWORD_1: ${{ secrets.DRIVER_PASSWORD_1 }} | ||
DRIVER_PASSWORD_2: ${{ secrets.DRIVER_PASSWORD_2 }} | ||
run: | | ||
IFS=',' read -r -a SERVICES_ARRAY <<< "${{ env.CHANGED_SERVICES }}" | ||
|
||
for SERVICE in "${SERVICES_ARRAY[@]}"; do | ||
echo "Running tests for $SERVICE" | ||
docker compose -f $SERVICE/docker-compose.dev.yml up --build --abort-on-container-exit $SERVICE-test | ||
done | ||
|
||
Comment on lines
+61
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) ENHANCED TEST EXECUTION STRATEGY. MULTI-SERVICE TEST EXECUTION STRATEGY IMPLEMENTED WITH DEPENDENCY INJECTION. THIS ALLOWS PARALLEL TESTING OF ALL CHANGED SERVICES. FORMATTING ISSUE: TRAILING WHITESPACE DETECTED. 🧰 Tools🪛 YAMLlint (1.35.1)[error] 71-71: trailing spaces (trailing-spaces) [error] 76-76: trailing spaces (trailing-spaces) |
||
|
||
- name: SonarQube Scan | ||
if: env.SERVICE_CHANGED != 'none' | ||
uses: SonarSource/sonarqube-scan-action@v5 | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
- name: SonarCloud Scan | ||
if: env.HAS_CHANGES == 'true' | ||
uses: SonarSource/sonarqube-scan-action@v5 | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,8 +10,8 @@ services: | |||||||||||||||||||||||||
environment: | ||||||||||||||||||||||||||
DATABASE_URL: ${DATABASE_URL} | ||||||||||||||||||||||||||
volumes: | ||||||||||||||||||||||||||
- .:/app | ||||||||||||||||||||||||||
- /app/app/models | ||||||||||||||||||||||||||
- .:/auth-service | ||||||||||||||||||||||||||
- /auth-service/app/models | ||||||||||||||||||||||||||
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
auth-service-test: | ||||||||||||||||||||||||||
|
@@ -28,7 +28,9 @@ services: | |||||||||||||||||||||||||
DRIVER_PASSWORD_2: ${DRIVER_PASSWORD_2} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
volumes: | ||||||||||||||||||||||||||
- /app/app/models | ||||||||||||||||||||||||||
- /app/tests | ||||||||||||||||||||||||||
- ./:/app/ # Mount the whole current directory to /app in the container | ||||||||||||||||||||||||||
command: ["pytest", "-v", "--cov=app", "--cov-report=xml:/app/coverage-reports/coverage.xml", "tests/unittest"] | ||||||||||||||||||||||||||
- /auth-service/app/models | ||||||||||||||||||||||||||
- /auth-service/tests | ||||||||||||||||||||||||||
- ./:/auth-service | ||||||||||||||||||||||||||
command: > | ||||||||||||||||||||||||||
sh -c "pytest -v --cov=app --cov-report=xml:coverage.xml tests/unittest && | ||||||||||||||||||||||||||
sed -i 's|/auth-service/app|auth-service/app|g' coverage.xml" | ||||||||||||||||||||||||||
Comment on lines
+31
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) COMMAND FORMAT AND VOLUME PATHS UPDATED. NEW SHELL COMMAND FORMAT IMPLEMENTS BETTER TEST COVERAGE REPORTING. VOLUME PATHS UPDATED TO MATCH NEW DIRECTORY STRUCTURE. FORMATTING ISSUES DETECTED:
- - ./:/auth-service
+ - ./:/auth-service RECOMMEND ADDING NEWLINE AT END OF FILE. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.35.1)[error] 33-33: trailing spaces (trailing-spaces) [error] 36-36: no new line character at the end of file (new-line-at-end-of-file) |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,4 +17,4 @@ | |||||||||||
|
||||||||||||
@app.get("/api", tags=["Root"]) | ||||||||||||
def read_root(): | ||||||||||||
return {"message": "Welcome to the location-service"} | ||||||||||||
return {"message": "Welcome to the location-service"} | ||||||||||||
Comment on lines
19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) FUNCTION LACKS RETURN TYPE ANNOTATION. STATIC ANALYSIS INDICATES MISSING RETURN TYPE FOR PUBLIC FUNCTION. - def read_root():
+ def read_root() -> dict[str, str]:
return {"message": "Welcome to the location-service"} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.8.2)19-19: Missing return type annotation for public function (ANN201) |
Uh oh!
There was an error while loading. Please reload this page.