name: Upload changes to back-end
on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v4
        with:
          python-version: '3.9'

      - name: Upload Json front-end
        if: contains(github.event.head_commit.message,'[back-end]') == false
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          cd ../
          git clone --depth 1 --single-branch --branch back-end https://github.com/3Snake3/Sapphirium.git BackEndBranch
          python Sapphirium/.github/workflows/upload/front2back.py
          cd BackEndBranch
          git config --global user.email "Li_plum@outlook.com"
          git config --global user.name "liplum"
          git status --porcelain
          git add .
          if [ -n "$(git status --porcelain)" ]; then
            git commit -m "Json front-end update"
            git push https://3Snake3:${{ secrets.SAPP_TOKEN }}@github.com/3Snake3/Sapphirium
          fi
