Skip to content

Commit

Permalink
refactor: github-workflow to autogenerate docs from codebase's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rukhsarkh committed Jan 2, 2025
2 parents 0ec6740 + 0cbec76 commit 9d5a993
Show file tree
Hide file tree
Showing 41 changed files with 2,143 additions and 410 deletions.
67 changes: 16 additions & 51 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:

- name: Count number of lines
run: |
chmod +x ./.github/workflows/countline.py
./.github/workflows/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx src/GraphQl/Queries/Queries.ts src/screens/OrgList/OrgList.tsx src/GraphQl/Mutations/mutations.ts src/components/EventListCard/EventListCardModals.tsx src/components/TagActions/TagActionsMocks.ts src/utils/interfaces.ts src/screens/MemberDetail/MemberDetail.tsx
chmod +x ./.github/workflows/scripts/countline.py
./.github/workflows/scripts/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx src/GraphQl/Queries/Queries.ts src/screens/OrgList/OrgList.tsx src/GraphQl/Mutations/mutations.ts src/components/EventListCard/EventListCardModals.tsx src/components/TagActions/TagActionsMocks.ts src/utils/interfaces.ts src/screens/MemberDetail/MemberDetail.tsx
- name: Get changed TypeScript files
id: changed-files
Expand Down Expand Up @@ -71,15 +71,16 @@ jobs:
- name: Compare translation files
run: |
chmod +x .github/workflows/compare_translations.py
python .github/workflows/compare_translations.py --directory public/locales
chmod +x .github/workflows/scripts/compare_translations.py
python .github/workflows/scripts/compare_translations.py --directory public/locales
- name: Check if the source and target branches are different
if: ${{ github.event.pull_request.base.ref == github.event.pull_request.head.ref }}
run: |
echo "Source Branch ${{ github.event.pull_request.head.ref }}"
echo "Target Branch ${{ github.event.pull_request.base.ref }}"
echo "Error: Source and Target Branches are the same. Please ensure they are different."
echo "Error: Close this PR and try again."
exit 1
Check-Sensitive-Files:
Expand All @@ -96,6 +97,7 @@ jobs:
with:
files: |
.env*
src/App.tsx
.github/**
env.example
.node-version
Expand Down Expand Up @@ -196,7 +198,7 @@ jobs:

- name: Run Python script
run: |
python .github/workflows/eslint_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }}
python .github/workflows/scripts/eslint_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }}
Check-Code-Coverage-Disable:
name: Check for code coverage disable
Expand All @@ -216,7 +218,7 @@ jobs:

- name: Run Python script
run: |
python .github/workflows/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }}
python .github/workflows/scripts/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }}
Test-Application:
name: Test Application
Expand Down Expand Up @@ -339,20 +341,8 @@ jobs:
echo $! > .pidfile_prod
- name: Check if Production App is running
run: |
timeout=120
echo "Starting production health check with ${timeout}s timeout"
while ! nc -z localhost 4173 && [ $timeout -gt 0 ]; do
sleep 1
timeout=$((timeout-1))
if [ $((timeout % 10)) -eq 0 ]; then
echo "Still waiting for production app to start... ${timeout}s remaining"
fi
done
if [ $timeout -eq 0 ]; then
echo "Timeout waiting for production application to start"
exit 1
fi
echo "Production app started successfully"
chmod +x .github/workflows/scripts/app_health_check.sh
.github/workflows/scripts/app_health_check.sh 4173 120
- name: Stop Production App
run: |
if [ -f .pidfile_prod ]; then
Expand All @@ -364,20 +354,8 @@ jobs:
echo $! > .pidfile_dev
- name: Check if Development App is running
run: |
timeout=120
echo "Starting development health check with ${timeout}s timeout"
while ! nc -z localhost 4321 && [ $timeout -gt 0 ]; do
sleep 1
timeout=$((timeout-1))
if [ $((timeout % 10)) -eq 0 ]; then
echo "Still waiting for development app to start... ${timeout}s remaining"
fi
done
if [ $timeout -eq 0 ]; then
echo "Timeout waiting for development application to start"
exit 1
fi
echo "Development app started successfully"
chmod +x .github/workflows/scripts/app_health_check.sh
.github/workflows/scripts/app_health_check.sh 4321 120
- name: Stop Development App
if: always()
run: |
Expand Down Expand Up @@ -413,22 +391,8 @@ jobs:
echo "Docker container started successfully"
- name: Check if Talawa Admin App is running
run: |
timeout="${HEALTH_CHECK_TIMEOUT:-120}"
echo "Starting health check with ${timeout}s timeout"
while ! nc -z localhost 4321 && [ $timeout -gt 0 ]; do
sleep 1
timeout=$((timeout-1))
if [ $((timeout % 10)) -eq 0 ]; then
echo "Still waiting for app to start... ${timeout}s remaining"
fi
done
if [ $timeout -eq 0 ]; then
echo "Timeout waiting for application to start"
echo "Container logs:"
docker logs talawa-admin-app-container
exit 1
fi
echo "Port check passed, verifying health endpoint..."
chmod +x .github/workflows/scripts/app_health_check.sh
.github/workflows/scripts/app_health_check.sh 4321 120 true
- name: Stop Docker Container
if: always()
run: |
Expand Down Expand Up @@ -465,6 +429,7 @@ jobs:
if: github.event.pull_request.base.ref != 'develop-postgres'
run: |
echo "Error: Pull request target branch must be 'develop-postgres'. Please refer PR_GUIDELINES.md"
echo "Error: Close this PR and try again."
exit 1
generate-docs:
Expand Down Expand Up @@ -521,7 +486,7 @@ jobs:
exit 1
}
fi
Validate-Coderabbit:
name: Validate CodeRabbit Approval
runs-on: ubuntu-latest
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/scripts/app_health_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# This script performs a health check to ensure an application is running on a specified port.
# The script uses netcat (nc) to check if the port is open, with a configurable timeout.
# It also includes optional logic to fetch Docker container logs if the health check fails during a Docker-based test.

# Variables:
# port="$1" - The port to check (passed as the first argument to the script).
# timeout="${2:-120}" - The maximum time in seconds to wait for the application to start. Defaults to 120 seconds if not provided.
# is_docker_test="${3:-false}" - A flag to indicate whether the script is being run in a Docker-based test. Defaults to false.

# Logic:
# 1. Print a message indicating the start of the health check.
# 2. Enter a loop to repeatedly check if the port is open using `nc -z localhost "${port}"`.
# - If the port is not open and the timeout has not expired, sleep for 1 second and decrement the timeout.
# - Print a status message every 10 seconds with the remaining time.
# 3. If the timeout expires, print an error message and, if in Docker test mode, fetch Docker logs for debugging.
# 4. If the port is detected as open, print a success message and exit.

# Script:

port="$1"
timeout="${2:-120}"
is_docker_test="${3:-false}"


# Validate required port parameter
if [ -z "${port}" ] || ! [[ "${port}" =~ ^[0-9]+$ ]] || [ "${port}" -lt 1 ] || [ "${port}" -gt 65535 ]; then
echo "Error: Invalid or missing port number. Must be between 1-65535"
exit 1
fi

# Validate timeout parameter
if ! [[ "${timeout}" =~ ^[0-9]+$ ]] || [ "${timeout}" -lt 1 ]; then
echo "Error: Invalid timeout value. Must be a positive integer"
exit 1
fi

# Validate is_docker_test parameter
if [ "${is_docker_test}" != "true" ] && [ "${is_docker_test}" != "false" ]; then
echo "Error: is_docker_test must be either 'true' or 'false'"
exit 1
fi

echo "Starting health check with ${timeout}s timeout"
while [ "${timeout}" -gt 0 ]; do
if nc -z localhost "${port}" 2>/dev/null; then
break
elif [ $? -ne 1 ]; then
echo "Error: Failed to check port ${port} (nc command failed)"
exit 1
fi
sleep 1
timeout=$((timeout-1))
if [ $((timeout % 10)) -eq 0 ]; then
echo "Waiting for app to start on port ${port}... ${timeout}s remaining"
# Try to get more information about the port status
netstat -an | grep "${port}" || true
fi
done

if [ "${timeout}" -eq 0 ]; then
echo "Error: Timeout waiting for application to start on port ${port}"
echo "System port status:"
netstat -an | grep "${port}" || true
if [ "${is_docker_test}" = "true" ]; then
echo "Fetching Docker container logs..."
if ! docker logs talawa-admin-app-container; then
echo "Error: Failed to fetch logs from container talawa-admin-app-container"
fi
fi
exit 1
fi
echo "App started successfully on port ${port}"

File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions .github/workflows/scripts/validate-coderabbit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

echo "Step 1: Fetching all PR reviews..."

response=$(curl -s -f -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews?per_page=1000") || {
echo "Error: Failed to fetch reviews from GitHub API"
exit 1
}

latest_reviews=$(echo "$response" | jq -c '[.[]] | group_by(.user.login) | map(max_by(.submitted_at))') || {
echo "Error: Failed to process reviews JSON"
exit 1
}

if [ "$latest_reviews" = "null" ] || [ -z "$latest_reviews" ]; then
echo "Error: Invalid reviews data"
exit 1
fi

echo "Step 2: Checking approval status of 'coderabbitai[bot]'..."
approval_state=$(echo "$latest_reviews" | jq -r '[.[] | select(.user.login == "coderabbitai[bot]" and .state == "APPROVED")] | length')

if [[ "$approval_state" =~ ^[0-9]+$ ]] && [[ $approval_state -gt 0 ]]; then
echo "Success: PR approved by CodeRabbit.ai."
else
echo ""
echo "ERROR:"
echo ""
echo "1) This PR is not approved by CodeRabbit.ai."
echo "2) In the 'Add a comment' section at the bottom"
echo " of the PR web page, add a comment with the"
echo " statement below to restart a review"
echo ""
echo "@coderabbitai full review"
exit 1
fi
Loading

0 comments on commit 9d5a993

Please sign in to comment.