Skip to content

Commit 915e550

Browse files
committed
Refactor action to add resuable build workflow
1 parent bb4e5dc commit 915e550

File tree

2 files changed

+82
-162
lines changed

2 files changed

+82
-162
lines changed

.github/workflows/build.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build and validate package
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target_path:
7+
description: "The path of the package or service to build"
8+
required: true
9+
type: string
10+
run_test:
11+
description: "Run lint and test"
12+
required: true
13+
type: boolean
14+
15+
jobs:
16+
build_package:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
python-version: [ 3.8, 3.9, "3.10", "3.11" ]
21+
steps:
22+
- name: Set up python ${{ matrix.python-version }}
23+
id: setup-python
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
#----------------------------------------------
28+
# ----- install & configure poetry -----
29+
#----------------------------------------------
30+
- name: Install Poetry
31+
uses: snok/install-poetry@v1
32+
with:
33+
virtualenvs-create: true
34+
virtualenvs-in-project: true
35+
installer-parallel: true
36+
37+
#----------------------------------------------
38+
# load cached venv if cache exists
39+
#----------------------------------------------
40+
- name: Load cached venv
41+
id: cached-poetry-dependencies
42+
uses: actions/cache@v2
43+
with:
44+
path: .venv
45+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }}
46+
#----------------------------------------------
47+
# install dependencies if cache does not exist
48+
#----------------------------------------------
49+
- name: Install dependencies
50+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
51+
run: poetry install --no-interaction --no-root
52+
working-directory: ${{ github.workspace }}/${{ github.event.inputs.target_path }}
53+
54+
#----------------------------------------------
55+
# install your root project, if required
56+
#----------------------------------------------
57+
- name: Install library
58+
run: poetry install --no-interaction
59+
working-directory: ${{ github.event.inputs.target_path }}
60+
61+
- name: Check-linting
62+
if: ${{ inputs.run_test }}
63+
run: poetry run black --check src
64+
working-directory: ${{ github.event.inputs.target_path }}
65+
66+
- name: Run unit test
67+
if: ${{ inputs.run_test }}
68+
run: poetry run python -m pytest tests/unit
69+
working-directory: ${{ github.event.inputs.target_path }}
70+
71+
# - name: Check types
72+
# if: ${{ inputs.run_test }}
73+
# run: |
74+
# mkdir .mypy_cache # Workaround for bad error message "error: --install-types failed (no mypy cache directory)"; see https://github.com/python/mypy/issues/10768#issuecomment-2178450153
75+
# poetry run mypy --install-types --non-interactive src
76+
# working-directory: ${{ github.event.inputs.target_path }}

.github/workflows/code-quality-checks.yml

+6-162
Original file line numberDiff line numberDiff line change
@@ -7,173 +7,17 @@ on:
77
branches:
88
- PECO-1803/connector-split
99
jobs:
10-
run-unit-tests:
10+
validate-connector-core:
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
python-version: [3.8, 3.9, "3.10", "3.11"]
15-
package: ["databricks_sql_connector_core", "databricks_sql_connector"]
1612
steps:
17-
#----------------------------------------------
18-
# check-out repo and set-up python
19-
#----------------------------------------------
2013
- name: Check out repository
2114
uses: actions/checkout@v2
22-
- name: Set up python ${{ matrix.python-version }}
23-
id: setup-python
24-
uses: actions/setup-python@v2
2515
with:
26-
python-version: ${{ matrix.python-version }}
27-
#----------------------------------------------
28-
# ----- install & configure poetry -----
29-
#----------------------------------------------
30-
- name: Install Poetry
31-
uses: snok/install-poetry@v1
32-
with:
33-
virtualenvs-create: true
34-
virtualenvs-in-project: true
35-
installer-parallel: true
36-
37-
#----------------------------------------------
38-
# load cached venv if cache exists
39-
#----------------------------------------------
40-
- name: Load cached venv
41-
id: cached-poetry-dependencies
42-
uses: actions/cache@v2
43-
with:
44-
path: .venv
45-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }}
46-
#----------------------------------------------
47-
# install dependencies if cache does not exist
48-
#----------------------------------------------
49-
- name: Install dependencies
50-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
51-
run: poetry install --no-interaction --no-root
52-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
53-
#----------------------------------------------
54-
# install your root project, if required
55-
#----------------------------------------------
56-
- name: Install library
57-
run: poetry install --no-interaction
58-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
59-
#----------------------------------------------
60-
# run test suite
61-
#----------------------------------------------
62-
- name: Run tests
63-
if: ${{ maxtrix.package != 'databricks_sql_connector'}}
64-
run: poetry run python -m pytest tests/unit
65-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
66-
check-linting:
67-
runs-on: ubuntu-latest
68-
strategy:
69-
matrix:
70-
python-version: [3.8, 3.9, "3.10"]
71-
package: ["databricks_sql_connector_core"]
72-
steps:
73-
#----------------------------------------------
74-
# check-out repo and set-up python
75-
#----------------------------------------------
76-
- name: Check out repository
77-
uses: actions/checkout@v2
78-
- name: Set up python ${{ matrix.python-version }}
79-
id: setup-python
80-
uses: actions/setup-python@v2
81-
with:
82-
python-version: ${{ matrix.python-version }}
83-
#----------------------------------------------
84-
# ----- install & configure poetry -----
85-
#----------------------------------------------
86-
- name: Install Poetry
87-
uses: snok/install-poetry@v1
88-
with:
89-
virtualenvs-create: true
90-
virtualenvs-in-project: true
91-
installer-parallel: true
92-
93-
#----------------------------------------------
94-
# load cached venv if cache exists
95-
#----------------------------------------------
96-
- name: Load cached venv
97-
id: cached-poetry-dependencies
98-
uses: actions/cache@v2
99-
with:
100-
path: .venv
101-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }}
102-
#----------------------------------------------
103-
# install dependencies if cache does not exist
104-
#----------------------------------------------
105-
- name: Install dependencies
106-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
107-
run: poetry install --no-interaction --no-root
108-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
109-
#----------------------------------------------
110-
# install your root project, if required
111-
#----------------------------------------------
112-
- name: Install library
113-
run: poetry install --no-interaction
114-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
115-
#----------------------------------------------
116-
# black the code
117-
#----------------------------------------------
118-
- name: Black
119-
run: poetry run black --check src
120-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
121-
122-
check-types:
123-
runs-on: ubuntu-latest
124-
strategy:
125-
matrix:
126-
python-version: [3.8, 3.9, "3.10"]
127-
package: ["databricks_sql_connector_core"]
128-
steps:
129-
#----------------------------------------------
130-
# check-out repo and set-up python
131-
#----------------------------------------------
132-
- name: Check out repository
133-
uses: actions/checkout@v2
134-
- name: Set up python ${{ matrix.python-version }}
135-
id: setup-python
136-
uses: actions/setup-python@v2
137-
with:
138-
python-version: ${{ matrix.python-version }}
139-
#----------------------------------------------
140-
# ----- install & configure poetry -----
141-
#----------------------------------------------
142-
- name: Install Poetry
143-
uses: snok/install-poetry@v1
144-
with:
145-
virtualenvs-create: true
146-
virtualenvs-in-project: true
147-
installer-parallel: true
16+
ref: ${{ github.head_ref }}
14817

149-
#----------------------------------------------
150-
# load cached venv if cache exists
151-
#----------------------------------------------
152-
- name: Load cached venv
153-
id: cached-poetry-dependencies
154-
uses: actions/cache@v2
18+
- name: Build
19+
uses: ./.github/workflows/build.yml
15520
with:
156-
path: .venv
157-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }}
158-
#----------------------------------------------
159-
# install dependencies if cache does not exist
160-
#----------------------------------------------
161-
- name: Install dependencies
162-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
163-
run: poetry install --no-interaction --no-root
164-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
165-
#----------------------------------------------
166-
# install your root project, if required
167-
#----------------------------------------------
168-
- name: Install library
169-
run: poetry install --no-interaction
170-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
171-
#----------------------------------------------
172-
# mypy the code
173-
#----------------------------------------------
174-
- name: Mypy
175-
run: |
176-
mkdir .mypy_cache # Workaround for bad error message "error: --install-types failed (no mypy cache directory)"; see https://github.com/python/mypy/issues/10768#issuecomment-2178450153
177-
poetry run mypy --install-types --non-interactive src
178-
working-directory: ${{ github.workspace }}/${{ matrix.package }}
21+
target_path: "databricks_sql_connector_core"
22+
run_test: true
17923

0 commit comments

Comments
 (0)