name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  workflow_dispatch:
  
env:
  ACTIONS_ALLOW_UNSECURE_COMMANDS: true
  OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

jobs:
  testing:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: install python 3.9 
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
          cache: 'pip' # caching pip dependencies
      - name: Check formatting (black)
        run: |
            pip install black
            black . --check
      - name: install python requirements
        run: pip install -r requirements.txt
      
      - name: make normal ebook test using google translate 
        run: |
            python3 make_book.py --book_name "test_books/Liber_Esther.epub" --no_limit --test --test_num 10 --model google --translate-tags div,p
            python3 make_book.py --book_name "test_books/Liber_Esther.epub" --no_limit --test --test_num 20 --model google

      - name: make openai key ebook test
        if: env.OPENAI_API_KEY != null
        run: |
            python3 make_book.py --book_name "test_books/lemo.epub" --no_limit --test --test_num 5 --language zh-hans
            python3 make_book.py --book_name "test_books/animal_farm.epub" --no_limit --test --test_num 5 --language ja --model gpt3
            
            
      - name: Rename and Upload ePub
        if: env.OPENAI_API_KEY != null
        uses: actions/upload-artifact@v2
        with:
          name: epub_output
          path: "test_books/lemo_bilingual.epub"

