name: upstream
concurrency:
  group: "${{github.workflow}}-${{github.ref}}"
  cancel-in-progress: true
on:
  workflow_dispatch:
  schedule:
    - cron: "0 8 * * 1,3,5" # At 08:00 on Monday, Wednesday, and Friday # https://crontab.guru/#0_8_*_*_1,3,5

jobs:
  xmlsoft-head:
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/sparklemotion/nokogiri-test:mri-3.1
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Setup libxml2
        run: |
          git clone --depth=1 https://gitlab.gnome.org/GNOME/libxml2
          cd libxml2
          env NOCONFIGURE=t ./autogen.sh
      - name: Setup libxslt
        run: |
          git clone --depth=1 https://gitlab.gnome.org/GNOME/libxslt
          cd libxslt
          env NOCONFIGURE=t ./autogen.sh
      - name: "Run bundle install"
        run: "bundle install --local || bundle install"
      - name: "Compile against libxml2 and libxslt source directories"
        run: "bundle exec rake compile -- --with-xml2-source-dir=${GITHUB_WORKSPACE}/libxml2 --with-xslt-source-dir=${GITHUB_WORKSPACE}/libxslt"
      - run: "bundle exec rake test"

  xmlsoft-head-valgrind:
    needs: ["xmlsoft-head"]
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/sparklemotion/nokogiri-test:mri-3.1
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Setup libxml2
        run: |
          git clone --depth=1 https://gitlab.gnome.org/GNOME/libxml2
          cd libxml2
          env NOCONFIGURE=t ./autogen.sh
      - name: Setup libxslt
        run: |
          git clone --depth=1 https://gitlab.gnome.org/GNOME/libxslt
          cd libxslt
          env NOCONFIGURE=t ./autogen.sh
      - name: "Run bundle install"
        run: "bundle install --local || bundle install"
      - name: "Compile against libxml2 and libxslt source directories"
        run: "bundle exec rake compile -- --with-xml2-source-dir=${GITHUB_WORKSPACE}/libxml2 --with-xslt-source-dir=${GITHUB_WORKSPACE}/libxslt"
      - run: "bundle exec rake test:valgrind"

  ruby-head:
    strategy:
      fail-fast: false
      matrix:
        plat: ["ubuntu", "windows", "macos"]
        sys: ["enable", "disable"]
    runs-on: ${{matrix.plat}}-latest
    steps:
      - name: configure git crlf
        if: matrix.plat == 'windows'
        run: |
          git config --system core.autocrlf false
          git config --system core.eol lf
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: MSP-Greg/setup-ruby-pkgs@v1
        with:
          ruby-version: "head"
          apt-get: "libxml2-dev libxslt1-dev pkg-config"
          mingw: "_upgrade_ libxml2 libxslt pkgconf"
          bundler-cache: true
      - uses: actions/cache@v2
        if: matrix.sys == 'disable'
        with:
          path: ports
          key: ports-${{matrix.plat}}-${{hashFiles('dependencies.yml', 'patches/**/*.patch')}}
      - run: bundle exec rake compile -- --${{matrix.sys}}-system-libraries
      - run: bundle exec rake test

  ruby-head-valgrind:
    needs: ["ruby-head"]
    strategy:
      fail-fast: false
      matrix:
        sys: ["enable", "disable"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: MSP-Greg/setup-ruby-pkgs@v1
        with:
          ruby-version: "head"
          apt-get: "libxml2-dev libxslt1-dev pkg-config valgrind"
          bundler-cache: true
      - uses: actions/cache@v2
        if: matrix.sys == 'disable'
        with:
          path: ports
          key: ports-ubuntu-${{hashFiles('dependencies.yml', 'patches/**/*.patch')}}
      - run: bundle exec rake compile -- --${{matrix.sys}}-system-libraries
      - run: bundle exec rake test:valgrind

  jruby-head:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: "jruby-head"
          bundler-cache: true
      - run: bundle exec rake compile
      - run: bundle exec rake test

  # html5lib-tests:
  #   runs-on: ubuntu-latest
  #   container:
  #     image: ghcr.io/sparklemotion/nokogiri-test:mri-3.1
  #   steps:
  #     - uses: actions/checkout@v2
  #       with:
  #         submodules: true
  #     - uses: actions/cache@v2
  #       with:
  #         path: ports
  #         key: ports-ubuntu-${{hashFiles('dependencies.yml', 'patches/**/*.patch')}}
  #     - name: Update html5lib-tests
  #       run: |
  #         cd test/html5lib-tests
  #         git remote update origin
  #         git checkout origin/master
  #         git log --pretty=oneline -n1
  #     - run: bundle install --local || bundle install
  #     - run: bundle exec rake compile -- --disable-system-libraries
  #     - run: bundle exec rake test
