name: CI

on:
  - pull_request
  - push

jobs:
  jabber:
    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v2
    - name: Dependencies
      run: |
        sudo apt-get update -y
        sudo apt-get install -y --no-install-recommends clang git make pkg-config libgnutls28-dev libgcrypt20-dev libglib2.0-dev prosody gcovr
        sudo prosodyctl stop

    - name: build bitlbee
      run: |
        ./configure --asan=1 --twitter=0
        cat ./.tests/gcovflags >> Makefile.settings
        make
        sudo make install
        sudo make install-etc

        touch ./debuglog

        sudo mkdir /var/lib/bitlbee
        sudo chmod -R 777 /var/lib/bitlbee
    
    - name: talk to bitlbee
      run: |
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/talk_to_bitlbee.py

        ./.tests/cleanup_bitlbee.sh
    
    - name: ask for help
      run: |
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/help.py

        ./.tests/cleanup_bitlbee.sh

    - name: (un)register
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/register.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/identify.py
        python3 ./.tests/unregister.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/setup_bitlbee.sh
        
        python3 ./.tests/identify_nonexist.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber connect
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_connect.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber delete account
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_delete_acc.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber add buddy
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_add_buddy.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber remove buddy
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_remove_buddy.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber send message
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_send_msg.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber rename buddy
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_rename_buddy.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber set status
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_status.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber go offline
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_offline.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber change default target
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_default_target.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: jabber block buddy
      if: ${{ always() }}
      run: |
        ./.tests/setup_prosody.sh
        ./.tests/setup_bitlbee.sh

        python3 ./.tests/jabber_block_buddy.py

        ./.tests/cleanup_bitlbee.sh
        ./.tests/cleanup_prosody.sh

    - name: code coverage
      if: ${{ always() }}
      run: |
        gcovr -r .
