Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: standard formatting #1198

Merged
merged 12 commits into from
Feb 12, 2024
36 changes: 36 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Commitlint

on: [push]

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Setup Node
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Print versions
run: |
git --version
node --version
npm --version
npx commitlint --version

# Run the commitlint action, considering its own dependencies and yours as well 🚀
# `github.workspace` is the path to your repository.
- uses: wagoid/commitlint-github-action@v5
env:
NODE_PATH: ${{ github.workspace }}/node_modules
with:
commitDepth: 1
53 changes: 53 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Code quality checks

on:
pull_request:

jobs:
py-scripts-lint:
name: Check for formatting of python scripts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Setting up python libraries
run: ./scripts/setup-python.sh

# Reference: https://black.readthedocs.io/en/stable/integrations/github_actions.html
- name: Check formatting for Python files
uses: psf/black@stable
with:
options: '--check --verbose'

formatting-lint:
name: Check for formatting & lint errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/[email protected]

- name: Setup Node
uses: actions/[email protected]
with:
node-version-file: .nvmrc
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Lint Checks
run: |
npm run lint

- run: git diff --exit-code

- name: Error message
if: ${{ failure() }}
run: |
echo 'ESLint check is failing. Please run `npm run lint` on your working copy and commit the changes.'
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run pre-commit
npm run pre-commit
108 changes: 59 additions & 49 deletions migration/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,126 @@
import json
import os

DEST_WEBAPP_FILE_PATH = 'rudder-webapp/src/components/destinations/schemas/'
DEST_CONFIG_BE_FILE_PATH = 'rudder-config-backend/src/scripts/destinationConfigs/'
DEST_SCHEMA_FILE_PATH = 'rudder-config-backend/src/scripts/schemaList/destinations/'
DEST_WEBAPP_FILE_PATH = "rudder-webapp/src/components/destinations/schemas/"
DEST_CONFIG_BE_FILE_PATH = "rudder-config-backend/src/scripts/destinationConfigs/"
DEST_SCHEMA_FILE_PATH = "rudder-config-backend/src/scripts/schemaList/destinations/"

SOURCE_WEBAPP_FILE_PATH = 'rudder-webapp/src/components/sources/source/warehouseSource/warehouseSourceList/'
SOURCE_CONFIG_BE_FILE_PATH = 'rudder-config-backend/src/scripts/sourceConfigs/'
SOURCE_WEBAPP_FILE_PATH = (
"rudder-webapp/src/components/sources/source/warehouseSource/warehouseSourceList/"
)
SOURCE_CONFIG_BE_FILE_PATH = "rudder-config-backend/src/scripts/sourceConfigs/"
# SOURCE_SCHEMA_FILE_PATH = 'rudder-config-backend/src/scripts/schemaList/destinations/'

CONFIGURATIONS_DIR_PATH = '../src/configurations'
DEST_CONFIG_PATH = f'{CONFIGURATIONS_DIR_PATH}/destinations'
SRC_CONFIG_PATH = f'{CONFIGURATIONS_DIR_PATH}/sources'
CONFIGURATIONS_DIR_PATH = "../src/configurations"
DEST_CONFIG_PATH = f"{CONFIGURATIONS_DIR_PATH}/destinations"
SRC_CONFIG_PATH = f"{CONFIGURATIONS_DIR_PATH}/sources"


def update_destination():
dest_list = [d[:-5].lower() for d in os.listdir(f'../../{DEST_CONFIG_BE_FILE_PATH}')]
dest_list = [
d[:-5].lower() for d in os.listdir(f"../../{DEST_CONFIG_BE_FILE_PATH}")
]
for dest in dest_list:
final_data = []
# read db_config
with open(f'../../{DEST_CONFIG_BE_FILE_PATH}{dest.upper()}.json', 'r') as f:
with open(f"../../{DEST_CONFIG_BE_FILE_PATH}{dest.upper()}.json", "r") as f:
db_config = json.loads(f.read())
print (db_config)
print(db_config)
final_data.append(db_config)
print ("========================")
print("========================")
# read ui_config
with open(f'../../{DEST_WEBAPP_FILE_PATH}{dest.upper()}.json', 'r') as f:
with open(f"../../{DEST_WEBAPP_FILE_PATH}{dest.upper()}.json", "r") as f:
ui_config = {"uiConfig": json.loads(f.read())}
print (ui_config)
print(ui_config)
final_data.append(ui_config)
print ("========================")
print("========================")
# read schema
if f'{dest.upper()}.json' in os.listdir(f'../../{DEST_SCHEMA_FILE_PATH}'):
with open(f'../../{DEST_SCHEMA_FILE_PATH}{dest.upper()}.json', 'r') as f:
if f"{dest.upper()}.json" in os.listdir(f"../../{DEST_SCHEMA_FILE_PATH}"):
with open(f"../../{DEST_SCHEMA_FILE_PATH}{dest.upper()}.json", "r") as f:
schema = {"schema": json.loads(f.read())}
else:
schema = {"schema": None}
print (schema)
print(schema)
final_data.append(schema)
print ("========================")
print("========================")
# metadata
with open('dest_meta_template.json', 'r') as f:
with open("dest_meta_template.json", "r") as f:
metadata = json.loads(f.read())
print (metadata)
print(metadata)
final_data.append(metadata)
print ("========================")
print("========================")

########################
## write new files
########################
if dest not in os.listdir(DEST_CONFIG_PATH):
os.system(f'mkdir {DEST_CONFIG_PATH}/{dest}')
print (f'created directory for {dest}')
os.system(f"mkdir {DEST_CONFIG_PATH}/{dest}")
print(f"created directory for {dest}")

file_names = ['db-config', 'ui-config', 'schema', 'metadata']
file_names = ["db-config", "ui-config", "schema", "metadata"]
for index, f_name in enumerate(file_names):
print (f'writing {f_name} for {dest}...')
with open(f'{DEST_CONFIG_PATH}/{dest}/{f_name}.json', 'w') as f:
print(f"writing {f_name} for {dest}...")
with open(f"{DEST_CONFIG_PATH}/{dest}/{f_name}.json", "w") as f:
f.write(json.dumps(final_data[index], indent=2))

print (f'complete for {dest}...')
print ('------------------------------------------------')
print(f"complete for {dest}...")
print("------------------------------------------------")


def update_source():
source_list = [d[:-5].lower() for d in os.listdir(f'../../{SOURCE_CONFIG_BE_FILE_PATH}')]
source_list = [
d[:-5].lower() for d in os.listdir(f"../../{SOURCE_CONFIG_BE_FILE_PATH}")
]
for source in source_list:
final_data = []
# read db_config
with open(f'../../{SOURCE_CONFIG_BE_FILE_PATH}{source.upper()}.json', 'r') as f:
with open(f"../../{SOURCE_CONFIG_BE_FILE_PATH}{source.upper()}.json", "r") as f:
db_config = json.loads(f.read())
print (db_config)
print(db_config)
final_data.append(db_config)
print ("========================")
print("========================")
# read ui_config
if f'{source.upper()}.json' in os.listdir(f'../../{SOURCE_WEBAPP_FILE_PATH}'):
with open(f'../../{SOURCE_WEBAPP_FILE_PATH}{source.upper()}.json', 'r') as f:
if f"{source.upper()}.json" in os.listdir(f"../../{SOURCE_WEBAPP_FILE_PATH}"):
with open(
f"../../{SOURCE_WEBAPP_FILE_PATH}{source.upper()}.json", "r"
) as f:
ui_config = {"uiConfig": json.loads(f.read())}
else:
ui_config = {"uiConfig": None}
print (ui_config)
print(ui_config)
final_data.append(ui_config)
print ("========================")
print("========================")
# read schema (we don't need schema for sources)
# if f'{source.upper()}.json' in os.listdir(f'../../{SOURCE_SCHEMA_FILE_PATH}'):
# with open(f'../../{SOURCE_SCHEMA_FILE_PATH}{source.upper()}.json', 'r') as f:
# schema = {"schema": json.loads(f.read())}
# else:
schema = {"schema": None}
print (schema)
print(schema)
final_data.append(schema)
print ("========================")
print("========================")
# metadata
with open('source_meta_template.json', 'r') as f:
with open("source_meta_template.json", "r") as f:
metadata = json.loads(f.read())
print (metadata)
print(metadata)
final_data.append(metadata)
print ("========================")
print("========================")

########################
## write new files
########################
if source not in os.listdir(SRC_CONFIG_PATH):
os.system(f'mkdir {SRC_CONFIG_PATH}/{source}')
print (f'created directory for {source}')
os.system(f"mkdir {SRC_CONFIG_PATH}/{source}")
print(f"created directory for {source}")

file_names = ['db_config', 'ui_config', 'schema', 'metadata']
file_names = ["db_config", "ui_config", "schema", "metadata"]
for index, f_name in enumerate(file_names):
print (f'writing {f_name} for {source}...')
with open(f'{SRC_CONFIG_PATH}/{source}/{f_name}.json', 'w') as f:
print(f"writing {f_name} for {source}...")
with open(f"{SRC_CONFIG_PATH}/{source}/{f_name}.json", "w") as f:
f.write(json.dumps(final_data[index], indent=2))

print (f'complete for {source}...')
print ('------------------------------------------------')
print(f"complete for {source}...")
print("------------------------------------------------")


if __name__ == "__main__":
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
"test:silent": "npm run test -- --silent",
"release": "npx standard-version",
"check:lint": "eslint \"src/**/*.*\" -f json -o reports/eslint.json || exit 0",
"format:py": "python3 -m black .",
"format": "prettier . --write",
"lint:fix": "eslint \"src/**/*.*\" --fix",
"lint": "npm run format && npm run lint:fix",
"prepare": "husky install",
"pre-commit": "npm run test && npx lint-staged",
"commit-msg": "commitlint --edit",
Expand Down Expand Up @@ -79,7 +81,8 @@
"glob": "^9.3.2"
},
"lint-staged": {
"*.{json,js,ts,md}": "prettier --write"
"*.{json,js,ts,md}": "prettier --write",
"*.{py}": "python3 -m black"
},
"config": {
"commitizen": {
Expand Down
Loading
Loading