|
| 1 | +name: Create PR to import libraries to main |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | +concurrency: |
| 5 | + group: ${{ github.workflow }} |
| 6 | + cancel-in-progress: true |
| 7 | +env: |
| 8 | + REPO: ${{ github.repository }} |
| 9 | + TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} |
| 10 | +jobs: |
| 11 | + sync: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Get current date |
| 15 | + id: date |
| 16 | + run: echo "::set-output name=dtm::$(date +'%y%m%d-%H%M')" |
| 17 | + - name: Sync |
| 18 | + run: | |
| 19 | + currsha=$(curl -s -H "Accept: application/vnd.github.VERSION.sha" https://api.github.com/repos/$REPO/commits/rightlib) |
| 20 | + echo "Current rightlib sha: ${currsha}" |
| 21 | + lastsha=$(curl -s https://raw.githubusercontent.com/$REPO/main/ydb/ci/rightlib.txt) |
| 22 | + echo "Last imported rightlib sha: ${lastsha}" |
| 23 | + if [ "${currsha}" == "${lastsha}" ];then |
| 24 | + echo "No new commits on the rightlib branch to merge, exiting" |
| 25 | + exit 0 |
| 26 | + fi |
| 27 | + echo "Git clone..." |
| 28 | + git clone https://[email protected]/$REPO.git ydb |
| 29 | + git config --global user.email "[email protected]" |
| 30 | + git config --global user.name "Alexander Smirnov" |
| 31 | + cd ydb |
| 32 | + # git fetch --depth `expr $(git rev-list --count HEAD) + 1` |
| 33 | + # echo "Commits in rightlib: $(git rev-list --count HEAD)" |
| 34 | + # echo "Fetch main..." |
| 35 | + # git fetch origin main:main --shallow-exclude rightlib |
| 36 | + # git fetch --depth `expr $(git rev-list --count main) + 1` |
| 37 | + # echo "Commits in main: $(git rev-list --count main)" |
| 38 | + git checkout rightlib |
| 39 | + libsha=$(git rev-parse HEAD) |
| 40 | + echo "Libs sha: $libsha" |
| 41 | + echo "Dev branch..." |
| 42 | + git checkout main |
| 43 | + devbranch="mergelibs-${{ steps.date.outputs.dtm }}" |
| 44 | + git checkout -b ${devbranch} |
| 45 | + prevsha=$(git rev-parse HEAD) |
| 46 | + git merge rightlib --no-edit |
| 47 | + currsha=$(git rev-parse HEAD) |
| 48 | + if [ ${prevsha} == ${currsha} ];then |
| 49 | + echo "Merge did not bring any changes, exiting" |
| 50 | + exit |
| 51 | + fi |
| 52 | + echo ${mainsha} > ydb/ci/rightlib.txt |
| 53 | + git add . |
| 54 | + git commit -m "Import libraries ${{ steps.date.outputs.dtm }}" |
| 55 | + git push --set-upstream origin mergelibs-${{ steps.date.outputs.dtm }} |
| 56 | + curl -L -X POST --fail-with-body \ |
| 57 | + -H "Accept: application/vnd.github+json" \ |
| 58 | + -H "Authorization: Bearer $TOKEN" \ |
| 59 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 60 | + https://api.github.com/repos/$REPO/pulls \ |
| 61 | + -d '{"title":"Library import ${{ steps.date.outputs.dtm }}","body":"","head":"'${devbranch}'","base":"main"}' |
0 commit comments