###############################################################################
# .github/workflows/tests.yml
#
# NOTE: GitHub Actions does not allocate a TTY, preventing `nb` from detecting
# piped input using `[[ -t 0 ]]` in the `_interactive_input()` function.
#
# More information:
#
# https://github.com/actions/runner/issues/241
#
# faketty is a GitHub action that uses work-arounds to provide a tty:
#
# https://github.com/marketplace/actions/faketty
#
# Scripts used by faketty for each platform:
#
# linux: `faketty`
#
# ```bash
# #!/bin/bash
#
# script -q -e -c "$*"
# ```
#
# win32: `faketty.ps1`
#
# ```posh
# Invoke-Expression "$args"
# ```
#
# darwin: `faketty`
#
# requires: `brew install expect`
#
# ```bash
# #!/bin/bash
#
# unbuffer $*
# ```
###############################################################################

name: "nb · Test Suite"

on:
  pull_request:
    branches: [ master ]
  # push:
  #   branches: [ master ]
  workflow_dispatch:

jobs:
  # test-ubuntu-aarch64:
  #   name: "Test: Ubuntu AArch64"
  #   runs-on: ubuntu-20.04
  #   steps:
  #     - uses: actions/checkout@v2.1.0
  #     - uses: uraimo/run-on-arch-action@v2
  #       # https://github.com/marketplace/actions/run-on-architecture
  #       name: Run commands
  #       id: runcmd
  #       with:
  #         arch:   aarch64
  #         distro: ubuntu20.04

  #         # Not required, but speeds up builds by storing container images in
  #         # a GitHub package registry.
  #         # githubToken: ${{ github.token }}

  #         # Set an output parameter `uname` for use in subsequent steps
  #         run: |
  #           uname -a
  #           echo ::set-output name=uname::$(uname -a)
  #     - name: "Setup"
  #       run: |
  #         sudo apt-get update
  #         sudo apt-get install bats -y
  #         sudo apt-get install ncat -y
  #         sudo apt-get install python-pygments -y
  #         sudo apt-get install w3m  -y
  #         curl -LO https://github.com/jgm/pandoc/releases/download/2.17.0.1/pandoc-2.17.0.1-1-amd64.deb
  #         sudo dpkg -i pandoc-2.17.0.1-1-amd64.deb
  #         curl -LO https://github.com/sharkdp/bat/releases/download/v0.16.0/bat_0.16.0_amd64.deb
  #         sudo dpkg -i bat_0.16.0_amd64.deb
  #         git config --global user.name   "Example Name"
  #         git config --global user.email  "example@example.com"
  #     - name: "Install bats-core"
  #       run: |
  #         git clone https://github.com/bats-core/bats-core.git "${HOME}/bats-core" &&
  #           cd "${HOME}/bats-core"
  #         git checkout 2e2e5df6adf0b846b411b6b2f7bb654cbc3e2c4e
  #         sudo ./install.sh /usr/local
  #     - name: "Set $TERM=xterm"
  #       run:  printf "TERM=xterm\\n" >> $GITHUB_ENV
  #     - name: "Run bats tests"
  #       run:  script -q -e -c "bats test/bookmark.bats"
  #     # - name: "Install Go"
  #     #   uses: actions/setup-go@v2
  #     # - name: "Run go test"
  #     #   run: cd nb.go && go test
  #     # - name: "Run nb.go bats tests"
  #     #   run:  script -q -e -c "bats test"

  # test-ubuntu-armv7:
  #   name: "Test: Ubuntu armv7"
  #   runs-on: ubuntu-20.04
  #   steps:
  #     - uses: actions/checkout@v2.1.0
  #     - uses: uraimo/run-on-arch-action@v2
  #       # https://github.com/marketplace/actions/run-on-architecture
  #       name: Run commands
  #       id: runcmd
  #       with:
  #         arch:   armv7
  #         distro: ubuntu20.04

  #         # Not required, but speeds up builds by storing container images in
  #         # a GitHub package registry.
  #         # githubToken: ${{ github.token }}

  #         # Set an output parameter `uname` for use in subsequent steps
  #         run: |
  #           uname -a
  #           echo ::set-output name=uname::$(uname -a)
  #     - name: "Setup"
  #       run: |
  #         sudo apt-get update
  #         sudo apt-get install bats -y
  #         sudo apt-get install ncat -y
  #         sudo apt-get install python-pygments -y
  #         sudo apt-get install w3m  -y
  #         curl -LO https://github.com/jgm/pandoc/releases/download/2.17.0.1/pandoc-2.17.0.1-1-amd64.deb
  #         sudo dpkg -i pandoc-2.17.0.1-1-amd64.deb
  #         curl -LO https://github.com/sharkdp/bat/releases/download/v0.16.0/bat_0.16.0_amd64.deb
  #         sudo dpkg -i bat_0.16.0_amd64.deb
  #         git config --global user.name   "Example Name"
  #         git config --global user.email  "example@example.com"
  #     - name: "Install bats-core"
  #       run: |
  #         git clone https://github.com/bats-core/bats-core.git "${HOME}/bats-core" &&
  #           cd "${HOME}/bats-core"
  #         git checkout 2e2e5df6adf0b846b411b6b2f7bb654cbc3e2c4e
  #         sudo ./install.sh /usr/local
  #     - name: "Set $TERM=xterm"
  #       run:  printf "TERM=xterm\\n" >> $GITHUB_ENV
  #     - name: "Run bats tests"
  #       run:  script -q -e -c "bats test/bookmark.bats"
  #     # - name: "Install Go"
  #     #   uses: actions/setup-go@v2
  #     # - name: "Run go test"
  #     #   run: cd nb.go && go test
  #     # - name: "Run nb.go bats tests"
  #     #   run:  script -q -e -c "bats test"

  test-macos-14:
    name: "Test: macOS 14 Sonoma"
    runs-on: macos-14
    steps:
      - uses: actions/checkout@v4
      - name: "Setup"
        run: |
          brew update
          brew install bat
          brew install bats-core
          brew install expect
          brew install gpg
          brew install nmap
          brew install pandoc
          brew install ripgrep
          brew install w3m
          gem install asciidoctor
          git config --global user.name   "Example Name"
          git config --global user.email  "example@example.com"
      - uses: browser-actions/setup-chrome@v1
        id: setup-chrome
      - run: |
          ${{ steps.setup-chrome.outputs.chrome-path }} --version
      - name: "Set $TERM=xterm"
        run:  printf "TERM=xterm\\n" >> $GITHUB_ENV
      - name: "Run bats tests"
        run:  unbuffer bats test
      # - name: "Install Go"
      #   uses: actions/setup-go@v2
      # - name: "Run go test"
      #   run: cd nb.go && go test
      # - name: "Run nb.go bats test"
      #   run: unbuffer bats test
  # test-macos-12:
  #   name: "Test: macOS 12 Monterey"
  #   runs-on: macos-12
  #   steps:
  #     - uses: actions/checkout@v3
  #     - name: "Setup"
  #       run: |
  #         brew update
  #         brew install bat
  #         brew install bats-core
  #         brew install expect
  #         brew install gpg
  #         brew install nmap
  #         brew install pandoc
  #         brew install ripgrep
  #         brew install w3m
  #         gem install asciidoctor
  #         git config --global user.name   "Example Name"
  #         git config --global user.email  "example@example.com"
  #     - uses: browser-actions/setup-chrome@v1
  #       id: setup-chrome
  #     - run: |
  #         ${{ steps.setup-chrome.outputs.chrome-path }} --version
  #     - name: "Set $TERM=xterm"
  #       run:  printf "TERM=xterm\\n" >> $GITHUB_ENV
  #     - name: "Run bats tests"
  #       run:  unbuffer bats test
  #     # - name: "Install Go"
  #     #   uses: actions/setup-go@v2
  #     # - name: "Run go test"
  #     #   run: cd nb.go && go test
  #     # - name: "Run nb.go bats test"
  #     #   run: unbuffer bats test
  # test-macos-11:
  #   name: "Test: macOS Big Sur 11.0"
  #   runs-on: macos-11.0
  #   steps:
  #     - uses: actions/checkout@v3
  #     - name: "Setup"
  #       run: |
  #         brew update
  #         brew install bat
  #         brew install bats-core
  #         brew install expect
  #         brew install gpg
  #         brew install nmap
  #         brew install pandoc
  #         brew install ripgrep
  #         brew install w3m
  #         gem install asciidoctor
  #         git config --global user.name   "Example Name"
  #         git config --global user.email  "example@example.com"
  #     - name: "Set $TERM=xterm"
  #       run:  printf "TERM=xterm\\n" >> $GITHUB_ENV
  #     - name: "Run bats tests"
  #       run:  unbuffer bats test
  #     # - name: "Install Go"
  #     #   uses: actions/setup-go@v2
  #     # - name: "Run go test"
  #     #   run: cd nb.go && go test
  #     # - name: "Run nb.go bats test"
  #     #   run: unbuffer bats test
  # test-macos-10-15:
  #   name: "Test: macOS Catalina 10.15"
  #   runs-on: macos-10.15
  #   steps:
  #     - uses: actions/checkout@v1
  #     - name: "Setup"
  #       run: |
  #         brew update
  #         brew install bat
  #         brew unlink  bats
  #         brew install bats-core
  #         brew install expect
  #         brew install gpg
  #         brew install nmap
  #         brew install pandoc
  #         brew install w3m
  #         git config --global user.name   "Example Name"
  #         git config --global user.email  "example@example.com"
  #     - name: "Set $TERM=xterm"
  #       run:  printf "TERM=xterm\\n" >> $GITHUB_ENV
  #     - name: "Run bats tests"
  #       run:  unbuffer bats test
  #     # - name: "Install Go"
  #     #   uses: actions/setup-go@v2
  #     # - name: "Run go test"
  #     #   run: cd nb.go && go test
  #     # - name: "Run nb.go bats test"
  #     #   run: unbuffer bats test
  test-ubuntu-2404:
    name: "Test: Ubuntu 24.04"
    runs-on: ubuntu-24.04
    env:
      LANG: C.UTF-8
      LC_ALL: C.UTF-8
      LC_TYPE: C.UTF-8
    steps:
      - uses: actions/checkout@v1
      - name: "Setup"
        run: |
          sudo apt-get update
          sudo apt-get install bats -y
          sudo apt-get install ncat -y
          sudo apt-get install python3-pygments -y
          sudo apt-get install ripgrep -y
          sudo apt-get install w3m -y
          curl -LO https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-amd64.deb
          sudo dpkg -i pandoc-3.2-1-amd64.deb
          curl -LO https://github.com/sharkdp/bat/releases/download/v0.24.0/bat_0.24.0_amd64.deb
          sudo dpkg -i bat_0.24.0_amd64.deb
          sudo gem install asciidoctor
          git config --global user.name   "Example Name"
          git config --global user.email  "example@example.com"
      - uses: browser-actions/setup-chrome@v1
        id: setup-chrome
      - run: |
          ${{ steps.setup-chrome.outputs.chrome-path }} --version
      - name: "Set $TERM=xterm"
        run:  printf "TERM=xterm\\n" >> $GITHUB_ENV
      - name: "Print encoding variables"
        run: |
          echo "'$LANG'"
          echo "'$LC_ALL'"
          echo "'$LC_TYPE'"
      - name: "Run bats tests"
        run:  script -q -e -c "bats test"
      # - name: "Install Go"
      #   uses: actions/setup-go@v2
      # - name: "Run go test"
      #   run: cd nb.go && go test
      # - name: "Run nb.go bats tests"
      #   run:  script -q -e -c "bats test"
