Skip to content

Commit 2344882

Browse files
committed
chore: adds ci/cd related infra content
1 parent 377d042 commit 2344882

File tree

10 files changed

+376
-0
lines changed

10 files changed

+376
-0
lines changed

.github/.OwlBot.lock.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
docker:
15+
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16+
digest: sha256:3b3a31be60853477bc39ed8d9bac162cac3ba083724cecaad54eb81d4e4dae9c
17+
# created: 2025-04-16T22:40:03.123475241Z

.github/.OwlBot.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
docker:
16+
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
17+
18+
deep-remove-regex:
19+
- /owl-bot-staging
20+
21+
begin-after-commit-hash: f2de93abafa306b2ebadf1d10d947db8bcf2bf15
22+

.github/CODEOWNERS

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Code owners file.
2+
# This file controls who is tagged for review for any given pull request.
3+
#
4+
# For syntax help see:
5+
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax
6+
7+
# The @googleapis/api-bigquery is the default owner for changes in this repo
8+
* @googleapis/api-bigquery @googleapis/yoshi-python
9+
10+
# The python-samples-reviewers team is the default owner for samples changes
11+
/samples/ @googleapis/api-bigquery @googleapis/python-samples-owners @googleapis/yoshi-python

.github/CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# How to Contribute
2+
3+
We'd love to accept your patches and contributions to this project. There are
4+
just a few small guidelines you need to follow.
5+
6+
## Contributor License Agreement
7+
8+
Contributions to this project must be accompanied by a Contributor License
9+
Agreement. You (or your employer) retain the copyright to your contribution;
10+
this simply gives us permission to use and redistribute your contributions as
11+
part of the project. Head over to <https://cla.developers.google.com/> to see
12+
your current agreements on file or to sign a new one.
13+
14+
You generally only need to submit a CLA once, so if you've already submitted one
15+
(even if it was for a different project), you probably don't need to do it
16+
again.
17+
18+
## Code reviews
19+
20+
All submissions, including submissions by project members, require review. We
21+
use GitHub pull requests for this purpose. Consult
22+
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23+
information on using pull requests.
24+
25+
## Community Guidelines
26+
27+
This project follows [Google's Open Source Community
28+
Guidelines](https://opensource.google.com/conduct/).

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
2+
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
3+
- [ ] Ensure the tests and linter pass
4+
- [ ] Code coverage does not decrease (if any source code was changed)
5+
- [ ] Appropriate docs were updated (if necessary)
6+
7+
Fixes #<issue_number_goes_here> 🦕

.github/release-please.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
releaseType: python
2+
handleGHRelease: true
3+
# NOTE: this section is generated by synthtool.languages.python
4+
# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py
5+
branches:
6+
- branch: v2
7+
handleGHRelease: true
8+
releaseType: python
9+
- branch: v1
10+
handleGHRelease: true
11+
releaseType: python
12+
- branch: v0
13+
handleGHRelease: true
14+
releaseType: python

.github/release-trigger.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
enabled: true
2+
multiScmName: python-bigquery

.github/workflows/lint.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
# Trigger workflow on GitHub merge queue events
6+
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group
7+
merge_group:
8+
types: [checks_requested]
9+
name: lint
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
# Use a fetch-depth of 2 to avoid error `fatal: origin/main...HEAD: no merge base`
21+
# See https://github.com/googleapis/google-cloud-python/issues/12013
22+
# and https://github.com/actions/checkout#checkout-head.
23+
with:
24+
fetch-depth: 2
25+
- name: Setup Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.13"
29+
- name: Install nox
30+
run: |
31+
python -m pip install --upgrade setuptools pip wheel
32+
python -m pip install nox
33+
- name: Run lint
34+
env:
35+
BUILD_TYPE: presubmit
36+
TEST_TYPE: lint
37+
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
38+
PY_VERSION: "unused"
39+
run: |
40+
ci/run_conditional_tests.sh
41+
- name: Run lint_setup_py
42+
env:
43+
BUILD_TYPE: presubmit
44+
TEST_TYPE: lint_setup_py
45+
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
46+
PY_VERSION: "unused"
47+
run: |
48+
ci/run_conditional_tests.sh

ci/run_conditional_tests.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# This script requires the following environment variables to be set:
17+
# `BUILD_TYPE` should be one of ["presubmit", "continuous"]
18+
# `TEST_TYPE` should be one of ["docs", "docfx", "prerelease", "unit"]
19+
# or match the name of the nox session that you want to run.
20+
# `PY_VERSION` should be one of ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
21+
22+
# `TEST_TYPE` and `PY_VERSION` are required by the script `ci/run_single_test.sh`
23+
24+
# This script will determine which directories have changed
25+
# under the `packages` folder. For `BUILD_TYPE=="presubmit"`,
26+
# we'll compare against the `packages` folder in HEAD,
27+
# whereas for `BUILD_TYPE=="continuous"` we'll compare changes
28+
# with HEAD~1. For all directories that have changed files, we will
29+
# run the script located at `${PROJECT_ROOT}/ci/run_single_test.sh`.
30+
31+
# `-e` enables the script to automatically fail when a command fails
32+
# `-o pipefail` sets the exit code to non-zero if any command fails,
33+
# or zero if all commands in the pipeline exit successfully.
34+
set -eo pipefail
35+
36+
export PROJECT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/..)
37+
38+
# A script file for running the test in a sub project.
39+
test_script="${PROJECT_ROOT}/ci/run_single_test.sh"
40+
41+
if [ ${BUILD_TYPE} == "presubmit" ]; then
42+
# For presubmit build, we want to know the difference from the
43+
# common commit in origin/main.
44+
GIT_DIFF_ARG="origin/main..."
45+
46+
# Then fetch enough history for finding the common commit.
47+
git fetch origin main --deepen=200
48+
49+
elif [ ${BUILD_TYPE} == "continuous" ]; then
50+
# For continuous build, we want to know the difference in the last
51+
# commit. This assumes we use squash commit when merging PRs.
52+
GIT_DIFF_ARG="HEAD~.."
53+
54+
# Then fetch one last commit for getting the diff.
55+
git fetch origin main --deepen=1
56+
57+
else
58+
# Run everything.
59+
GIT_DIFF_ARG=""
60+
fi
61+
62+
# Then detect changes in the test scripts.
63+
64+
set +e
65+
git diff --quiet ${GIT_DIFF_ARG} ci
66+
changed=$?
67+
set -e
68+
69+
# Now we have a fixed list, but we can change it to autodetect if
70+
# necessary.
71+
72+
subdirs=(
73+
packages
74+
)
75+
76+
RETVAL=0
77+
78+
for subdir in ${subdirs[@]}; do
79+
for d in `ls -d ${subdir}/*/`; do
80+
should_test=false
81+
if [ -n "${GIT_DIFF_ARG}" ]; then
82+
echo "checking changes with 'git diff --quiet ${GIT_DIFF_ARG} ${d}'"
83+
set +e
84+
git diff --quiet ${GIT_DIFF_ARG} ${d}
85+
changed=$?
86+
set -e
87+
if [[ "${changed}" -eq 0 ]]; then
88+
echo "no change detected in ${d}, skipping"
89+
else
90+
echo "change detected in ${d}"
91+
should_test=true
92+
fi
93+
else
94+
# If GIT_DIFF_ARG is empty, run all the tests.
95+
should_test=true
96+
fi
97+
if [ "${should_test}" = true ]; then
98+
echo "running test in ${d}"
99+
pushd ${d}
100+
# Temporarily allow failure.
101+
set +e
102+
${test_script}
103+
ret=$?
104+
set -e
105+
if [ ${ret} -ne 0 ]; then
106+
RETVAL=${ret}
107+
fi
108+
popd
109+
fi
110+
done
111+
done
112+
113+
exit ${RETVAL}

ci/run_single_test.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2022 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script requires the following environment variables to be set:
18+
# `TEST_TYPE` should be one of ["lint", "lint_setup_py", "docs", "docfx", "prerelease"]
19+
# `PY_VERSION` should be one of ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
20+
21+
# This script is called by the `ci/run_conditional_tests.sh` script.
22+
# A specific `nox` session will be run, depending on the value of
23+
# `TEST_TYPE` and `PY_VERSION`. For example, if `TEST_TYPE` is
24+
# `lint`, the `nox -s lint` session will be run.
25+
26+
27+
set -e
28+
29+
if [ -z "${TEST_TYPE}" ]; then
30+
echo "missing TEST_TYPE env var"
31+
exit 1
32+
fi
33+
34+
if [ -z "${PY_VERSION}" ]; then
35+
echo "missing PY_VERSION env var"
36+
exit 1
37+
fi
38+
39+
# Don't fail on errors so we can capture all of the output
40+
set +e
41+
42+
case ${TEST_TYPE} in
43+
docs)
44+
nox -s docs
45+
# This line needs to be directly after `nox -s docs` in order
46+
# for the failure to appear in Github presubmits
47+
retval=$?
48+
# Clean up built docs and python cache after the build process to avoid
49+
# `[Errno 28] No space left on device`
50+
# See https://github.com/googleapis/google-cloud-python/issues/12271
51+
rm -rf docs/_build
52+
;;
53+
docfx)
54+
nox -s docfx
55+
# This line needs to be directly after `nox -s docfx` in order
56+
# for the failure to appear in Github presubmits
57+
retval=$?
58+
# Clean up built docs and python cache after the build process to avoid
59+
# `[Errno 28] No space left on device`
60+
# See https://github.com/googleapis/google-cloud-python/issues/12271
61+
rm -rf docs/_build
62+
;;
63+
prerelease)
64+
nox -s prerelease_deps-3.13
65+
retval=$?
66+
;;
67+
unit)
68+
case ${PY_VERSION} in
69+
"3.7")
70+
nox -s unit-3.7
71+
retval=$?
72+
;;
73+
"3.8")
74+
nox -s unit-3.8
75+
retval=$?
76+
;;
77+
"3.9")
78+
nox -s unit-3.9
79+
retval=$?
80+
;;
81+
"3.10")
82+
nox -s unit-3.10
83+
retval=$?
84+
;;
85+
"3.11")
86+
nox -s unit-3.11
87+
retval=$?
88+
;;
89+
"3.12")
90+
nox -s unit-3.12
91+
retval=$?
92+
;;
93+
"3.13")
94+
nox -s unit-3.13
95+
retval=$?
96+
;;
97+
*)
98+
echo "unsupported PY_VERSION"
99+
exit 1
100+
;;
101+
esac
102+
;;
103+
*)
104+
nox -s ${TEST_TYPE}
105+
retval=$?
106+
;;
107+
esac
108+
109+
# Clean up `__pycache__` and `.nox` directories to avoid error
110+
# `No space left on device` seen when running tests in Github Actions
111+
find . | grep -E "(__pycache__)" | xargs rm -rf
112+
rm -rf .nox
113+
114+
exit ${retval}

0 commit comments

Comments
 (0)