Skip to content

Commit af7b656

Browse files
committed
adds unittest.yml
1 parent c656ee9 commit af7b656

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

.github/workflows/unittest.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- autogen
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: unittest
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
unit:
16+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
17+
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
18+
# https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
19+
runs-on: ubuntu-22.04
20+
strategy:
21+
matrix:
22+
python: ['3.9', '3.10', "3.11", "3.12", "3.13"]
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
# Use a fetch-depth of 2 to avoid error `fatal: origin/main...HEAD: no merge base`
27+
# See https://github.com/googleapis/google-cloud-python/issues/12013
28+
# and https://github.com/actions/checkout#checkout-head.
29+
with:
30+
fetch-depth: 2
31+
- name: Setup Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: ${{ matrix.python }}
35+
- name: Install nox
36+
run: |
37+
python -m pip install --upgrade setuptools pip wheel
38+
python -m pip install nox
39+
- name: Run unit tests
40+
env:
41+
COVERAGE_FILE: .coverage-${{ matrix.python }}
42+
BUILD_TYPE: presubmit
43+
TEST_TYPE: unit
44+
PY_VERSION: ${{ matrix.python }}
45+
run: |
46+
nox -s unit-${{ matrix.python }}
47+
- name: Upload coverage results
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: coverage-artifact-${{ '{{' }} matrix.python {{ '}}' }}
51+
path: .coverage-${{ matrix.python }}
52+
unit-extended:
53+
name: ${{ matrix.option }}
54+
runs-on: ubuntu-latest
55+
strategy:
56+
matrix:
57+
python: ["3.13"]
58+
option: ["prerelease_deps"]
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v4
62+
# Use a fetch-depth of 2 to avoid error `fatal: origin/main...HEAD: no merge base`
63+
# See https://github.com/googleapis/google-cloud-python/issues/12013
64+
# and https://github.com/actions/checkout#checkout-head.
65+
with:
66+
fetch-depth: 2
67+
- name: Setup Python
68+
uses: actions/setup-python@v5
69+
with:
70+
python-version: ${{ matrix.python }}
71+
- name: Install nox
72+
run: |
73+
python -m pip install --upgrade setuptools pip wheel
74+
python -m pip install nox
75+
- name: Run ${{ matrix.option }} tests
76+
env:
77+
BUILD_TYPE: presubmit
78+
TEST_TYPE: ${{ matrix.option }}
79+
# 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.
80+
PY_VERSION: "unused"
81+
run: |
82+
nox -s unit-${{ matrix.option }}-${{ matrix.python }}
83+
84+
cover:
85+
runs-on: ubuntu-latest
86+
needs:
87+
- unit
88+
steps:
89+
- name: Checkout
90+
uses: actions/checkout@v4
91+
# Use a fetch-depth of 2 to avoid error `fatal: origin/main...HEAD: no merge base`
92+
# See https://github.com/googleapis/google-cloud-python/issues/12013
93+
# and https://github.com/actions/checkout#checkout-head.
94+
with:
95+
fetch-depth: 2
96+
- name: Setup Python
97+
uses: actions/setup-python@v5
98+
with:
99+
python-version: "3.10"
100+
- name: Set number of files changes in packages directory
101+
id: packages
102+
run: echo "::set-output name=num_files_changed::$(git diff HEAD~1 -- packages | wc -l)"
103+
- name: Install coverage
104+
if: steps.packages.num_files_changed > 0
105+
run: |
106+
python -m pip install --upgrade setuptools pip wheel
107+
python -m pip install coverage
108+
- name: Download coverage results
109+
if: ${{ steps.date.packages.num_files_changed > 0 }}
110+
uses: actions/download-artifact@v4
111+
with:
112+
path: .coverage-results/
113+
- name: Report coverage results
114+
if: ${{ steps.date.packages.num_files_changed > 0 }}
115+
run: |
116+
find .coverage-results -type f -name '*.zip' -exec unzip {} \;
117+
coverage combine .coverage-results/**/.coverage*
118+
coverage report --show-missing --fail-under=100

0 commit comments

Comments
 (0)