name: CI
on:
  pull_request:
  push: { branches: master }
jobs:
  test:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        ruby-version: [2.6.10, 2.7.7, 3.0.6, 3.1.3, 3.2.1, 3.3.0]
    steps:
      - uses: actions/checkout@v3

      - name: Set up Ruby ${{ matrix.ruby-version }}
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby-version }}
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: 3.8

      - name: Cache bundler
        uses: actions/cache@v1
        id: bundler-cache
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-${{ matrix.ruby-version }}-gem-v3-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/net-ssh.gemspec') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.ruby-version }}-gem-v3-
      
      - name: Cache pip
        uses: actions/cache@v1
        id: pip-cache
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-v1
          restore-keys: |
            ${{ runner.os }}-pip-v1
      - name: Bundle install
        run: |
          gem install bundler ${{ (startsWith(matrix.ruby-version, '2.6.') || startsWith(matrix.ruby-version, '2.7.')) && '-v 2.4.22' || '' }}
          bundle config set path 'vendor/bundle'
          bundle config set --local path 'vendor/bundle'
          bundle install --jobs 4 --retry 3 --path vendor/bundle
          BUNDLE_GEMFILE=./Gemfile.noed25519 bundle install --jobs 4 --retry 3 --path vendor/bundle
        env:
          BUNDLE_PATH: vendor/bundle

      
      - name: Add to etc/hosts
        run: |
          sudo echo "127.0.0.1  gateway.netssh" | sudo tee -a /etc/hosts
      - name: Check sshd_config
        run: sudo cat '/etc/ssh/sshd_config' || true
      - name: Check sshd_config2
        run: sudo cat /etc/ssh/sshd_config.d/*.conf || true
      - name: Check sshd pid
        run: sudo ps aux | grep sshd
      - name: Ansible install
        run: |
          python -m pip install --upgrade pip
          pip install ansible urllib3 pyOpenSSL ndg-httpsclient pyasn1
          ansible-galaxy install rvm.ruby
          pwd
          uname -a
          export
          who am i
          ansible-playbook ./test/integration/playbook.yml -i "localhost," --become -c local -e 'no_rvm=true' -e 'myuser=runner' -e 'mygroup=runner' -e 'homedir=/home/runner'
      - name: Check sshd_config
        run: sudo cat '/etc/ssh/sshd_config' || true
      - name: Check sshd pid
        run: sudo ps aux | grep sshd
      - name: Check sshd_config2
        run: sudo cat /etc/ssh/sshd_config.d/*.conf || true
      - name: Run Tests
        run: bundle exec rake test
        env:
          NET_SSH_RUN_INTEGRATION_TESTS: 1
          CI: 1
      - name: Run tests (without rbnacl)
        run: bundle exec rake test
        env:
          BUNDLE_GEMFILE: ./Gemfile.norbnacl
          NET_SSH_RUN_INTEGRATION_TESTS: 1
          CI: 1
      - name: Run Tests (without ed25519)
        run: bundle exec rake test
        env:
          BUNDLE_GEMFILE: ./Gemfile.noed25519
          NET_SSH_RUN_INTEGRATION_TESTS: 1
          CI: 1
      - name: Run test helper test
        run: bundle exec rake test_test
