Skip to content

Commit

Permalink
Merge branch 'develop-postgres' into added-add.module.css-check-pytho…
Browse files Browse the repository at this point in the history
…n-script
  • Loading branch information
IITI-tushar authored Jan 6, 2025
2 parents adab723 + c8a1290 commit 4ea8e30
Show file tree
Hide file tree
Showing 153 changed files with 7,966 additions and 4,231 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/merge-conflict-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Merge Conflict Check Workflow

on:
pull_request:
branches:
- '**'
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
Merge-Conflict-Check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check Mergeable Status via Github API
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
max_retries=3
retry_delay=5
for ((i=1; i<=max_retries; i++)); do
echo "Attempt $i of $max_retries"
if ! response=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" --jq '.mergeable'); then
if [[ $response == *"rate limit exceeded"* ]]; then
echo "Rate limit exceeded. Waiting before retry..."
sleep 60 # Wait longer for rate limit
else
echo "Failed to call GitHub API: $response"
if [ $i -eq $max_retries ]; then
echo "Maximum retries reached. Exiting."
exit 1
fi
sleep $retry_delay
fi
continue
fi
case "$response" in
"true")
echo "No conflicts detected."
exit 0
;;
"false")
echo "Merge conflicts detected."
exit 1
;;
*)
echo "Mergeable status unknown: $response"
if [ $i -eq $max_retries ]; then
echo "Maximum retries reached. Exiting."
exit 1
fi
sleep $retry_delay
;;
esac
done
93 changes: 40 additions & 53 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ 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
# Run the CSS import check script
- name: Check for CSS violations and print correct imports
run: |
chmod +x ./.github/workflows/css_check.py
./.github/workflows/css_check.py --directory .
- name: Get changed TypeScript files
- name: Get changed TypeScript files
id: changed-files
uses: tj-actions/changed-files@v45
- name: Check formatting
Expand Down Expand Up @@ -77,15 +77,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 @@ -102,6 +103,8 @@ jobs:
with:
files: |
.env*
vitest.config.js
src/App.tsx
.github/**
env.example
.node-version
Expand All @@ -117,7 +120,6 @@ jobs:
.eslintignore
.prettierrc
.prettierignore
.nojekyll
vite.config.ts
docker-compose.yaml
Dockerfile
Expand All @@ -139,6 +141,11 @@ jobs:
*.password
*.secret
*.credentials
.nojekyll
yarn.lock
docs/docusaurus.config.ts
docs/sidebar*
CNAME
- name: List all changed unauthorized files
if: steps.changed-unauth-files.outputs.any_changed == 'true' || steps.changed-unauth-files.outputs.any_deleted == 'true'
Expand Down Expand Up @@ -198,7 +205,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 @@ -218,7 +225,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 @@ -341,20 +348,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 @@ -366,20 +361,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 @@ -415,22 +398,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 @@ -467,4 +436,22 @@ 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
Validate-Coderabbit:
name: Validate CodeRabbit Approval
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Test-Docusaurus-Deployment]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Validate CodeRabbit.ai Approval
run: |
chmod +x $GITHUB_WORKSPACE/.github/workflows/scripts/validate-coderabbit.sh
$GITHUB_WORKSPACE/.github/workflows/scripts/validate-coderabbit.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_REPOSITORY: ${{ github.repository }}
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.
38 changes: 38 additions & 0 deletions .github/workflows/scripts/validate-coderabbit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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"
echo ""
exit 1
fi
5 changes: 2 additions & 3 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ name: Mark stale issues and pull requests

on:
schedule:
- cron: "0 0 * * *"
- cron: "0 * * * *"

permissions:
issues: write
pull-requests: write

jobs:
stale:

name: Process Stale Issues and PRs
runs-on: ubuntu-latest

steps:
- uses: actions/stale@v9
with:
Expand Down
Empty file added 3141
Empty file.
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/.github/ @palisadoes
CODEOWNERS @palisadoes
# CODEOWNERS @palisadoes
Loading

0 comments on commit 4ea8e30

Please sign in to comment.