Skip to content

Commit

Permalink
Added changes
Browse files Browse the repository at this point in the history
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
  • Loading branch information
NishantSinghhhhh committed Feb 27, 2025
2 parents 355789b + d38e6a8 commit 86ce9f5
Show file tree
Hide file tree
Showing 62 changed files with 7,529 additions and 1,864 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Add the PR Review Policy
uses: thollander/actions-comment-pull-request@v3
with:
comment_tag: pr_review_policy
comment-tag: pr_review_policy
message: |
## Our Pull Request Approval Process
Expand Down
33 changes: 12 additions & 21 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
echo "Error: Close this PR and try again."
exit 1
check_biome_ignore:
name: Check for biome_ignore
python_checks:
name: Run Python Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -64,30 +64,19 @@ jobs:
with:
python-version: 3.9

- name: Run Python script
- name: Run Biome Ignore Check
run: |
python .github/workflows/scripts/biome_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
- name: Run Code Coverage Disable Check
run: |
python .github/workflows/scripts/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }}
- name: Run TS Ignore Check
run: |
python .github/workflows/scripts/detect_ts_ignore.py --files ${{ steps.changed-files.outputs.all_changed_files }}
check_gql_tada:
name: Check gql tada files and configuration
runs-on: ubuntu-latest
Expand Down Expand Up @@ -167,6 +156,8 @@ jobs:
docs/docusaurus.config.ts
docs/sidebar*
setup.ts
src/graphql/types/Mutation/**
src/graphql/types/Query/**
tsconfig.build.json
vite.config.mts
CNAME
Expand All @@ -193,7 +184,7 @@ jobs:
Run-Tests:
name: Run tests for talawa api
runs-on: ubuntu-latest
needs: [Code-Quality-Checks, check_code_coverage_disable]
needs: [Code-Quality-Checks, python_checks]
env:
CODECOV_UNIQUE_NAME: ${{github.workflow}}-${{github.ref_name}}
steps:
Expand Down Expand Up @@ -221,7 +212,7 @@ jobs:
uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: "./coverage/lcov.info"
min_coverage: 45.0
min_coverage: 48.6

Test-Docusaurus-Deployment:
name: Test Deployment to https://docs-api.talawa.io
Expand Down
134 changes: 134 additions & 0 deletions .github/workflows/scripts/detect_ts_ignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env python3
"""Script to detect and report usage of @ts-ignore comments in TypeScript."""

import argparse
import re
import sys
import logging
import os

# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(levelname)s: %(message)s",
)

TS_IGNORE_PATTERN = r"(?://|/\*)\s*@ts-ignore(?:\s+|$)"

IGNORED_EXTENSIONS = {
# Image formats
".avif",
".jpeg",
".jpg",
".png",
".webp",
".gif",
".bmp",
".ico",
".svg",
# Video formats
".mp4",
".webm",
".mov",
".avi",
".mkv",
# Audio formats
".mp3",
".wav",
".ogg",
# Document formats
".pdf",
".doc",
".docx",
}


def is_binary_file(filepath: str) -> bool:
"""Check if a file is binary based on its extension.
Args:
filepath (str): The file path.
Returns:
bool: True if the file should be ignored, False otherwise.
"""
return os.path.splitext(filepath)[1].lower() in IGNORED_EXTENSIONS


def check_ts_ignore(files: list[str]) -> int:
"""Check for occurrences of '@ts-ignore' in the given files.
Args:
files (list[str]): List of file paths to check.
Returns:
int: 0 if no violations, 1 if violations are found.
"""
ts_ignore_found = False

for file in files:
if not is_binary_file(file):
try:
logging.info("Checking file: %s", file)
with open(file, encoding="utf-8") as f:
for line_num, line in enumerate(f, start=1):
# Handle more variations of @ts-ignore
if re.search(
TS_IGNORE_PATTERN,
line.strip(),
):
print(
f"❌ Error: '@ts-ignore' found in {file} ",
f"at line {line_num}",
)
logging.debug(
"Found @ts-ignore in line: %s",
line.strip(),
)
ts_ignore_found = True
except FileNotFoundError:
logging.warning("File not found: %s", file)
except OSError:
logging.exception("Could not read %s", file)
if not ts_ignore_found:
print("✅ No '@ts-ignore' comments found in the files.")

return 1 if ts_ignore_found else 0


def main() -> None:
"""Main function to parse arguments and run the check.
This function sets up argument parsing for file paths and runs the ts-ignore
check on the specified files.
Args:
None
Returns:
None: The function exits the program with status code 0 if no ts-ignore
comments are found, or 1 if any are detected.
"""
parser = argparse.ArgumentParser(
description="Check for @ts-ignore in changed files.",
)
parser.add_argument(
"--files",
nargs="+",
help="List of changed files",
required=True,
)
args = parser.parse_args()

# Filter TypeScript files
ts_files = [f for f in args.files if f.endswith((".ts", ".tsx"))]
if not ts_files:
logging.info("No TypeScript files to check.")
sys.exit(0)

exit_code = check_ts_ignore(args.files)
sys.exit(exit_code)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
close-pr-message: 'This pull request did not get any activity in the past 180 days and thus has been closed.'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
days-before-stale: 10
days-before-stale: 7
days-before-close: 180
remove-stale-when-updated: true
exempt-all-milestones: true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/.env-*
/.env_*

# Ignore the deploy compose file
/compose.deploy.yaml

# Ignore upload directories
cert/**
certs/**
Expand Down
13 changes: 10 additions & 3 deletions docker/api.Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ RUN groupmod -n talawa vscode \
&& touch /commandhistory/.bash_history \
&& chown -R talawa /commandhistory \
&& echo "export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" >> /home/talawa/.bashrc
# Create a global profile script that both login and non-interactive shells load
RUN echo '#!/bin/sh' > /etc/profile.d/fnm.sh \
&& echo 'export PATH="/home/talawa/.local/share/fnm:$PATH"' >> /etc/profile.d/fnm.sh \
&& echo 'eval "$(fnm env --corepack-enabled --resolve-engines --use-on-cd --version-file-strategy=recursive)"' >> /etc/profile.d/fnm.sh \
&& chmod +x /etc/profile.d/fnm.sh
# Ensure non-interactive bash sessions load the script
ENV BASH_ENV=/etc/profile.d/fnm.sh
# Also, have the talawa login shell source it explicitly by appending to its .bashrc
RUN echo "source /etc/profile.d/fnm.sh" >> /home/talawa/.bashrc
USER talawa
# Installs fnm.
RUN curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell \
# Appends the fnm configuration to `/home/talawa/.bashrc` file.
&& echo eval \"\$\(fnm env --corepack-enabled --resolve-engines --use-on-cd --version-file-strategy=recursive\)\" >> /home/talawa/.bashrc
RUN curl -fsSL --proto '=https' --tlsv1.2 https://fnm.vercel.app/install | bash -s -- --skip-shell
ENV PATH=/home/talawa/.local/share/fnm:${PATH}
WORKDIR /home/talawa/api

Expand Down
Loading

0 comments on commit 86ce9f5

Please sign in to comment.