name: Sync with mirror repo
on:
  push:
    branches:
      - dev
jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@master
      - name: Set up Python 3.7
        uses: actions/setup-python@v1
        with:
          python-version: 3.7
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: Build frontend
        working-directory: ./webiojs
        run: |
          npm install
          gulp
          cp dist/pywebio.min.* ../pywebio/html/js
      - name: Build doc demos
        run: |
          pip3 install -e ".[all]"
          pip3 install -r requirements.txt
          cd docs && CODE_EXPORT_PATH=../demos/doc_demos make clean html
      - name: Set dev version
        run: python3 tools/build_dev_version.py
      - name: Push
        run: |
          git fetch --unshallow origin
          git remote add aliyun "https://code.aliyun.com/wang0618/pywebio.git"
          git config credential.helper '!f() { sleep 1; echo "username=${ALIYUN_GIT_USER}"; echo "password=${ALIYUN_GIT_PASSWORD}"; }; f'
          rm .gitignore
          git add pywebio/__version__.py
          git add pywebio/html/js
          git add demos/doc_demos
          git config user.email "${ALIYUN_GIT_USER}"
          git config user.name "${ALIYUN_GIT_USER}"
          git commit --amend --no-edit
          git push -f -u aliyun --tags || true
          git push -f -u aliyun || true
        env:
          ALIYUN_GIT_USER: ${{ secrets.ALIYUN_GIT_USER }}
          ALIYUN_GIT_PASSWORD: ${{ secrets.ALIYUN_GIT_PASSWORD }}