name: Sync_JD_Shell_v3_To_Gitee
on:
  push:
    branches:
      - v3
  workflow_dispatch:
jobs:
  sync:
    runs-on: ubuntu-18.04
    if: github.repository == 'lan-tianxiang/js_tool'
    timeout-minutes: 3
    steps:
    - name: Init Build Dependencies
      env:
        DEBIAN_FRONTEND: noninteractive
      run: |
        sudo -E rm -rf /etc/apt/sources.list.d
        sudo -E apt-get update -y
        sudo -E apt-get install -y build-essential git git-core curl wget
        sudo -E apt-get clean -y
        git config --global user.name 'lan-tianxiang' && git config --global user.email 'highdimen@gitee.com'
    - name: Prepare Key
      run: |
        mkdir -p ~/.ssh
        echo -e "${{ secrets.RSA_PRIVATE_KEY }}" > ~/.ssh/id_rsa
        chmod 600 ~/.ssh/id_rsa
        ssh-keyscan github.com > ~/.ssh/known_hosts
    - name: Clone Master
      run: |
        git clone -b v3 git@github.com:lan-tianxiang/js_tool.git v3
    - name: Prepare Key
      run: |
        mkdir -p ~/.ssh
        echo -e "${{ secrets.RSA_PRIVATE_KEY }}" > ~/.ssh/id_rsa
        chmod 600 ~/.ssh/id_rsa
        ssh-keyscan gitee.com > ~/.ssh/known_hosts
    - name: push Master
      run: |
        cd v3
        perl -i -pe "s|url \= git\@github.com:lan-tianxiang\/jd_shell.git|url \= git\@gitee.com:highdimen\/jd_shell.git|g" .git/config
        cat .git/config
        echo "## UpdateTime: "$(date) >> jd.sh
        git add .
        git commit -m "update"
        git push -f
    - name: Delete Workflow Runs
      uses: Mattraks/delete-workflow-runs@main
      with:
        token: ${{ github.token }}
        repository: ${{ github.repository }}
        retain_days: 1
        keep_minimum_runs: 0
