name: gem-install
concurrency:
  group: "${{github.workflow}}-${{github.ref}}"
  cancel-in-progress: true
on:
  workflow_dispatch:
  push:
    branches:
      - main
      - v*.*.x
    tags:
      - v*.*.*
  pull_request:
    types: [opened, synchronize]
    branches:
      - '*'

jobs:
  cruby-package:
    name: "cruby-package"
    runs-on: ubuntu-latest
    container:
      image: "larskanis/rake-compiler-dock-mri-x86_64-linux:1.2.2"
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions/cache@v2
        with:
          path: ports/archives
          key: tarballs-ubuntu-${{hashFiles('dependencies.yml', 'patches/**/*.patch')}}
      - run: ./scripts/test-gem-build gems ruby
      - uses: actions/upload-artifact@v2
        with:
          name: cruby-gem
          path: gems
          retention-days: 1

  cruby-linux-install:
    needs: ["cruby-package"]
    strategy:
      fail-fast: false
      matrix:
        sys: ["enable", "disable"]
        ruby: ["2.6", "2.7", "3.0", "3.1", "head"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: MSP-Greg/setup-ruby-pkgs@v1
        with:
          ruby-version: "${{matrix.ruby}}"
          apt-get: "libxml2-dev libxslt1-dev pkg-config"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-gem
          path: gems
      - run: ./scripts/test-gem-install gems --${{matrix.sys}}-system-libraries

  cruby-osx-install:
    needs: ["cruby-package"]
    strategy:
      fail-fast: false
      matrix:
        sys: ["enable", "disable"]
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.1"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-gem
          path: gems
      - run: ./scripts/test-gem-install gems --${{matrix.sys}}-system-libraries

  cruby-windows-install:
    needs: ["cruby-package"]
    strategy:
      fail-fast: false
      matrix:
        sys: ["enable", "disable"]
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: MSP-Greg/setup-ruby-pkgs@v1
        with:
          ruby-version: "3.0"
          mingw: "libxml2 libxslt"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-gem
          path: gems
      - run: |
          gem install --verbose --no-document gems/*.gem -- --${{matrix.sys}}-system-libraries
          gem list -d nokogiri
          nokogiri -v

  cruby-windows-install-ucrt:
    needs: ["cruby-package"]
    strategy:
      fail-fast: false
      matrix:
        sys: ["enable", "disable"]
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: MSP-Greg/setup-ruby-pkgs@v1
        with:
          ruby-version: "3.1"
          mingw: "libxml2 libxslt"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-gem
          path: gems
      - run: |
          gem install --verbose --no-document gems/*.gem -- --${{matrix.sys}}-system-libraries
          gem list -d nokogiri
          nokogiri -v

  cruby-native-package:
    name: "cruby-native-package"
    strategy:
      fail-fast: false
      matrix:
        plat:
          - "aarch64-linux"
          # - "arm64-darwin" # github actions does not support this as of 2022-01
          - "x64-mingw-ucrt"
          - "x64-mingw32"
          - "x86-linux"
          # - "x86-mingw32" # github actions does not support this as of 2022-01
          - "x86_64-darwin"
          - "x86_64-linux"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions/cache@v2
        with:
          path: ports/archives
          key: tarballs-ubuntu-${{hashFiles('dependencies.yml', 'patches/**/*.patch')}}
      - run: |
          docker run --rm -v "$(pwd):/nokogiri" -w /nokogiri \
            larskanis/rake-compiler-dock-mri-${{matrix.plat}}:1.2.2 \
            ./scripts/test-gem-build gems ${{matrix.plat}}
      - uses: actions/upload-artifact@v2
        with:
          name: "cruby-${{matrix.plat}}-gem"
          path: gems
          retention-days: 1

  cruby-x86-linux-install:
    needs: ["cruby-native-package"]
    strategy:
      fail-fast: false
      matrix:
        ruby: ["2.6", "2.7", "3.0", "3.1"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions/download-artifact@v2
        with:
          name: cruby-x86-linux-gem
          path: gems
      - run: |
          docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
          docker run --rm -v "$(pwd):/nokogiri" -w /nokogiri \
            --platform=linux/386 \
            ruby:${{matrix.ruby}} \
            ./scripts/test-gem-install gems

  cruby-aarch64-linux-install:
    needs: ["cruby-native-package"]
    strategy:
      fail-fast: false
      matrix:
        ruby: ["2.6", "2.7", "3.0", "3.1"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions/download-artifact@v2
        with:
          name: cruby-aarch64-linux-gem
          path: gems
      - run: |
          docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
          docker run --rm -v "$(pwd):/nokogiri" -w /nokogiri \
            --platform=linux/arm64/v8 \
            ruby:${{matrix.ruby}} \
            ./scripts/test-gem-install gems

  cruby-x86_64-linux-install:
    needs: ["cruby-native-package"]
    strategy:
      fail-fast: false
      matrix:
        ruby: ["2.6", "2.7", "3.0", "3.1"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: "${{matrix.ruby}}"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-x86_64-linux-gem
          path: gems
      - run: ./scripts/test-gem-install gems

  cruby-x86_64-musl-install:
    needs: ["cruby-native-package"]
    strategy:
      fail-fast: false
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/sparklemotion/nokogiri-test:alpine
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions/download-artifact@v2
        with:
          name: cruby-x86_64-linux-gem
          path: gems
      - run: ./scripts/test-gem-install gems

  cruby-x86_64-darwin-install:
    needs: ["cruby-native-package"]
    strategy:
      fail-fast: false
      matrix:
        ruby: ["2.6", "2.7", "3.0", "3.1"]
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: "${{matrix.ruby}}"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-x86_64-darwin-gem
          path: gems
      - run: ./scripts/test-gem-install gems

  cruby-x64-mingw32-install:
    needs: ["cruby-native-package"]
    strategy:
      fail-fast: false
      matrix:
        ruby: ["2.6", "2.7", "3.0"]
    runs-on: windows-latest
    steps:
      - uses: MSP-Greg/setup-ruby-pkgs@v1
        with:
          ruby-version: "${{matrix.ruby}}"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-x64-mingw32-gem
          path: gems
      - run: |
          gem install --verbose --no-document gems/*.gem
          gem list -d nokogiri
          nokogiri -v

  cruby-x64-mingw-ucrt-install:
    needs: ["cruby-native-package"]
    strategy:
      fail-fast: false
      matrix:
        ruby: ["3.1"]
    runs-on: windows-2022
    steps:
      - uses: MSP-Greg/setup-ruby-pkgs@v1
        with:
          ruby-version: "${{matrix.ruby}}"
      - uses: actions/download-artifact@v2
        with:
          name: cruby-x64-mingw-ucrt-gem
          path: gems
      - run: |
          gem install --verbose --no-document gems/*.gem
          gem list -d nokogiri
          nokogiri -v

  jruby-package:
    name: "jruby-package"
    runs-on: ubuntu-latest
    container:
      image: "larskanis/rake-compiler-dock-jruby:1.2.2"
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - run: ./scripts/test-gem-build gems java
      - uses: actions/upload-artifact@v2
        with:
          name: jruby-gem
          path: gems
          retention-days: 1

  jruby-install:
    needs: ["jruby-package"]
    strategy:
      fail-fast: false
      matrix:
        ruby: ["jruby-9.3", "jruby-head"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: "${{matrix.ruby}}"
      - uses: actions/download-artifact@v2
        with:
          name: jruby-gem
          path: gems
      - run: ./scripts/test-gem-install gems
