Skip to content

fix: synchronization base error #1

fix: synchronization base error

fix: synchronization base error #1

name: synchronize to dtk6
on:
workflow_call:
inputs:
dest_repo:
type: string
required: true
source_repo:
type: string
required: true
source_repo:
type: string
required: true
source_ref:
type: string
required: true
pull_number:
type: number
required: true
secrets:
CI_ROBOT_PAT:
required: true
env:
GH_TOKEN: ${{ secrets.CI_ROBOT_PAT }}
jobs:
sync-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout source repository ${{ inputs.source_repo }}
- name: Checkout source repository ${{ inputs.source_repo }}
uses: actions/checkout@v3
with:
token: ${{ env.GH_TOKEN }}
token: ${{ env.GH_TOKEN }}
ref: ${{ inputs.source_ref }}
path: 'source'
repository: ${{ inputs.source_repo }}
repository: ${{ inputs.source_repo }}
fetch-depth: 0
- name: Checkout dest repository ${{ inputs.dest_repo }}
uses: actions/checkout@v3
with:
token: ${{ env.GH_TOKEN }}
token: ${{ env.GH_TOKEN }}
ref: 'master'
path: 'dest'
repository: ${{ inputs.dest_repo }}
- name: Synchronize files to ${{ inputs.dest_repo }}
id: rsync
run: |
git config --global user.name "deepin-ci-robot"
git config --global user.email "[email protected]"
tbranch="sync-${{ inputs.pull_number }}"
set -x
cd ${{ github.workspace }}/dest
git checkout -B ${tbranch}
git checkout -B ${tbranch}
cd ${{ github.workspace }}/source
git remote add upstream ${{ github.event.repository.clone_url }}
git fetch --all
git rebase upstream/master
if [[ -f ${{ github.workspace }}/source/.syncexclude ]]; then
rsync -avzp --delete --exclude=.git --exclude=.github --exclude=.obs --exclude=debian --exclude=archlinux --exclude=rpm --exclude-from=.syncexclude ${{ github.workspace }}/source/ ${{ github.workspace }}/dest/
rsync -avzp --delete --exclude=.git --exclude=.github --exclude=.obs --exclude=debian --exclude=archlinux --exclude=rpm --exclude-from=.syncexclude ${{ github.workspace }}/source/ ${{ github.workspace }}/dest/
else
rsync -avzp --delete --exclude=.git --exclude=.github --exclude=.obs --exclude=debian --exclude=archlinux --exclude=rpm ${{ github.workspace }}/source/ ${{ github.workspace }}/dest/
rsync -avzp --delete --exclude=.git --exclude=.github --exclude=.obs --exclude=debian --exclude=archlinux --exclude=rpm ${{ github.workspace }}/source/ ${{ github.workspace }}/dest/
fi
cd ${{ github.workspace }}/dest
difference=$(git diff)
echo "tbranch=${tbranch}" >> $GITHUB_OUTPUT
if [[ ! -z ${difference} ]]; then
echo "has_diff=true" >> $GITHUB_OUTPUT
else
echo "has_diff=false" >> $GITHUB_OUTPUT
fi
- name: Commit changes to ${{ inputs.dest_repo }}
if: steps.rsync.outputs.has_diff
run: |
tbranch=${{ steps.rsync.outputs.tbranch }}
cd ${{ github.workspace }}/dest
difference=$(git diff)
echo "tbranch=${tbranch}" >> $GITHUB_OUTPUT
if [[ ! -z ${difference} ]]; then
echo "has_diff=true" >> $GITHUB_OUTPUT
else
echo "has_diff=false" >> $GITHUB_OUTPUT
fi
- name: Commit changes to ${{ inputs.dest_repo }}
if: steps.rsync.outputs.has_diff
run: |
tbranch=${{ steps.rsync.outputs.tbranch }}
cd ${{ github.workspace }}/dest
git add :/
git commit \
-m "sync: from ${{ github.repository }}" \
-m "Synchronize source files from ${{ github.repository }}." \
-m "Source-pull-request: https://github.com/${{ github.repository }}/pull/${{ inputs.pull_number }}"
git push -u -f origin ${tbranch}
-m "Source-pull-request: https://github.com/${{ github.repository }}/pull/${{ inputs.pull_number }}"
git push -u -f origin ${tbranch}
cd ${{ github.workspace }}/dest
gh repo set-default ${{ inputs.dest_repo }}
result=$(gh pr list --base master --head ${tbranch} --state open)
if [[ -z $result ]]; then
gh pr create -B master -H ${tbranch} --fill
gh pr create -B master -H ${tbranch} --fill
fi