Skip to content

Commit

Permalink
chore(build): update copyright headers and pre-commit hook #1736
Browse files Browse the repository at this point in the history
Issue: #1736

The copyright headers in Python files have been updated to include SPDX license
identifier and change "Google Inc." to "Google LLC". Additionally, simplified
the pre-commit hook command for branch protection.

CHANGELOG:
- chore: update copyright header to use "Google LLC" instead of "Google Inc."
- chore: add SPDX-License-Identifier to copyright headers
- build: simplify no-commits-on-branches pre-commit hook command by removing 'py' argument
- feat: add check licenses script for later use
- chore: remove spurious .projectile file that would cause emacs to tighten scope
- refactor: move PATH environment variable handling into its own
  function
- feat: add govulncheck to check for known vulnerabilities in
  dependencies
- feat: add cleanup temp files script
  • Loading branch information
yesudeep committed Jan 31, 2025
1 parent d2c0617 commit 59ba5dc
Show file tree
Hide file tree
Showing 41 changed files with 488 additions and 51 deletions.
16 changes: 16 additions & 0 deletions go/samples/cloud_run_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
#!/bin/sh
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0


# This script deploys a sample to Cloud Run.
# Run it from this directory (go/samples).
Expand Down
16 changes: 16 additions & 0 deletions go/samples/cloud_run_request.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
#!/bin/sh
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0


# This script makes a request to a sample application deployed
# to cloud run.
Expand Down
16 changes: 16 additions & 0 deletions go/samples/pgvector/pgvector.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
-- Copyright 2025 Google LLC
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- SPDX-License-Identifier: Apache-2.0

-- This SQL enables the vector extension and creates the table and data used
-- in the accompanying sample.

Expand Down
18 changes: 18 additions & 0 deletions js/testapps/next/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

:root {
--background: #ffffff;
--foreground: #171717;
Expand Down
18 changes: 18 additions & 0 deletions js/testapps/next/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';
import './globals.css';
Expand Down
18 changes: 18 additions & 0 deletions js/testapps/next/src/app/page.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

.title {
display: flex;
gap: 10px;
Expand Down
18 changes: 18 additions & 0 deletions js/testapps/next/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

'use client';

import { tellJoke } from '@/genkit/joke';
Expand Down
Empty file removed py/.projectile
Empty file.
9 changes: 9 additions & 0 deletions py/bin/check-licenses
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail

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

pushd "${TOP_DIR}/go"
go-licenses check ./... --disallowed_types=restricted,forbidden,reciprocal,unknown
popd
10 changes: 10 additions & 0 deletions py/bin/cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -x
set -euo pipefail

function genkit::cleanup() {
rm -rf /tmp/e2e* || true && rm -rf /tmp/test-cli* || true
}

genkit::cleanup
11 changes: 11 additions & 0 deletions py/bin/fmt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ fi

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

addlicense \
-c "Google LLC" \
-s \
-ignore '**/.github/**/*' \
-ignore '**/.mypy_cache/**/*' \
-ignore '**/bazel-*/**/*' \
-ignore '**/docs/**/*' \
-ignore '**/node_modules/**/*' \
-ignore '**/pnpm-lock.yaml' \
"$TOP_DIR"

# Format all TOML files.
"${TOP_DIR}/py/bin/format_toml_files"
if [[ $? -ne 0 ]]; then
Expand Down
93 changes: 60 additions & 33 deletions py/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ fi

OS_NAME=$(uname)

PYTHON_CLI_TOOLS=(
"httpie" # HTTP client. See: https://httpie.io/
"mypy" # Static type checker. See: https://mypy.readthedocs.io/en/stable/
"ruff" # Fast linter. See: https://github.com/astral-sh/ruff
)

# Updates your shell profile to include a path.
function genkit::update_path() {
local new_path="$1"
Expand Down Expand Up @@ -77,8 +83,19 @@ function genkit::update_path() {
fi
}

function genkit::preconfigure_environment() {
git clean -Xfd
genkit::update_path "$HOME/.cargo/bin"
genkit::update_path "$HOME/.local/bin"
genkit::update_path "$HOME/.local/share/pnpm"
genkit::update_path "$HOME/go/bin"
genkit::update_path "$HOME/google-cloud-sdk/bin"
}

# Install all the required tools common to all audiences.
function genkit::install_prerequisites() {
genkit::preconfigure_environment

if [[ ${OS_NAME} == "Darwin" && -x "$(command -v brew)" ]]; then
# Darwin-based systems.
brew install \
Expand Down Expand Up @@ -109,20 +126,21 @@ function genkit::install_prerequisites() {

# Install rust.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
~/.cargo/bin/rustup update
rustup update

# Install uv for Python versioning, packaging, and workspace management.
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install pnpm for JavaScript package management.
# See: https://github.com/pnpm/pnpm/issues/6217
curl -fsSL https://get.pnpm.io/install.sh | env ENV="$HOME/.bashrc" SHELL="$(which bash)" PNPM_VERSION=10.0.0 bash -

genkit::update_path "$HOME/.cargo/bin"
genkit::update_path "$HOME/.local/share/pnpm"
genkit::update_path "$HOME/go/bin"
curl -fsSL https://get.pnpm.io/install.sh |
env ENV="$HOME/.bashrc" \
SHELL="$(which bash)" \
PNPM_VERSION=10.0.0 \
bash -
}

# Install the Google Cloud SDK.
function genkit::install_google_cloud_sdk() {
# This depends on Python 3.11 and installs it for the user on some systems.
if command -v gcloud &>/dev/null; then
Expand All @@ -135,30 +153,14 @@ function genkit::install_google_cloud_sdk() {
gcloud config set disable_usage_reporting true
}

# Install all the required tools for CI.
function genkit::install_ci_packages() {
genkit::install_prerequisites
genkit::install_python_cli_tools
genkit::install_go_cli_tools
genkit::install_docs_cli_tools
}

# Install all the required tools for engineering.
function genkit::install_eng_packages() {
genkit::install_prerequisites
genkit::install_go_cli_tools
genkit::install_cargo_cli_tools
genkit::install_python_cli_tools
genkit::install_docs_cli_tools
genkit::install_google_cloud_sdk
genkit::install_pnpm_cli_tools
genkit::install_pre_commit_hooks
}

# Install all the required tools that have been written in Go.
function genkit::install_go_cli_tools() {
go install github.com/Gelio/go-global-update@latest
go install github.com/captainhook-go/captainhook/cmd/captainhook@latest
go install github.com/google/addlicense@latest
go install github.com/google/go-licenses@latest
go install github.com/jesseduffield/lazygit@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
}

# Install all the required tools that have been written in Rust. We're assuming
Expand All @@ -178,12 +180,6 @@ function genkit::install_pnpm_cli_tools() {
pnpm add -g genkit-cli
}

PYTHON_CLI_TOOLS=(
"httpie" # HTTP client. See: https://httpie.io/
"mypy" # Static type checker. See: https://mypy.readthedocs.io/en/stable/
"ruff" # Fast linter. See: https://github.com/astral-sh/ruff
)

# Install all the Python-related formatter and static analysis tools.
function genkit::install_python_cli_tools() {
for package in "${PYTHON_CLI_TOOLS[@]}"; do
Expand All @@ -208,7 +204,38 @@ function genkit::install_docs_cli_tools() {

# Install pre-commit hooks.
function genkit::install_pre_commit_hooks() {
~/go/bin/captainhook install -f -c ${TOP_DIR}/py/captainhook.json
captainhook install -f -c "${TOP_DIR}/py/captainhook.json"
}

# Setup genkit.
function genkit::setup_genkit() {
pushd "${TOP_DIR}"
pnpm i
pnpm run setup
popd
}

# Install all the common packages.
function genkit::install_common_packages() {
genkit::install_prerequisites
genkit::install_go_cli_tools
genkit::install_cargo_cli_tools
genkit::install_python_cli_tools
genkit::install_docs_cli_tools
genkit::install_pnpm_cli_tools
}

# Install all the required tools for CI.
function genkit::install_ci_packages() {
genkit::install_common_packages
}

# Install all the required tools for engineering.
function genkit::install_eng_packages() {
genkit::install_common_packages
genkit::install_google_cloud_sdk
genkit::install_pre_commit_hooks
genkit::setup_genkit
}

# Entry point for the setup script.
Expand Down
Loading

0 comments on commit 59ba5dc

Please sign in to comment.