Skip to content

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PurnenduMIshra129th committed Jan 2, 2025
2 parents b30e79d + 9a5a8c6 commit c5ad21f
Show file tree
Hide file tree
Showing 256 changed files with 17,554 additions and 1,355 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ dist

# Docusaurus cache and generated files
.docusaurus
docs/

# Serverless directories
.serverless/
Expand Down
103 changes: 94 additions & 9 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#
##############################################################################
##############################################################################

name: Pull request workflow
on:
pull_request:
branches:
- "**"

jobs:
check_base_branch:
# only run the job if the pull request actor is not dependabot
Expand All @@ -19,7 +26,9 @@ jobs:
name: Check base branch
run: |
echo "Pull requests are only allowed against the 'develop-postgres' branch. Please refer to the pull request guidelines."
echo "Error: Close this PR and try again."
exit 1
check_code_quality:
name: Checking code quality
runs-on: ubuntu-latest
Expand All @@ -30,6 +39,55 @@ jobs:
run: docker buildx build --file ./docker/api.Containerfile --tag talawa_api --target non_production ./
- name: Check type errors
run: docker container run talawa_api pnpm check_code_quality
- 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_eslint_disable:
name: Check for eslint-disable
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Run Python script
run: |
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
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Run Python script
run: |
python .github/workflows/scripts/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }}
check_gql_tada:
name: Check gql tada files and configuration
runs-on: ubuntu-latest
Expand All @@ -40,6 +98,7 @@ jobs:
run: docker buildx build --file ./docker/api.Containerfile --tag talawa_api --target non_production ./
- name: Check gql tada
run: docker container run talawa_api pnpm check_gql_tada

check_drizzle_migrations:
name: Check drizzle migration files
runs-on: ubuntu-latest
Expand All @@ -50,6 +109,7 @@ jobs:
run: docker buildx build --file ./docker/api.Containerfile --tag talawa_api --target non_production ./
- name: Check drizzle migrations
run: docker container run --env-file ./envFiles/.env.ci talawa_api pnpm check_drizzle_migrations

check_type_errors:
name: Check type errors
runs-on: ubuntu-latest
Expand All @@ -60,9 +120,10 @@ jobs:
run: docker buildx build --file ./docker/api.Containerfile --tag talawa_api --target non_production ./
- name: Check type errors
run: docker container run talawa_api pnpm check_type_errors
check_unauthorized_file_changes:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Check if there are unauthorized file changes

Check-Sensitive-Files:
if: ${{ github.actor != 'dependabot[bot]' && !contains(github.event.pull_request.labels.*.name, 'ignore-sensitive-files-pr') }}
name: Checks if sensitive files have been changed without authorization
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
Expand All @@ -80,6 +141,12 @@ jobs:
LICENSE
tsconfig.json
vitest.config.ts
pnpm-lock.yaml
package.json
.nojekyll
docs/docusaurus.config.ts
docs/sidebar*
CNAME
- env:
CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
if: steps.changed_files.outputs.any_changed == 'true' || steps.changed_files.outputs.any_deleted == 'true'
Expand All @@ -91,7 +158,8 @@ jobs:
done
echo "To override this, apply the 'ignore-sensitive-files-pr' label"
exit 1
run_tests:
Run-Tests:
name: Run tests for talawa api
runs-on: ubuntu-latest
steps:
Expand All @@ -103,8 +171,25 @@ jobs:
run: docker compose build
- name: Run tests
run: docker compose up --exit-code-from api
name: Pull request workflow
on:
pull_request:
branches:
- "**"

Test-Docusaurus-Deployment:
name: Test Deployment to https://docs-api.talawa.io
runs-on: ubuntu-latest
needs: [Run-Tests]
# Run only if the develop-postgres branch and not dependabot
if: ${{ github.actor != 'dependabot[bot]' && github.event.pull_request.base.ref == 'develop-postgres' }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
cache: pnpm
cache-dependency-path: |
docs/pnpm-lock.yaml
docs/package.json
# Run Docusaurus in the ./docs directory
- name: Install dependencies
working-directory: ./docs
run: pnpm install --frozen-lockfile
- name: Test building the website
working-directory: ./docs
run: pnpm build
64 changes: 64 additions & 0 deletions .github/workflows/push-deploy-website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
##############################################################################
##############################################################################
#
# NOTE!
#
# Please read the README.md file in this directory that defines what should
# be placed in this file
#
##############################################################################
##############################################################################

name: PUSH Workflow - Website Deployment

on:
push:
branches:
- "develop-postgres"

env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}

jobs:
Deploy-Docusaurus:
name: Deploy https://docs-api.talawa.io website
runs-on: ubuntu-latest
# Run only if the develop-postgres branch and not dependabot
if: ${{ github.actor != 'dependabot[bot]' }}
environment:
# This "name" has to be the repos' branch that contains
# the current active website. There must be an entry for
# the same branch in the PalisadoesFoundation's
# "Code and automation > Environments > github-pages"
# menu. The branch "name" must match the branch in the
# "on.push.branches" section at the top of this file
name: develop-postgres
url: https://docs-api.talawa.io
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/cache@v3
with:
path: docs/.docusaurus
key: docusaurus-${{ hashFiles('docs/**') }}
restore-keys: |
docusaurus-
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_GITHUB_PAGES }}
- name: Deploy to GitHub Pages
env:
USE_SSH: true
GIT_USER: git
working-directory: ./docs
run: |
git config --global user.email "[email protected]"
git config --global user.name "gh-actions"
if ! pnpm install --frozen-lockfile; then
echo "Failed to install dependencies"
exit 1
fi
if ! pnpm run deploy; then
echo "Deployment failed"
exit 1
fi
161 changes: 161 additions & 0 deletions .github/workflows/scripts/code_coverage_disable_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
"""Code Coverage Disable Checker Script.
Methodology:
Recursively analyzes TypeScript files in the specified directories or
checks specific files
to ensure they do not contain code coverage disable statements.
This script enforces proper code coverage practices in the project.
NOTE:
This script complies with our python3 coding and documentation standards.
It complies with:
1) Pylint
2) Pydocstyle
3) Pycodestyle
4) Flake8
5) Python Black
"""

import os
import re
import argparse
import sys


def has_code_coverage_disable(file_path):
"""
Check if a TypeScript file contains code coverage disable statements.
Args:
file_path (str): Path to the TypeScript file.
Returns:
bool: True if code coverage disable statement is found, False
otherwise.
"""
code_coverage_disable_pattern = re.compile(
r"""//?\s*istanbul\s+ignore(?:\s+(?:next|-line))?[^\n]*|
/\*\s*istanbul\s+ignore\s+(?:next|-line)\s*\*/""",
re.IGNORECASE,
)
try:
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
return bool(code_coverage_disable_pattern.search(content))
except FileNotFoundError:
print(f"File not found: {file_path}")
return False
except PermissionError:
print(f"Permission denied: {file_path}")
return False
except (IOError, OSError) as e:
print(f"Error reading file {file_path}: {e}")
return False


def check_code_coverage(files_or_dirs):
"""
Check TypeScript files for code coverage disable statements.
Args:
files_or_dirs (list): List of files or directories to check.
Returns:
bool: True if code coverage disable statement is found, False
otherwise.
"""
code_coverage_found = False

for item in files_or_dirs:
if os.path.isdir(item):
# If it's a directory, recursively walk through the files in it
for root, _, files in os.walk(item):
if "node_modules" in root:
continue
for file_name in files:
if (
file_name.endswith(".ts")
and not file_name.endswith(".test.ts")
and not file_name.endswith(".spec.ts")
):
file_path = os.path.join(root, file_name)
if has_code_coverage_disable(file_path):
print(
f"""File {file_path} contains code coverage disable statement."""
)
code_coverage_found = True
elif os.path.isfile(item):
# If it's a file, check it directly
if (
item.endswith(".ts")
and not item.endswith(".test.ts")
and not item.endswith(".spec.ts")
):
if has_code_coverage_disable(item):
print(
f"""File {item} contains code coverage disable statement. Please remove it and add the appropriate tests."""
)
code_coverage_found = True

return code_coverage_found


def arg_parser_resolver():
"""Resolve the CLI arguments provided by the user.
Returns:
result: Parsed argument object
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--directory",
type=str,
nargs="+",
default=[os.getcwd()],
help="""One or more directories to check for code coverage disable
statements (default: current directory).""",
)
parser.add_argument(
"--files",
type=str,
nargs="+",
default=[],
help="""One or more files to check directly for code coverage disable
statements (default: check directories).""",
)
return parser.parse_args()


def main():
"""
Execute the script's main functionality.
This function serves as the entry point for the script. It performs
the following tasks:
1. Validates and retrieves the files or directories to check from
command line arguments.
2. Checks files or directories for code coverage disable statements.
3. Provides informative messages based on the analysis.
4. Exits with an error if code coverage disable statements are found.
Raises:
SystemExit: If an error occurs during execution.
"""
args = arg_parser_resolver()
files_or_dirs = args.files if args.files else args.directory
# Check code coverage in the specified files or directories
code_coverage_found = check_code_coverage(files_or_dirs)

if code_coverage_found:
print("Code coverage disable check failed. Exiting with error.")
sys.exit(1)

print("Code coverage disable check completed successfully.")


if __name__ == "__main__":
main()
Loading

0 comments on commit c5ad21f

Please sign in to comment.