Skip to content

Added workflow for import SDK from ydb repo #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/import_generation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
1 change: 1 addition & 0 deletions .github/last_commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ec36c2f7151e1e7718c2f0c0b2292383cab01e64
93 changes: 93 additions & 0 deletions .github/scripts/copy_sources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

tmp_dir=$(mktemp -d)

echo "Copying sources..."

cp -r $1/ydb/public/sdk/cpp/* $tmp_dir
echo "tmp_dir: $tmp_dir"

rm -r $tmp_dir/client
rm -r $tmp_dir/src/client/cms
rm -r $tmp_dir/src/client/config
rm -r $tmp_dir/src/client/debug
rm -r $tmp_dir/src/client/draft

rm -r $tmp_dir/include/ydb-cpp-sdk/client/cms
rm -r $tmp_dir/include/ydb-cpp-sdk/client/config
rm -r $tmp_dir/include/ydb-cpp-sdk/client/debug
rm -r $tmp_dir/include/ydb-cpp-sdk/client/draft

rm -r $tmp_dir/tests/unit/client/draft

mkdir -p $tmp_dir/src/api/client/yc_private
mkdir -p $tmp_dir/src/api/client/yc_public

cp -r $1/ydb/public/api/client/yc_private/iam $tmp_dir/src/api/client/yc_private
cp -r $1/ydb/public/api/client/yc_private/operation $tmp_dir/src/api/client/yc_private
cp -r $1/ydb/public/api/client/yc_public/common $tmp_dir/src/api/client/yc_public
cp -r $1/ydb/public/api/client/yc_public/iam $tmp_dir/src/api/client/yc_public
cp -r $1/ydb/public/api/grpc $tmp_dir/src/api
cp -r $1/ydb/public/api/protos $tmp_dir/src/api

rm -r $tmp_dir/src/api/protos/out
rm $tmp_dir/include/ydb-cpp-sdk/type_switcher.h $tmp_dir/src/version.h

cp -r $2/util $tmp_dir
cp -r $2/library $tmp_dir

cp -r $2/.devcontainer $tmp_dir
cp -r $2/.git $tmp_dir
cp -r $2/.github $tmp_dir
cp -r $2/contrib $tmp_dir
cp -r $2/cmake $tmp_dir
cp -r $2/scripts $tmp_dir
cp -r $2/third_party $tmp_dir
cp -r $2/tools $tmp_dir

cp $2/.gitignore $tmp_dir
cp $2/.gitmodules $tmp_dir
cp $2/CMakePresets.json $tmp_dir
cp $2/CMakeLists.txt $tmp_dir
cp $2/LICENSE $tmp_dir
cp $2/README.md $tmp_dir

cp $2/include/ydb-cpp-sdk/type_switcher.h $tmp_dir/include/ydb-cpp-sdk/type_switcher.h
cp $2/src/version.h $tmp_dir/src/version.h

cd $2

find src/ include/ tests/ examples/ -type f -name "CMakeLists.txt" | while read f;
do
mkdir -p "$(dirname "$tmp_dir/$f")" && cp -p $f $tmp_dir/$f
done

cd -

echo "Copying completed"
echo "Patching sources..."

rm -rf $tmp_dir/adapters $tmp_dir/client

SED_INCLUDE='(^\s*#include\s*)(<|\")'

find $tmp_dir -type f -regex ".*\(h\|cpp\|cpp.in\|c\|ipp\|jnj\|rl6\|h.txt\|proto\)$" | while read f;
do
sed -i -E \
's/'$SED_INCLUDE'ydb\/public\/api\//\1\2src\/api\//g;
s/(^\s*import\s*)(\")ydb\/public\/api\//\1\2src\/api\//g;
s/'$SED_INCLUDE'ydb\/public\/sdk\/cpp\/include\//\1\2/g;
s/'$SED_INCLUDE'ydb\/public\/sdk\/cpp\//\1\2/g;
s/'$SED_INCLUDE'library\/cpp\/retry\/retry_policy\.h/\1\2ydb-cpp-sdk\/library\/retry\/retry_policy\.h/g;
s/'$SED_INCLUDE'library\/cpp\/string_utils\/base64\/base64\.h/\1\2src\/library\/string_utils\/base64\/base64\.h/g;
s/(inline\s*)Dev/\1V3/g;
s/(inline\s*namespace\s*)Dev/\1V3/g;' $f
done

echo "Patching completed"
echo "RSync..."

rsync -c -I -W -r --delete --filter '- **/ya.make' --filter '- sdk_common.inc' $tmp_dir/ $2
rm -rf $tmp_dir

echo "RSync completed"
4 changes: 2 additions & 2 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
options: '-h localhost'
steps:
- name: Checkout PR
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event.pull_request.head.sha != ''
with:
submodules: true
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event.pull_request.head.sha == ''
with:
submodules: true
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/import.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Import

on:
workflow_dispatch:

jobs:
import-ydb-sdk:
runs-on: ubuntu-latest
steps:
- name: Checkout ydb-cpp-sdk
uses: actions/checkout@v4
with:
submodules: true
path: ydb-cpp-sdk

- name: Checkout ydb
uses: actions/checkout@v4
with:
repository: ydb-platform/ydb
ref: main
fetch-depth: 0
submodules: true
path: ydb

- name: Sync commits
run: |
sudo apt-get -y update
sudo apt-get -y install rsync

git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

LAST_COMMIT=$(cat ydb-cpp-sdk/.github/last_commit.txt)

COMMITS=$(git -C ydb log --format="%H" --reverse $LAST_COMMIT..main -- ydb/public/sdk/cpp ydb/public/api)
if [ -z "$COMMITS" ]; then
echo "No new commits to import"
exit 0
fi

GENERATION=$(cat ydb-cpp-sdk/.github/import_generation.txt)

git -C ydb-cpp-sdk checkout -b import-pr-$GENERATION
for commit in $COMMITS; do
echo "Importing commit: $commit"
git -C ydb checkout $commit
ydb-cpp-sdk/.github/scripts/copy_sources.sh ydb ydb-cpp-sdk
if [ -z "$(git -C ydb-cpp-sdk status --porcelain)" ]; then
echo "No changes for commit: $commit"
continue
fi
echo $commit > ydb-cpp-sdk/.github/last_commit.txt

message=$(git -C ydb show -s --format='%s')

git -C ydb-cpp-sdk add .
git -C ydb-cpp-sdk status

git -C ydb-cpp-sdk commit --author="$(git -C ydb show -s --format='%an <%ae>' $commit)" -m "$message" --no-edit

git -C ydb-cpp-sdk show -s --pretty=medium
done

- name: Create Pull Request
run: |
cd ydb-cpp-sdk
sudo apt-get -y install gh

GENERATION=$(cat .github/import_generation.txt)

echo "$((GENERATION + 1))" > .github/import_generation.txt

git add .github/import_generation.txt
git commit -m "Update import generation: $GENERATION"

git remote add token-origin https://${{ secrets.GITHUB_TOKEN }}@github.com/ydb-platform/ydb-cpp-sdk.git
git push token-origin import-pr-$GENERATION

gh pr create \
--base ${{ github.ref_name }} \
--head import-pr-$GENERATION \
--title "Import YDB C++ SDK $GENERATION" \
--body "Automatic import of new commits from ydb repository"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout PR
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event.pull_request.head.sha != ''
with:
submodules: true
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event.pull_request.head.sha == ''
with:
submodules: true
Expand Down Expand Up @@ -84,13 +84,13 @@ jobs:
options: '-h localhost'
steps:
- name: Checkout PR
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event.pull_request.head.sha != ''
with:
submodules: true
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
if: github.event.pull_request.head.sha == ''
with:
submodules: true
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/warmup_cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ jobs:
compiler: [clang, gcc]
steps:
- name: Checkout
uses: actions/checkout@v3
if: github.event.pull_request.head.sha == ''
uses: actions/checkout@v4
with:
submodules: true
- name: Install dependencies
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ _deps
!*/
# Unignore all files inside canondata dir
!*/canondata/*

# Unignore all files inside .github dir
!*/.github/*
# C libraries
*.so
*.a
Expand Down
Loading