---
name: CI

on:
  push:
    branches: '*'
  pull_request:
    branches: '*'

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      socks5:
        image: serjs/go-socks5-proxy
        env:
          PROXY_USER: user
          PROXY_PASSWORD: password
        ports:
          - 1080:1080

    strategy:
      matrix:
        ruby: ['3.2', '3.3', '3.4', head]

    steps:
      - uses: actions/checkout@v4

      - name: Install Act dependencies
        if: ${{ env.ACT }}
        run: |
          apt-get update && apt-get install sudo -y  # https://github.com/nektos/act/issues/107

      - name: Install and setup tor
        run: |
          sudo apt-get update
          sudo apt-get install -y tor
          tor --version
          sudo sh -c 'echo SocksPort 9050 > /etc/tor/torrc'
          sudo sh -c 'echo ControlPort 9051 >> /etc/tor/torrc'
          export HashedControlPassword=$(tor --quiet --hash-password "")
          sudo sh -c "echo HashedControlPassword $HashedControlPassword >> /etc/tor/torrc"
          sudo sh -c 'cat /etc/tor/torrc'
          tor --verify-config
          # sudo service tor start
          # pidof tor

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1  # https://github.com/ruby/setup-ruby
        with:
          ruby-version: ${{ matrix.ruby }}
          bundler-cache: true

      - name: Install gems
        run: |
          bundle install

      - name: Run tests
        run: |
          bundle exec rake
