Repository navigation
115 lines (94 loc) · 3.07 KB
/
Copy pathci.yaml
File metadata and controls
115 lines (94 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Python Connectors CI
on:
push:
branches:
- master
workflow_dispatch:
jobs:
detect-clients:
runs-on: ubuntu-latest
outputs:
clients: ${{ steps.detect.outputs.clients }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect clients to build
id: detect
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
BEFORE_SHA: ${{ github.event.before }}
CURRENT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
# Every buildable package in the repository
ALL_CLIENTS=()
if [ -d common ]; then
ALL_CLIENTS+=("common")
fi
for client in clients/*; do
if [ -d "$client" ]; then
ALL_CLIENTS+=("$(basename "$client")")
fi
done
build_all() {
printf '%s\n' "${ALL_CLIENTS[@]}" | jq -R -s -c 'split("\n") | map(select(. != ""))'
}
BASE_SHA=""
if [ "$EVENT_NAME" = "push" ] \
&& [ -n "${BEFORE_SHA:-}" ] \
&& [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ] \
&& git cat-file -e "${BEFORE_SHA}^{commit}" 2>/dev/null; then
BASE_SHA="$BEFORE_SHA"
fi
if [ -z "$BASE_SHA" ]; then
echo "No usable diff base (event '$EVENT_NAME'): building every client"
CLIENTS_JSON=$(build_all)
else
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$CURRENT_SHA")
echo "Changed files:"
echo "$CHANGED_FILES" | sed 's/^/ /'
CLIENTS_JSON=$(echo "$CHANGED_FILES" | awk -F/ '
$1 == "common" { print "common" }
$1 == "clients" && NF > 2 { print $2 }
' | jq -R -s -c 'split("\n") | map(select(. != "")) | unique')
fi
echo "Clients to build: $CLIENTS_JSON"
echo "clients=$CLIENTS_JSON" >> "$GITHUB_OUTPUT"
build:
needs: detect-clients
if: ${{ needs.detect-clients.outputs.clients != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
client: ${{ fromJson(needs.detect-clients.outputs.clients) }}
python-version: ["3.12"]
poetry-version: ["1.8.4"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
pip3 install --upgrade pip && \
pip3 install ruff black && \
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Build ${{ matrix.client }} client
run: |
if [ "${{ matrix.client }}" == "common" ]; then
cd common
else
cd clients/${{ matrix.client }}
fi
# Install dependencies
poetry install
# Format
poetry run black .
# Lint
poetry run ruff check --fix .
# Test
poetry run pytest tests
# Build
poetry build