Skip to content

Connection Charts Page & Testing > 95% Frontend Coverage [GSOC 2025] #554

Connection Charts Page & Testing > 95% Frontend Coverage [GSOC 2025]

Connection Charts Page & Testing > 95% Frontend Coverage [GSOC 2025] #554

Workflow file for this run

##############################################################################
##############################################################################
#
# PR Workflow
#
##############################################################################
##############################################################################
name: PR Workflow
on:
pull_request:
branches:
- "**"
env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}
DATABASE_NAME: switchmap_unittest
DATABASE_USERNAME: switchmap_unittest
DATABASE_PASSWORD: switchmap_unittest
MYSQL_ROOT_USERNAME: root
MYSQL_ROOT_PASSWORD: root
jobs:
Code-Quality-Checks:
name: Performs linting, formatting, type-checking, checking for different source and target branch
runs-on: ubuntu-latest
steps:
- name: Checkout the Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- 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
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black pydocstyle flake8-docstrings
- name: Run Black Formatter Check
run: |
black --check .
- name: Run Flake8 Linter
run: |
flake8 --docstring-convention google switchmap bin setup tests .github --ignore E402,E722,E203,F401,W503
- name: Run pydocstyle
run: |
pydocstyle switchmap setup bin tests --convention=google --add-ignore=D415,D205
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 code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Changed Unauthorized files
id: changed-unauth-files
run: |
# Define the list of sensitive files/patterns:
SENSITIVE_FILES=(
CODE_OF_CONDUCT.md
CODE_STYLE.md
CONTRIBUTING.md
DOCUMENTATION.md
INSTALLATION.md
ISSUE_GUIDELINES.md
PR_GUIDELINES.md
README.md
.coderabbit.yaml
docs/CNAME
docs/static/CNAME
docs/package.json
docs/sidebar*.js
docs/docusaurus.config.js
docs/babel.config.js
docs/tsconfig.json
.gitignore
CODEOWNERS
LICENSE
.pydocstyle
pyproject.toml
.flake8
requirements.txt
CNAME
yaml.lock
package.json
package-lock.json
.pre-commit-config.yaml
)
# Get changed/added/modified/renamed files and deleted files
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
DELETED_FILES=$(git diff --name-only --diff-filter=D ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
SENSITIVE_CHANGED=false
ALL_CHANGED_FILES=""
# Check if any file in the diff matches our sensitive patterns
for PATTERN in "${SENSITIVE_FILES[@]}"; do
for FILE in $CHANGED_FILES $DELETED_FILES; do
if [[ "$FILE" == "$PATTERN" || "$FILE" =~ $PATTERN ]]; then
ALL_CHANGED_FILES+="$FILE "
SENSITIVE_CHANGED=true
fi
done
done
# Send outputs to GitHub Actions
echo "all_changed_files=$ALL_CHANGED_FILES" >> $GITHUB_OUTPUT
echo "any_changed=$SENSITIVE_CHANGED" >> $GITHUB_OUTPUT
echo "any_deleted=$([ -n "$DELETED_FILES" ] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
- name: List all changed unauthorized files
if: steps.changed-unauth-files.outputs.any_changed == 'true' || steps.changed-unauth-files.outputs.any_deleted == 'true'
env:
CHANGED_UNAUTH_FILES: ${{ steps.changed-unauth-files.outputs.all_changed_files }}
run: |
for file in ${CHANGED_UNAUTH_FILES}; do
echo "$file is unauthorized to change/delete"
done
echo "To override this, apply the 'ignore-sensitive-files-pr' label"
exit 1
Count-Changed-Files:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Checks if number of files changed is acceptable
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
# Use multiline token syntax to safely output file names
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
CHANGED_FILES_COUNT=$(echo "$CHANGED_FILES" | wc -l)
echo "changed_files_count=$CHANGED_FILES_COUNT" >> $GITHUB_OUTPUT
- name: Echo number of changed files
run: |
echo "Number of changed files: ${{ steps.changed-files.outputs.changed_files_count }}"
- name: Check if the number of changed files is less than 10000
if: ${{ steps.changed-files.outputs.changed_files_count > 10000 }}
run: |
echo "Error: Too many files (greater than 10000) changed in the pull request."
echo "Possible issues:"
echo "- Contributor may be merging into an incorrect branch."
echo "- Source branch may be incorrect. Please use develop as the source branch."
exit 1
Test-Application:
name: Test Application
needs: [Code-Quality-Checks, Docstring-Compliance]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: 3.11
- name: Updated Ubuntu package sources
run: sudo apt-get -y update
- name: Install Ubuntu packages
run: sudo apt-get install -y python3 python3-pip snmp libsnmp-dev gcc python-dev-is-python3 python3-venv mysql-server
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies and test
run: |
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip3 install -r requirements.txt
pip install pytest-cov coverage
tests/bin/error_code_report.py
tests/bin/test_db_config_setup.py
sudo systemctl start mysql.service
sudo mysql -u${{ env.MYSQL_ROOT_USERNAME }} -p${{ env.MYSQL_ROOT_PASSWORD }} -e "CREATE DATABASE ${{ env.DATABASE_NAME }};"
sudo mysql -u${{ env.MYSQL_ROOT_USERNAME }} -p${{ env.MYSQL_ROOT_PASSWORD }} -e "CREATE USER '${{ env.DATABASE_USERNAME }}'@'localhost' IDENTIFIED BY '${{ env.DATABASE_PASSWORD }}';"
sudo mysql -u${{ env.MYSQL_ROOT_USERNAME }} -p${{ env.MYSQL_ROOT_PASSWORD }} -e "GRANT ALL PRIVILEGES ON ${{ env.DATABASE_NAME }}.* TO '${{ env.DATABASE_USERNAME }}'@'localhost';"
sudo mysql -u${{ env.MYSQL_ROOT_USERNAME }} -p${{ env.MYSQL_ROOT_PASSWORD }} -e "FLUSH PRIVILEGES;"
pytest --cov=switchmap --cov-report=lcov:coverage/coverage.lcov --cov-report=term-missing tests/switchmap_
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: PalisadoesFoundation/switchmap-ng
verbose: true
files: ./coverage/coverage.lcov
gcov_ignore: "docs/"
fail_ci_if_error: false
name: "${{ env.CODECOV_UNIQUE_NAME }}"
- name: Test acceptable level of code coverage
uses: VeryGoodOpenSource/very_good_coverage@v3
with:
path: ./coverage/coverage.lcov
min_coverage: 0.0
Test-Frontend:
name: Test Frontend and Coverage
runs-on: ubuntu-latest
needs: [Code-Quality-Checks] # or [Test-Application] if you want backend ready
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Cache node modules
uses: actions/cache@v4
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install frontend dependencies
working-directory: frontend
run: npm install
- name: Run frontend tests with coverage
working-directory: frontend
run: npm run test -- --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: frontend/coverage/lcov.info
fail_ci_if_error: true
verbose: true
- name: Test acceptable level of code coverage
uses: VeryGoodOpenSource/very_good_coverage@v3
with:
path: frontend/coverage/lcov.info
min_coverage: 80.0
Test-Docusaurus-Deployment:
name: Test Deployment to https://docs-legacy.switchmap-ng.io
runs-on: ubuntu-latest
needs: [Test-Application]
if: ${{ github.actor != 'dependabot[bot]' && github.event.pull_request.base.ref == 'develop' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: yarn
cache-dependency-path: "docs/"
- name: Install dependencies
working-directory: ./docs
run: yarn install --frozen-lockfile
- name: Test building the website
working-directory: ./docs
run: yarn build
Check-Target-Branch:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Check Target Branch
runs-on: ubuntu-latest
steps:
- name: Check if the target branch is develop
if: ${{ github.event.pull_request.base.ref != 'develop' }}
run: |
echo "Error: Pull request target branch must be 'develop' not ${{ github.event.pull_request.base.ref }}. 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: [Code-Quality-Checks, Test-Application]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- 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 }}
Docstring-Compliance:
name: Check Docstring Compliance
runs-on: ubuntu-latest
needs: [Code-Quality-Checks]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install docstring_parser
- name: Run docstring compliance check
run: |
source venv/bin/activate
python .github/workflows/scripts/check_docstrings.py --directories switchmap setup bin tests .github