on:
  schedule:
    - cron: '0 0 * * 6'

jobs:
  redox:
    name: Check compilation on Redox
    runs-on: ubuntu-latest
    container:
      image: redoxos/redoxer:latest
    steps:
      - uses: actions/checkout@master
      - name: prepare repository for redoxer compilation
        run: bash scripts/redox/uncomment-cargo.sh
      - name: compile for redox
        run: redoxer build --verbose

  codecov:
    name: Collect code coverage data
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: build
          args: --verbose
        env:
          CARGO_INCREMENTAL: '0'
          RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests' # -Cpanic=abort
      - uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - name: Install pipenv
        run: |
          python -V
          python -m pip install --upgrade pip
          python -m pip install pipenv
      - run: pipenv install
        working-directory: ./extra_tests
      - name: run snippets
        run: pipenv run pytest -v
        working-directory: ./extra_tests
        env:
          RUSTPYTHON_DEBUG: 'true'
      - name: run cpython tests
        run: cargo run -- -m test -v
        env:
          RUSTPYTHONPATH: ${{ github.workspace }}/Lib
      - uses: actions-rs/grcov@v0.1
        id: coverage
      - name: upload to Codecov
        uses: codecov/codecov-action@v1
        with:
          file: ${{ steps.coverage.outputs.report }}

  testdata:
    name: Collect regression test data
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: build rustpython
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --verbose
      - name: collect tests data
        run: cargo run --release extra_tests/jsontests.py
        env:
          RUSTPYTHONPATH: ${{ github.workspace }}/Lib
      - name: upload tests data to the website
        env:
          SSHKEY: ${{ secrets.ACTIONS_TESTS_DATA_DEPLOY_KEY }}
          GITHUB_ACTOR: ${{ github.actor }}
        run: |
          echo "$SSHKEY" >~/github_key
          chmod 600 ~/github_key
          export GIT_SSH_COMMAND="ssh -i ~/github_key"

          git clone git@github.com:RustPython/rustpython.github.io.git website
          cd website
          cp ../extra_tests/cpython_tests_results.json ./_data/regrtests_results.json
          git add ./_data/regrtests_results.json
          git -c user.name="Github Actions" -c user.email="actions@github.com" commit -m "Update regression test results" --author="$GITHUB_ACTOR"
          git push
