update #97
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: push to gitee | |
on: | |
push: | |
jobs: | |
push-to-gitee: | |
if: ${{ (github.repository_owner == 'jingjingxyk') && (github.repository == 'jingjingxyk/swoole-cli') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: install deps | |
run: | | |
sudo apt install openssh-client | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Prepare Secret Key | |
env: | |
PUSH_TO_GITEE_SECRET_KEY: ${{ secrets.PUSH_TO_GITEE_SECRET_KEY }} | |
run: | | |
mkdir -p ~/.ssh/ | |
printf "%s\n" "$PUSH_TO_GITEE_SECRET_KEY" > ~/.ssh/swoole-cli-github-push-to-gitee-key | |
chmod 0400 ~/.ssh/swoole-cli-github-push-to-gitee-key | |
cat > ~/.ssh/config <<'EOF' | |
Host gitee.com | |
Hostname gitee.com | |
Port 22 | |
PreferredAuthentications publickey | |
StrictHostKeyChecking no | |
IdentityFile ~/.ssh/swoole-cli-github-push-to-gitee-key | |
EOF | |
ls -lh ~/.ssh/ | |
- name: push to gitee | |
run: | | |
set -x | |
# ssh -T [email protected] | |
git fetch origin -a | |
git remote add gitee [email protected]:jingjingxyk/swoole-cli.git | |
git fetch gitee -a | |
git push gitee --all | |
# 求差集 (gitee 存在的分支,github 不存在分支,执行删除操作) | |
GITEE_BRANCHS=$(git branch -r --list | grep -v -- '->' | grep 'gitee/' | sed 's/gitee\///' | xargs -I {} echo {} | sort) | |
GITHUB_BRANCHS=$(git branch -r --list | grep -v -- '->' | grep 'origin/' | sed 's/origin\///' | xargs -I {} echo {} | sort) | |
comm -23 <(echo $GITEE_BRANCHS) <(echo $GITHUB_BRANCHS) | awk -F "\t" '{ print $1 }' | xargs -I {} echo {} | |
comm -23 <(echo $GITEE_BRANCHS) <(echo $GITHUB_BRANCHS) | awk -F "\t" '{ print $1 }' | xargs -I {} echo {} | xargs -I {} git push -d gitee {} | |