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

add initial precommit workflows #150

Merged

Conversation

Abhishekbhagwat
Copy link
Collaborator

No description provided.

@Abhishekbhagwat
Copy link
Collaborator Author

@code-review-assist review

Copy link

@code-review-assist code-review-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request adds pre-commit workflows for linting and link checking. This is a great addition and will help maintain code quality and consistency. The chosen linters are appropriate for the project's languages. A few suggestions for improvement are below.

#############################
on:
push:
branches-ignore: [main]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider linting against the main branch instead of ignoring it. This ensures any changes are compatible with the main branch before merging, preventing integration issues.

Suggested change
branches-ignore: [main]
branches: [main]

env:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER_REGEX_EXCLUDE: 'gemini/sample-apps/finance-advisor-spanner/.*\.sql'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The FILTER_REGEX_EXCLUDE setting could be documented with a comment explaining its purpose and the files it excludes. This improves clarity and maintainability.

Suggested change
FILTER_REGEX_EXCLUDE: 'gemini/sample-apps/finance-advisor-spanner/.*\.sql'
# Exclude specific files from linting, e.g., SQL files in a specific directory.
FILTER_REGEX_EXCLUDE: 'gemini/sample-apps/finance-advisor-spanner/.*\\.sql'

Comment on lines 60 to 65
VALIDATE_PYTHON_ISORT: false
VALIDATE_CHECKOV: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_TYPESCRIPT_STANDARD: false
VALIDATE_GITHUB_ACTIONS: false
VALIDATE_YAML_PRETTIER: false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Consider enabling VALIDATE_PYTHON_ISORT, VALIDATE_GITHUB_ACTIONS, and VALIDATE_YAML_PRETTIER for better code style consistency and catching potential issues in GitHub Actions and YAML files. While disabling some linters might be necessary for specific reasons, ensure these decisions are documented for clarity.

Suggested change
VALIDATE_PYTHON_ISORT: false
VALIDATE_CHECKOV: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_TYPESCRIPT_STANDARD: false
VALIDATE_GITHUB_ACTIONS: false
VALIDATE_YAML_PRETTIER: false
VALIDATE_PYTHON_ISORT: true
VALIDATE_GITHUB_ACTIONS: true
VALIDATE_YAML_PRETTIER: true
VALIDATE_CHECKOV: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_TYPESCRIPT_STANDARD: false

on:
pull_request:
branches: [main]
push:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the linter workflow, consider changing this to lint against the main branch to catch issues before merging.

Suggested change
push:
branches: [main]

else
# If running in a push
while read -r file || [ -n "$line" ]; do
notebooks+=("$file")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The comparison HEAD^1 might not be reliable in all cases (e.g., merged commits). Consider using origin/main... (or your default branch) to compare against the main branch, ensuring consistent behavior across different scenarios.

Suggested change
notebooks+=("$file")
done < <(git diff --name-only origin/main... | grep '\\.ipynb$')

python3 -m tensorflow_docs.tools.nbfmt --test "$notebook"
NBFMT_RTN=$?
echo "Running flake8..."
python3 -m nbqa flake8 "$notebook" --show-source --extend-ignore=W391,E501,F821,E402,F404,F704,W503,E203,E722,W293,W291,I100

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Consider adding more specific error codes to extend-ignore to provide more granular control over which flake8 errors are ignored. Documenting the reasons for ignoring specific errors can enhance maintainability.

Suggested change
python3 -m nbqa flake8 "$notebook" --show-source --extend-ignore=W391,E501,F821,E402,F404,F704,W503,E203,E722,W293,W291,I100
python3 -m nbqa flake8 "$notebook" --show-source --extend-ignore=W391,E501,F821,E402,F404,F704,W503,E203,E722,W293,W291,I100 # Ignoring specific flake8 errors, add reasons here.

Copy link
Collaborator

@RajeshThallam RajeshThallam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RajeshThallam RajeshThallam merged commit 59f5fe4 into GoogleCloudPlatform:main Dec 19, 2024
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants