Skip to content

Commit

Permalink
Added linting and pytests (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadam14 authored Jan 21, 2025
1 parent 01f8101 commit cf6fb99
Show file tree
Hide file tree
Showing 60 changed files with 302,023 additions and 4,274 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
92 changes: 92 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '16 17 * * 5'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: python
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
31 changes: 31 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Coverage

on:
workflow_run:
workflows: ["Tests"]
types:
- completed

jobs:
coverage:
name: Run tests & display coverage
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write
# Gives the action the necessary permissions for looking up the
# workflow that launched this workflow, and download the related
# artifact that contains the comment to be published
actions: read
steps:
- name: Post comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
verbose: true
43 changes: 43 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Linters

on:
pull_request:
push:
branches:
- "main"

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install --only linters --no-root
- name: Run black
run: |
poetry run black --check .
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install --only linters --no-root
- name: Run ruff
run: |
poetry run ruff check .
47 changes: 47 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on:
pull_request:
push:
branches:
- "main"

jobs:
unit-tests:
runs-on: ubuntu-latest
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for pushing data to the
# python-coverage-comment-action branch, and for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install --no-root
- name: Launch tests & generate report
run: poetry run pytest
- name: Coverage comment
id: coverage_comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
verbose: true
- name: Store Pull Request comment to be posted
uses: actions/upload-artifact@v4
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
name: python-coverage-comment-action
# If you use a different name, update COMMENT_FILENAME accordingly
path: python-coverage-comment-action.txt
4 changes: 2 additions & 2 deletions validation_aws/Job_Dockerfile → Job_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ WORKDIR /usr/app

COPY pyproject.toml .
COPY poetry.lock .
COPY src/ ./src/
COPY src/sbl_validation_processor/*.py ./src/sbl_validation_processor/

RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
RUN poetry install --only main,processors

ARG JOB_PATH=""
ENV JOB_PATH=${JOB_PATH}
Expand Down
4 changes: 2 additions & 2 deletions validation_aws/Lambda_Dockerfile → Lambda_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ WORKDIR ${LAMBDA_TASK_ROOT}

COPY ./pyproject.toml ${LAMBDA_TASK_ROOT}
COPY ./poetry.lock ${LAMBDA_TASK_ROOT}
COPY ./src ./src
COPY src/sbl_validation_processor/*.py ./src/sbl_validation_processor/

RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
RUN poetry install --only main,processors

ARG LAMBDA_PATH

Expand Down
2 changes: 1 addition & 1 deletion validation_aws/Local_Dockerfile → Local_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY poetry.lock .
COPY src/ ./src/

RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
RUN poetry install --no-dev --with local --with processors

COPY local_watchdog/local_file_watcher.py .

Expand Down
3 changes: 1 addition & 2 deletions validation_aws/SQS_Dockerfile → SQS_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ WORKDIR /usr/app

COPY pyproject.toml .
COPY poetry.lock .
COPY src/ ./src/

RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
RUN poetry install --only main,eks --no-root

ARG SQS_PATH=""
ENV SQS_PATH=${SQS_PATH}
Expand Down
File renamed without changes.
39 changes: 21 additions & 18 deletions validation_aws/do_sqs.sh → do_sqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ then
docker run -d --platform linux/amd64 --network sbl-project_default -v /tmp/filing_bucket/upload/:/tmp/filing_bucket/upload/ -e ENV=LOCAL -e DB_NAME=filing -e DB_USER=filing_user -e DB_PWD=filing_user -e DB_HOST=pg --name local_validation_run local_validation_run:latest
docker container ls
else
docker build --platform linux/amd64 -t sqs-parquet:latest -f SQS_Dockerfile --build-arg SQS_PATH=sqs_csv_to_parquet .
docker build --platform linux/amd64 -t sqs-validate:latest -f SQS_Dockerfile --build-arg SQS_PATH=sqs_parquet_validation .
docker build --platform linux/amd64 -t sqs-aggregator:latest -f SQS_Dockerfile --build-arg SQS_PATH=sqs_validation_aggregator .
docker build --platform linux/amd64 -t sqs-parquet-job:latest -f Job_Dockerfile --build-arg JOB_PATH=sqs_csv_to_parquet .
docker build --platform linux/amd64 -t sqs-validator-job:latest -f Job_Dockerfile --build-arg JOB_PATH=sqs_parquet_validation .
docker build --platform linux/amd64 -t sqs-aggregator-job:latest -f Job_Dockerfile --build-arg JOB_PATH=sqs_validation_aggregator .
docker tag sqs-parquet:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet:latest
docker tag sqs-parquet-job:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet-job:latest
docker tag sqs-validate:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validate:latest
docker tag sqs-validator-job:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validator-job:latest
docker tag sqs-aggregator:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator:latest
docker tag sqs-aggregator-job:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator-job:latest
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet:latest
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet-job:latest
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validate:latest
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validator-job:latest
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator:latest
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator-job:latest
docker build --platform linux/amd64 -t sqs-parquet:latest -f SQS_Dockerfile --build-arg SQS_PATH=src/sbl_validation_processor/sqs_csv_to_parquet .
docker build --platform linux/amd64 -t sqs-validate:latest -f SQS_Dockerfile --build-arg SQS_PATH=src/sbl_validation_processor/sqs_parquet_validation .
docker build --platform linux/amd64 -t sqs-aggregator:latest -f SQS_Dockerfile --build-arg SQS_PATH=src/sbl_validation_processor/sqs_validation_aggregator .
docker build --platform linux/amd64 -t sqs-parquet-job:latest -f Job_Dockerfile --build-arg JOB_PATH=src/sbl_validation_processor/sqs_csv_to_parquet .
docker build --platform linux/amd64 -t sqs-validator-job:latest -f Job_Dockerfile --build-arg JOB_PATH=src/sbl_validation_processor/sqs_parquet_validation .
docker build --platform linux/amd64 -t sqs-aggregator-job:latest -f Job_Dockerfile --build-arg JOB_PATH=src/sbl_validation_processor/sqs_validation_aggregator .
docker tag sqs-parquet:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet:latest.2
docker tag sqs-parquet-job:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet-job:latest.2
docker tag sqs-validate:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validate:latest.2
docker tag sqs-validator-job:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validator-job:latest.2
docker tag sqs-aggregator:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator:latest.2
docker tag sqs-aggregator-job:latest 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator-job:latest.2
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet:latest.2
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-parquet-job:latest.2
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validate:latest.2
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-validator-job:latest.2
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator:latest.2
docker push 099248080076.dkr.ecr.us-east-1.amazonaws.com/cfpb/regtech/sqs-aggregator-job:latest.2
kubectl rollout restart deployment -n regtech sqs-csv-poller
kubectl rollout restart deployment -n regtech sqs-pqs-poller
kubectl rollout restart deployment -n regtech sqs-res-poller
fi

Loading

0 comments on commit cf6fb99

Please sign in to comment.