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

fix: formatting conventional commit messages and fix some pre-commit breakage #1935 #1978

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0

# Add 'root' label to any root file changes
# Quotation marks are required for the leading asterisk
root:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0

name: "Pull Request Labeler"

on:
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0

name: Python Checks

on: pull_request
Expand All @@ -11,9 +14,6 @@ jobs:
matrix:
python-version:
- "3.12"
defaults:
run:
working-directory: py

steps:
- uses: actions/checkout@v4
Expand All @@ -28,16 +28,19 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Format check
run: uv run ruff format --check .
run: uv run --directory py ruff format --check .

- name: Lint with ruff
run: uv run ruff check .
run: uv run --directory py ruff check .

- name: Check licenses
run: ./bin/check_license

- name: Run tests
run: ./bin/run_tests
run: ./py/bin/run_python_tests

- name: Build documentation
run: uv run mkdocs build --strict
run: uv run --directory py mkdocs build --strict

- name: Build distributions
run: ./bin/build_dists
run: ./py/bin/build_dists
8 changes: 8 additions & 0 deletions .hooks/conventional-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

cat "$1" | convco check --from-stdin
File renamed without changes.
45 changes: 45 additions & 0 deletions COMMIT_MESSAGE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
feat:

ISSUE:

CHANGELOG:
- []

## COMMIT MESSAGE FULL EXAMPLE
#
# feat(py/plugins/vertexai): Implement two-factor authentication
#
# This commit introduces two-factor authentication for enhanced security.
# It uses TOTP and requires users to configure an authenticator app.
#
# ISSUE: #123
#
# CHANGELOG:
# - [ ] Add support for two-factor authentication
# - [ ] Update user login endpoint to require two-factor authentication
#
# BREAKING CHANGE: The API endpoint for user login has been modified.

## CONVENTIONAL COMMIT TEMPLATE
#
# Subject line (required, max 50 characters, use imperative mood):
# <type>(<scope>): <short description>
# Example: feat(user-authentication): Implement two-factor authentication
#
# Body (optional, wrap at 72 characters, explain the change in more detail, mention why and what):
# <detailed description>

## TYPES OF CHANGE (choose one):
# - feat: A new feature
# - fix: A bug fix
# - docs: Documentation changes
# - style: Code style changes (formatting, etc.)
# - refactor: Code refactoring (no new features or bug fixes)
# - perf: Performance improvements
# - test: Adding or modifying tests
# - build: Changes that affect the build system or external dependencies
# - ci: Changes to CI configuration files and scripts
# - chore: Routine tasks, build process changes, etc.
# - revert: Revert a previous commit
#
## SCOPE (optional, specify the affected area, e.g., component, module):
47 changes: 47 additions & 0 deletions bin/add_license
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
#
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0
#
# Adds a license header to all files that don't already have it.

# set -x # Uncomment to enable tracing.
set -euo pipefail

TOP_DIR=$(git rev-parse --show-toplevel)

if ! command -v addlicense &>/dev/null; then
if ! command -v go &>/dev/null; then
echo "Please install go"
exit 1
fi
echo "Installing addlicense..."
go install github.com/google/addlicense@latest
fi

# NOTE: If you edit the ignore patterns, make sure to update the ignore patterns
# in the corresponding check_license script.
$HOME/go/bin/addlicense \
-c "Google LLC" \
-s=only \
-l apache \
-ignore '**/.dist/**/*' \
-ignore '**/.eggs/**/*' \
-ignore '**/.idea/**/*' \
-ignore '**/.mypy_cache/**/*' \
-ignore '**/.next/**/*' \
-ignore '**/.output/**/*' \
-ignore '**/.pytest_cache/**/*' \
-ignore '**/.ruff_cache/**/*' \
-ignore '**/.venv/**/*' \
-ignore '**/.wxt/**/*' \
-ignore '**/__pycache__/**/*' \
-ignore '**/bazel-*/**/*' \
-ignore '**/coverage/**/*' \
-ignore '**/develop-eggs/**/*' \
-ignore '**/dist/**/*' \
-ignore '**/node_modules/**/*' \
-ignore '**/pnpm-lock.yaml' \
-ignore '.nx/**/*' \
-ignore '.trunk/**/*' \
"$TOP_DIR"
File renamed without changes.
50 changes: 50 additions & 0 deletions bin/check_license
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0
#
# Checks that all files have a license header.

# set -x # Uncomment to enable tracing.
set -euo pipefail

TOP_DIR=$(git rev-parse --show-toplevel)

if ! command -v addlicense &>/dev/null; then
if ! command -v go &>/dev/null; then
echo "Please install go"
exit 1
fi
echo "Installing addlicense..."
go install github.com/google/addlicense@latest
fi

export PATH=$(go env GOPATH):$PATH

# NOTE: If you edit the ignore patterns, make sure to update the ignore patterns
# in the corresponding add_license script.
$HOME/go/bin/addlicense \
-check \
-c "Google LLC" \
-s=only \
-l apache \
-ignore '**/.dist/**/*' \
-ignore '**/.eggs/**/*' \
-ignore '**/.idea/**/*' \
-ignore '**/.mypy_cache/**/*' \
-ignore '**/.next/**/*' \
-ignore '**/.output/**/*' \
-ignore '**/.pytest_cache/**/*' \
-ignore '**/.ruff_cache/**/*' \
-ignore '**/.venv/**/*' \
-ignore '**/.wxt/**/*' \
-ignore '**/__pycache__/**/*' \
-ignore '**/bazel-*/**/*' \
-ignore '**/coverage/**/*' \
-ignore '**/develop-eggs/**/*' \
-ignore '**/dist/**/*' \
-ignore '**/node_modules/**/*' \
-ignore '**/pnpm-lock.yaml' \
-ignore '.nx/**/*' \
-ignore '.trunk/**/*' \
"$TOP_DIR"
32 changes: 14 additions & 18 deletions py/bin/fmt → bin/fmt
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,17 @@ fi

TOP_DIR=$(git rev-parse --show-toplevel)

addlicense \
-c "Google LLC" \
-s=only \
-ignore '**/.github/**/*' \
-ignore '**/.mypy_cache/**/*' \
-ignore '**/bazel-*/**/*' \
-ignore '**/docs/**/*' \
-ignore '**/node_modules/**/*' \
-ignore '**/pnpm-lock.yaml' \
"$TOP_DIR"
# Add license header to all files that don't already have it.
"${TOP_DIR}/bin/add_license"

# Format all TOML files.
"${TOP_DIR}/py/bin/format_toml_files"
"${TOP_DIR}/bin/format_toml_files"
if [[ $? -ne 0 ]]; then
exit 1
fi

# Format all Python code.
uvx ruff format "${TOP_DIR}/py"
uv run --directory "${TOP_DIR}/py" ruff format .
if [[ $? -ne 0 ]]; then
exit 1
fi
Expand All @@ -47,9 +39,13 @@ fi
popd

# Format all TypeScript code.
pushd ${TOP_DIR}
pnpm run format
if [[ $? -ne 0 ]]; then
exit 1
fi
popd
#
# TODO: Re-enable once we have biome configured and enabled because that is
# several times faster and compatible.
#
#pushd ${TOP_DIR}
#pnpm run format
#if [[ $? -ne 0 ]]; then
# exit 1
#fi
#popd
54 changes: 54 additions & 0 deletions bin/format_toml_files
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
#
# Format all TOML files in the project.
#
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

TOP_DIR=$(git rev-parse --show-toplevel)

if command -v taplo >/dev/null 2>&1; then
if [ ! -f "${TOP_DIR}/taplo.toml" ]; then
echo "error: config file not found at ${TOP_DIR}/taplo.toml"
exit 1
fi

FORMATTER_COMMAND="taplo format --config ${TOP_DIR}/taplo.toml"
if command -v rust-parallel >/dev/null 2>&1; then
FORMATTER_COMMAND="rust-parallel -j4 ${FORMATTER_COMMAND}"
else
echo "warning: it is recommended to install https://crates.io/crates/rust-parallel for faster formatting"
fi

pushd "${TOP_DIR}"
if command -v fd >/dev/null 2>&1; then
echo "Using fd"
fd -e toml \
--exclude '**/*.egg-info/**' \
--exclude '**/.dist/**' \
--exclude '**/.next/**' \
--exclude '**/.output/**' \
--exclude '**/.pytest_cache/**' \
--exclude '**/.venv/**' \
--exclude '**/__pycache__/**' \
--exclude '**/bazel-*/**' \
--exclude '**/build/**' \
--exclude '**/develop-eggs/**' \
--exclude '**/dist/**' \
--exclude '**/eggs/**' \
--exclude '**/node_modules/**' \
--exclude '**/sdist/**' \
--exclude '**/site/**' \
--exclude '**/target/**' \
--exclude '**/venv/**' \
--exclude '**/wheels/**' |
${FORMATTER_COMMAND}
else
echo "Please install https://github.com/sharkdp/fd to find files to format."
fi
popd
else
echo "Please install https://github.com/tamasfe/taplo to format TOML files."
fi
Loading
Loading