Skip to content

Commit 3996666

Browse files
authored
Merge pull request #380 from binance/modularize_connectors
Modularize Connectors
2 parents b943389 + 312a7e3 commit 3996666

File tree

3,899 files changed

+465711
-33979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,899 files changed

+465711
-33979
lines changed

.github/workflows/ci.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Python Connectors CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
detect-clients:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
clients: ${{ steps.detect.outputs.clients }}
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Detect all clients
18+
id: detect
19+
run: |
20+
ALL_CLIENTS=$(ls -d clients/*/ | xargs -n 1 basename | jq -R -s -c 'split("\n")[:-1]')
21+
echo "Detected clients: $ALL_CLIENTS"
22+
echo "clients=$ALL_CLIENTS" >> $GITHUB_ENV
23+
echo "::set-output name=clients::$ALL_CLIENTS"
24+
25+
build:
26+
needs: detect-clients
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
client: ${{ fromJson(needs.detect-clients.outputs.clients) }}
31+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
32+
poetry-version: ["latest", "main", "1.8.4"]
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Set up Python ${{ matrix.python-version }}
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: ${{ matrix.python-version }}
42+
43+
- name: Install poetry
44+
uses: abatilo/actions-poetry@v3
45+
with:
46+
poetry-version: ${{ matrix.poetry-version }}
47+
48+
- name: Build ${{ matrix.client }} client
49+
run: |
50+
if [ "${{ matrix.client }}" == "common" ]; then
51+
cd common
52+
else
53+
cd clients/${{ matrix.client }}
54+
fi
55+
56+
# Install dependencies
57+
poetry install
58+
59+
# Format
60+
poetry run black .
61+
62+
# Lint
63+
poetry run ruff check --fix .
64+
65+
# Test
66+
poetry run pytest tests
67+
68+
# Build
69+
poetry build

.github/workflows/pythonpackage.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
name: Sync Connectors with Public Repo
2+
3+
on:
4+
# push:
5+
# branches:
6+
# - master
7+
workflow_dispatch:
8+
9+
jobs:
10+
detect-targets:
11+
runs-on: self-hosted
12+
outputs:
13+
modified_targets: ${{ steps.filter.outputs.modified_targets }}
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 2
19+
20+
- name: Detect modified targets
21+
id: filter
22+
run: |
23+
MODIFIED_TARGETS=()
24+
25+
# Determine base commit: use HEAD^ if it exists, otherwise use the first commit
26+
if git rev-parse --verify HEAD^ >/dev/null 2>&1; then
27+
BASE_COMMIT="HEAD^"
28+
else
29+
BASE_COMMIT=$(git rev-list --max-parents=0 HEAD)
30+
fi
31+
32+
# Check common directory
33+
if ! git diff --quiet "$BASE_COMMIT" HEAD -- "common"; then
34+
echo "Changes detected in common"
35+
MODIFIED_TARGETS+=("common")
36+
fi
37+
38+
# Loop through each client directory in "clients/"
39+
for client in clients/*; do
40+
CLIENT_NAME=$(basename "$client")
41+
# Check for changes in the client directory between BASE_COMMIT and HEAD
42+
if ! git diff --quiet "$BASE_COMMIT" HEAD -- "$client"; then
43+
echo "Changes detected in $CLIENT_NAME"
44+
MODIFIED_TARGETS+=("$CLIENT_NAME")
45+
fi
46+
done
47+
48+
# Detect any change whose top-level folder isn’t clients/, common/, .github/
49+
if git diff --name-only "$BASE_COMMIT" HEAD \
50+
| grep -Ev '^(clients|common|\.github)/' \
51+
| grep -q .; then
52+
echo "Changes detected in repo root"
53+
MODIFIED_TARGETS+=("root")
54+
fi
55+
56+
# Convert the array of modified targets into a JSON array
57+
MODIFIED_TARGETS_JSON=$(printf '%s\n' "${MODIFIED_TARGETS[@]}" | jq -R -s -c 'split("\n") | map(select(. != ""))')
58+
59+
echo "modified_targets: $MODIFIED_TARGETS_JSON"
60+
echo "modified_targets=$MODIFIED_TARGETS_JSON" >> $GITHUB_ENV
61+
echo "::set-output name=modified_targets::$MODIFIED_TARGETS_JSON"
62+
63+
sync-connectors:
64+
runs-on: self-hosted
65+
needs: detect-targets
66+
if: ${{ needs.detect-targets.outputs.modified_targets != '[]' }}
67+
strategy:
68+
matrix:
69+
target: ${{ fromJson(needs.detect-targets.outputs.modified_targets) }}
70+
permissions:
71+
contents: write
72+
pull-requests: write
73+
repository-projects: write
74+
75+
steps:
76+
- name: Checkout source repository
77+
uses: actions/checkout@v3
78+
79+
- name: Determine directory path
80+
id: get_dir_path
81+
run: |
82+
if [[ "${{ matrix.target }}" == "root" ]]; then
83+
DIR_PATH="."
84+
elif [[ "${{ matrix.target }}" == "common" ]]; then
85+
DIR_PATH="${{ matrix.target }}"
86+
else
87+
DIR_PATH="clients/${{ matrix.target }}"
88+
fi
89+
echo "DIR_PATH=$DIR_PATH" >> $GITHUB_ENV
90+
91+
- name: Determine version for ${{ matrix.target }}
92+
if: ${{ matrix.target != 'root' }}
93+
id: get_version
94+
run: |
95+
VERSION=$(jq -r .version ${{ env.DIR_PATH }}/pyproject.toml)
96+
echo "VERSION=$VERSION" >> $GITHUB_ENV
97+
echo "Detected version: $VERSION"
98+
99+
- name: Extract latest changes from CHANGELOG
100+
if: ${{ matrix.target != 'root' }}
101+
id: get_changelog
102+
run: |
103+
VERSION=${{ env.VERSION }}
104+
105+
CHANGELOG_CONTENT=$(awk -v version="## ${VERSION}" '/^## / {p=0} $0 ~ version {p=1} p' ${{ env.DIR_PATH }}/CHANGELOG.md | tail -n +2)
106+
ESCAPED_CHANGELOG=$(echo "$CHANGELOG_CONTENT" | sed 's/`/\\`/g')
107+
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
108+
echo "$ESCAPED_CHANGELOG" >> $GITHUB_ENV
109+
echo "EOF" >> $GITHUB_ENV
110+
111+
- name: Sync ${{ matrix.target }} changes to public repo
112+
env:
113+
GH_PAT: ${{ secrets.GH_PAT }}
114+
id: check_changes
115+
run: |
116+
TARGET_REPO="binance/binance-connector-python"
117+
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
118+
119+
# Configure git
120+
git config --global user.name "github-actions"
121+
git config --global user.email "github-actions@github.com"
122+
123+
git clone https://x-access-token:${GH_PAT}@github.com/binance/binance-connector-python.git public-repo
124+
125+
cd public-repo
126+
git fetch origin ${DEFAULT_BRANCH}
127+
128+
if [[ "${{ matrix.target }}" == "root" ]]; then
129+
BRANCH="root-update-${GITHUB_RUN_NUMBER}"
130+
COMMIT_MSG="Update root-level docs and configs"
131+
PR_TITLE="Update root-level documentation and configuration"
132+
PR_BODY="Apply recent updates to root-level documentation and configuration files."
133+
else
134+
BRANCH="rc-${{ matrix.target }}-v${{ env.VERSION }}"
135+
COMMIT_MSG="Release ${{ matrix.target }} v${{ env.VERSION }}"
136+
PR_TITLE="Release ${{ matrix.target }} v${{ env.VERSION }}"
137+
if [ -n "${{ env.CHANGELOG }}" ]; then
138+
PR_BODY="${{ env.CHANGELOG }}"
139+
else
140+
PR_BODY="Release v${{ env.VERSION }}."
141+
fi
142+
fi
143+
144+
# Compare directories
145+
if ! diff -qr --exclude=".git" --exclude="dist" --exclude="poetry.lock" ../${{ env.DIR_PATH }} ${{ env.DIR_PATH }} > /dev/null; then
146+
echo "Changes detected in ${{ matrix.target }}"
147+
else
148+
echo "No changes detected in ${{ matrix.target }}. Exiting..."
149+
exit 0
150+
fi
151+
152+
if [[ "${{ matrix.target }}" == "root" ]]; then
153+
rsync -avh --delete \
154+
--exclude='.git' \
155+
--exclude='.github' \
156+
--exclude='poetry.lock' \
157+
--exclude='clients' \
158+
--exclude='common' \
159+
--exclude='public-repo' \
160+
../ .
161+
else
162+
rsync -avh --delete ../${{ env.DIR_PATH }}/ ${{ env.DIR_PATH }}/
163+
fi
164+
165+
# Create new branch
166+
git checkout -b "${BRANCH}"
167+
168+
git add .
169+
git commit -m "${COMMIT_MSG}"
170+
git push origin "${BRANCH}"
171+
172+
# Authenticate with GitHub CLI
173+
echo "${GH_PAT}" | gh auth login --with-token
174+
175+
# Create a Pull Request
176+
PR_URL=$(gh pr create \
177+
--repo "$TARGET_REPO" \
178+
--base ${DEFAULT_BRANCH} \
179+
--head "${BRANCH}" \
180+
--title "${PR_TITLE}" \
181+
--body "${PR_BODY}")
182+
183+
# Extract PR number from URL
184+
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
185+
186+
# Mark the PR as ready for review
187+
gh pr ready "$PR_NUMBER"
188+
189+
echo "Pull Request created and is ready to be reviewed: #$PR_NUMBER"
190+
191+
# Add reviewers
192+
gh pr edit "$PR_NUMBER" --add-reviewer binance/solutions-managers

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__
66
.tox
77
.python-version
88
.DS_Store
9+
poetry.lock
910

1011
# Environments
1112
.env
@@ -19,4 +20,4 @@ venv/
1920
# document build
2021
docs/build/
2122

22-
examples/*.ini
23+
examples/*.ini

.pre-commit-config.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)