GitHub Action to Test Basic DB Access and Updates #5909
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
############################################################################## | |
# | |
# NOTE! | |
# | |
# Please read the README.md file in this directory that defines what should | |
# be placed in this file. | |
# | |
############################################################################## | |
############################################################################## | |
name: Pull request workflow | |
on: | |
pull_request: | |
branches: | |
- "**" | |
jobs: | |
check_base_branch: | |
# only run the job if the pull request actor is not dependabot | |
if: ${{ github.actor != 'dependabot[bot]' }} | |
name: Check base branch of the pull request to be develop-postgres | |
runs-on: ubuntu-latest | |
steps: | |
- if: github.event.pull_request.base.ref != 'develop-postgres' | |
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 | |
Code-Quality-Checks: | |
name: Checking code quality | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout this repository | |
uses: actions/checkout@v4.2.2 | |
- name: Build talawa api non production environment docker image | |
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_biome_ignore: | |
name: Check for biome_ignore | |
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/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 | |
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 | |
steps: | |
- name: Checkout this repository | |
uses: actions/checkout@v4.2.2 | |
- name: Build talawa api non production environment docker image | |
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 | |
steps: | |
- name: Checkout this repository | |
uses: actions/checkout@v4.2.2 | |
- name: Build talawa api non production environment docker image | |
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 | |
steps: | |
- name: Checkout this repository | |
uses: actions/checkout@v4.2.2 | |
- name: Build talawa api non production environment docker image | |
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-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 | |
needs: [Code-Quality-Checks] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout this repository | |
uses: actions/checkout@v4.2.2 | |
- id: changed_files | |
name: Get changed files | |
uses: tj-actions/changed-files@v45.0.4 | |
with: | |
files: | | |
.coderabbit.yaml | |
Caddyfile | |
codegen.ts | |
Dockerfile* | |
docker-compose* | |
drizzle_migrations/** | |
.dockerignore | |
.env.sample | |
.env_test | |
eslint.config.mjs | |
envFiles/** | |
.gitignore | |
init-mongo.sh | |
.prettierignore | |
.prettierrc.json | |
.pylintrc | |
.github/** | |
biome.jsonc | |
drizzle_migrations/** | |
renovate.json | |
requirements.txt | |
schema.graphql | |
CODEOWNERS | |
LICENSE | |
tsconfig.json | |
vitest.config.ts | |
pnpm-lock.yaml | |
package.json | |
package-lock.json | |
.nojekyll | |
docs/docusaurus.config.ts | |
docs/sidebar* | |
setup.ts | |
tsconfig.build.json | |
vite.config.mts | |
CNAME | |
CODE_OF_CONDUCT.md | |
CODE_STYLE.md | |
CONTRIBUTING.md | |
DOCUMENTATION.md | |
INSTALLATION.md | |
ISSUE_GUIDELINES.md | |
PR_GUIDELINES.md | |
README.md | |
- 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' | |
name: Show changed files | |
run: | | |
echo "Unauthorized changes were made in the following files:" | |
for FILE in ${CHANGED_FILES}; do | |
echo "$FILE" | |
done | |
echo "To override this, apply the 'ignore-sensitive-files-pr' label" | |
exit 1 | |
Run-Tests: | |
name: Run tests for talawa api | |
runs-on: ubuntu-latest | |
needs: [Code-Quality-Checks, check_code_coverage_disable] | |
env: | |
CODECOV_UNIQUE_NAME: ${{github.workflow}}-${{github.ref_name}} | |
steps: | |
- name: Checkout this repository | |
uses: actions/checkout@v4.2.2 | |
- name: Create .env file for talawa api testing environment | |
run: cp ./envFiles/.env.ci ./.env | |
- name: Build talawa api compose testing environment | |
run: docker compose build | |
- name: Run tests | |
run: docker compose up --exit-code-from api | |
- name: Copy coverage from container | |
run: | | |
CONTAINER_ID=$(docker ps -aq --filter "ancestor=talawa-api") | |
docker cp $CONTAINER_ID:/home/talawa/api/coverage ./coverage | |
- name: Present and upload coverage to Codecov as ${{env.CODECOV_UNIQUE_NAME}} | |
uses: codecov/codecov-action@v4 | |
with: | |
verbose: true | |
token: ${{ secrets.CODECOV_TOKEN }} | |
fail_ci_if_error: false | |
name: "${{env.CODECOV_UNIQUE_NAME}}" | |
- name: Test acceptable level of code coverage | |
uses: VeryGoodOpenSource/very_good_coverage@v2 | |
with: | |
path: "./coverage/lcov.info" | |
min_coverage: 45.0 | |
Sample-Data-Check: | |
name: Checking database connection and access | |
runs-on: ubuntu-latest | |
needs: [Run-Tests] | |
steps: | |
- name: Checkout this repository | |
uses: actions/checkout@v4.2.2 | |
- name: Create .env file for talawa api testing environment | |
run: cp ./envFiles/.env.ci ./.env | |
- name: Building Talawa API | |
run: docker compose build | |
- name: Run Container | |
run: docker compose up -d | |
- name: Adding tables to testing environment | |
run: docker compose exec api pnpm apply_drizzle_test_migrations | |
- name: Validate Database Records | |
run: docker compose exec api pnpm add:sample_data | |
- name: Stop Services | |
run: docker compose down | |
Test-Docusaurus-Deployment: | |
name: Test Deployment to https://docs-api.talawa.io | |
runs-on: ubuntu-latest | |
needs: [Run-Tests, Sample-Data-Check] | |
# 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 | |
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/workflows/scripts/validate-coderabbit.sh | |
.github/workflows/scripts/validate-coderabbit.sh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PR_NUMBER: ${{ github.event.pull_request.number }} | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
Python-Compliance: | |
name: Check Python Code Style | |
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 -r .github/workflows/requirements.txt | |
- name: Run Black Formatter Check | |
run: | | |
source venv/bin/activate | |
black --check . | |
- name: Run Flake8 Linter | |
run: | | |
source venv/bin/activate | |
flake8 --docstring-convention google --ignore E402,E722,E203,F401,W503 .github | |
- name: Run pydocstyle | |
run: | | |
source venv/bin/activate | |
pydocstyle --convention=google --add-ignore=D415,D205 .github | |
- name: Run docstring compliance check | |
run: | | |
source venv/bin/activate | |
python .github/workflows/scripts/check_docstrings.py --directories .github | |
# Import-Sample-Data: | |
# name: Import Sample Data | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout this repository | |
# uses: actions/checkout@v4.2.2 | |
# - name: Create .env file for talawa api testing environment | |
# run: cp ./envFiles/.env.ci ./.env | |
# - name: Build talawa api non production environment docker image | |
# run: docker compose build | |
# - name: Run import:sample-data | |
# uses: addnab/docker-run-action@v3 | |
# with: | |
# image: talawa_api | |
# options: --env-file ./envFiles/.env.ci | |
# run: pnpm run import:sample-data |