-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from wednesday-solutions/feat/ci-integration
Feat: integrating ci pipeline
- Loading branch information
Showing
18 changed files
with
590 additions
and
151 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Data Engineering CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- feat/* | ||
- fix/* | ||
|
||
jobs: | ||
run-ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.10.12 | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install mypy==1.7.1 pylint==3.0.2 pyspark==3.3.0 coverage | ||
- name: Type check | ||
run: mypy ./ --ignore-missing-imports | ||
|
||
- name: Lint | ||
run: pylint app/ main.py setup.py --output pylint-report.txt | ||
|
||
- name: Testing | ||
run: coverage run --source=app -m unittest discover -s app/tests/ | ||
|
||
- name: Test coverage report | ||
run: coverage xml | ||
|
||
- name: SonarQube Scan | ||
uses: sonarsource/sonarqube-scan-action@master | ||
with: | ||
args: > | ||
-Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | ||
|
||
- uses: sonarsource/sonarqube-quality-gate-action@master | ||
timeout-minutes: 5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
.env | ||
.env | ||
.coverage | ||
app/__pycache__ | ||
app/tests/__pycache__ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 22.3.0 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.5.0 | ||
hooks: | ||
- id: check-ast | ||
- id: trailing-whitespace | ||
- id: check-merge-conflict | ||
- id: debug-statements | ||
- id: detect-private-key | ||
- id: end-of-file-fixer | ||
|
||
- repo: local | ||
hooks: | ||
- id: mypy | ||
name: Type Checking | ||
entry: mypy ./ --ignore-missing-imports | ||
language: system | ||
always_run: true | ||
types: [python3] | ||
stages: [commit] | ||
|
||
- id: lint | ||
name: Linting | ||
entry: pylint app/ main.py setup.py | ||
language: system | ||
always_run: true | ||
types: [python3] | ||
stages: [commit] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[MASTER] | ||
disable=C0114,C0103,C0116,R0914,E0401,W0511,W0108,R0911,R0801,C0115 | ||
|
||
[FORMAT] | ||
max-line-length=150 | ||
max-module-lines=350 | ||
|
||
[SIMILARITIES] | ||
min-similarity-lines=4 |
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from app.connect_glue import init_glue | ||
|
||
|
||
class TestInitGlue(unittest.TestCase): | ||
@patch("app.connect_glue.SparkContext") | ||
@patch("app.connect_glue.GlueContext") | ||
@patch("app.connect_glue.Job") | ||
def test_init_glue(self, mock_job, mock_glue_context, mock_spark_context): | ||
# Mock the SparkContext, GlueContext, and Job | ||
mock_spark_context_instance = MagicMock() | ||
mock_glue_context_instance = MagicMock() | ||
mock_job_instance = MagicMock() | ||
|
||
# Set up the behavior of the mock instances | ||
mock_spark_context.return_value = mock_spark_context_instance | ||
mock_glue_context.return_value = mock_glue_context_instance | ||
mock_job.return_value = mock_job_instance | ||
|
||
# Call the function to test | ||
glue_context, spark, job = init_glue() | ||
|
||
# Assertions | ||
mock_spark_context.assert_called_once() | ||
mock_glue_context.assert_called_once_with(mock_spark_context_instance) | ||
mock_job.assert_called_once_with(mock_glue_context_instance) | ||
|
||
# Check if the returned values are correct | ||
self.assertEqual(glue_context, mock_glue_context_instance) | ||
self.assertEqual(spark, mock_glue_context_instance.spark_session) | ||
self.assertEqual(job, mock_job_instance) | ||
|
||
@patch("app.connect_glue.SparkContext") | ||
@patch("app.connect_glue.GlueContext") | ||
@patch("app.connect_glue.Job") | ||
def test_init_glue_failure(self, mock_job, mock_glue_context, mock_spark_context): | ||
# Simulate a ValueError during SparkContext initialization | ||
error_statement = "Simulated SparkContext initialization failure" | ||
mock_spark_context.side_effect = ValueError(error_statement) | ||
|
||
# Call the function to test | ||
with self.assertRaises(ValueError) as context: | ||
init_glue() | ||
|
||
# Assertions | ||
mock_spark_context.assert_called_once() | ||
mock_glue_context.assert_not_called() # GlueContext should not be called if SparkContext initialization fails | ||
mock_job.assert_not_called() # Job should not be called if SparkContext initialization fails | ||
|
||
# Check if the error displayed correctly | ||
self.assertEqual(str(context.exception), error_statement) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
stock_name,market,close_price,date | ||
ABC Corp,NYSE,100.25,2023-01-01 | ||
DEF Ltd,LSE,50.75,2023-01-01 | ||
XYZ Inc,NASDAQ,75.50,2023-01-01 | ||
ABC Corp,NYSE,95.20,2023-01-11 | ||
DEF Ltd,LSE,55.40,2023-01-11 | ||
XYZ Inc,NASDAQ,80.10,2023-01-11 | ||
ABC Corp,NYSE,105.80,2023-01-21 | ||
DEF Ltd,LSE,60.20,2023-01-21 | ||
XYZ Inc,NASDAQ,92.40,2023-01-21 | ||
ABC Corp,NYSE,110.50,2023-01-31 | ||
DEF Ltd,LSE,68.75,2023-01-31 | ||
XYZ Inc,NASDAQ,102.60,2023-01-31 | ||
ABC Corp,NYSE,115.75,2023-02-10 | ||
DEF Ltd,LSE,75.30,2023-02-10 | ||
XYZ Inc,NASDAQ,112.20,2023-02-10 |
Oops, something went wrong.