ropensci-review-tools / babelquarto

Renders a Multilingual Quarto Project (Book or Website)
https://docs.ropensci.org/babelquarto/
Other
40 stars 7 forks source link

Failed to render through Github Action. Error: unused argument (metadata = metadata) #45

Closed ntluong95 closed 4 months ago

ntluong95 commented 5 months ago

Hi Maëlle,

I am having a problem of rendering the book through Github Action. The book can be rendered locally without any error using function babelquarto::render_book(). However, when implementing on Github Action, I am encountering the following problem image

Could you please have a look to see what happened? Here is my github action

name: Render Book on PR to Main

on:
  workflow_dispatch:  # Allows the workflow to be triggered manually
  pull_request_target:
    types: [closed]
    branches:
      - main

jobs:
  setup-environment-packages:
    if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'handbook_v')
    runs-on: ubuntu-latest
    continue-on-error: true
    env:
      RENV_PATHS_ROOT: ~/.cache/R/renv
      R_LIBS_USER: ~/.cache/R/renv/Library
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Set up R
        uses: r-lib/actions/setup-r@v2
        with:
          r-version: '4.3.2'

      - name: Setup pandoc
        uses: r-lib/actions/setup-pandoc@v2

      - name: Install system dependencies and R packages
        run: |
          sudo apt-get update
          sudo apt-get install -y libcurl4-openssl-dev libxml2-dev libssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libglpk-dev r-cran-rjava r-base-dev openjdk-11-jdk gdal-bin libgdal-dev libxslt1-dev libgit2-dev libgeos-dev libproj-dev libudunits2-dev libcairo2-dev libxt-dev libmagick++-dev libpoppler-cpp-dev libpq-dev libmysqlclient-dev libsqlite3-dev libssh2-1-dev libgmp3-dev libmpfr-dev libprotobuf-dev protobuf-compiler libgl1-mesa-dev libglu1-mesa-dev libpoppler-glib-dev libtbb-dev libsodium-dev libv8-dev libnetcdf-dev netcdf-bin libjq-dev libharfbuzz-dev libfribidi-dev libnode-dev jq
          sudo R CMD javareconf

      - name: Set up renv
        uses: r-lib/actions/setup-renv@v2
        with:
          cache-version: 2

      - name: Install Bioconductor packages
        run: |
          Rscript -e 'install.packages("babelquarto", repos = c("https://ropensci.r-universe.dev", "https://cloud.r-project.org"))'   
          Rscript -e 'install.packages("babeldown", repos = c("https://ropensci.r-universe.dev", "https://cloud.r-project.org"))'   
          Rscript -e 'renv::snapshot()'                

      - name: Install quarto
        uses: quarto-dev/quarto-actions/setup@v2
        with:
          version: 1.4.550
      - name: Fix locale
        run: |
          export LANG=en_US.UTF-8
          export LC_CTYPE=en_US.UTF-8
          export LC_ALL=en_US.UTF-8

      - name: Render the book
        run: Rscript -e 'library(babelquarto); babelquarto::render_book()'
        continue-on-error: true

  render-and-publish:
    needs: setup-environment-packages
    runs-on: ubuntu-latest
    if: success()  
    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Commit results to main branch
        run: |
          git config --local user.email "actions@github.com"
          git config --local user.name "GitHub Actions"
          git add .
          git commit -m "CI added changes `date +'%Y-%m-%d %H:%M:%S'`" || echo "No changes to commit"
          git push origin || echo "No changes to commit"
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          branch: main
          github_token: ${{ secrets.GITHUB_TOKEN }}
          force: true

And here is my _quarto.yml

project:
  type: book
  output-dir: html_outputs

published-title: "Last updated"

# profile:
#   default: full
#   group: 
#     - [full, small]

book:
  title: "The Epidemiologist R Handbook"
  search:
    type: textbox
  repo-url: https://github.com/appliedepi/epihandbook_eng
  # site-url: https://epirhandbook.com
  sharing: ["twitter", "facebook", "linkedin"]
  sidebar:
        logo: "images/Applied_Epi_logo.png"
        tools:
                - icon: twitter
                  href: "https://twitter.com/appliedepi"
                - icon: linkedin
                  href: "https://www.linkedin.com/company/appliedepi/"
                # - icon: github
                #   menu:
                #         - text: Source Code
                #           url: "https://github.com/appliedepi/epihandbook_eng"
                #         - text: Report a Bug
                #           url: "https://github.com/appliedepi/epihandbook_eng/issues/new"

  date: today
  date-format: "MMM D, YYYY"
  favicon: "images/Applied_Epi_logo.png"
  cookie-consent:
    type: implied
    style: simple
    palette: dark
  google-analytics:
    tracking-id: "G-QXDW878QLX"
    storage: cookies
    anonymize-ip: true

  chapters:
  # INTRO & CONTRIBUTORS
  - index.qmd                              # objectives, how to read, authors, acknowledgements

  # ABOUT BOOK
  - part: "About this book"
    part-vn: "Về cuốn sách này"
    part-fr: "À propos de ce livre"
    part-es: "Acerca de este libro"
    part-jp: "本書について"
    part-tr: "Bu kitap hakkında"
    part-pt: "Sobre este livro"
    part-ru: "Об этой книге"
    part-de: "Über dieses Buch"
    chapters:
    - new_pages/editorial_style.qmd          # editorial style
    - new_pages/data_used.qmd                # data used

  # BASICS
  - part: "Basics"
    part-vn: "Nhập môn về R"
    part-fr: "Les bases de R"
    part-es: "Aspectos básicos"
    part-jp: "基本編"
    part-tr: "Temel Bilgiler"
    part-pt: "Básico"
    part-ru: "Основы"
    part-de: "Grundlagen"
    chapters:
    - new_pages/basics.qmd
    - new_pages/transition_to_R.qmd
    - new_pages/packages_suggested.qmd
    - new_pages/r_projects.qmd
    - new_pages/importing.qmd

  # DATA MANGEMENT
  - part: "Data Management"
    part-vn: "Quản lý dữ liệu"
    part-fr: "Gestion des données"
    part-es: "Gestión de datos"
    part-jp: "データマネジメント"
    part-tr: "Veri Yönetimi"
    part-pt: "Gerenciamento de Dados"
    part-ru: "Управление данными"
    part-de: "Datenmanagement"
    chapters:
    - new_pages/cleaning.qmd
    - new_pages/dates.qmd
    - new_pages/characters_strings.qmd
    - new_pages/factors.qmd
    - new_pages/pivoting.qmd
    - new_pages/grouping.qmd
    - new_pages/joining_matching.qmd
    - new_pages/deduplication.qmd
    - new_pages/iteration.qmd

  # ANALYSIS
  - part: "Analysis"
    part-vn: "Phân tích dữ liệu"
    part-fr: "Analyse"
    part-es: "Análisis"
    part-jp: "データ分析"
    part-tr: "Analiz"
    part-pt: "Análise dos Dados"
    part-ru: "Анализ"
    part-de: "Analyse"
    chapters:
    - new_pages/tables_descriptive.qmd
    - new_pages/stat_tests.qmd
    - new_pages/regression.qmd
    - new_pages/missing_data.qmd
    - new_pages/standardization.qmd
    - new_pages/moving_average.qmd
    - new_pages/time_series.qmd #done
    - new_pages/epidemic_models.qmd #done
    - new_pages/contact_tracing.qmd #done
    - new_pages/survey_analysis.qmd #done
    - new_pages/survival_analysis.qmd #done
    - new_pages/gis.qmd #done

  # DATA VIZ
  - part: "Data Visualization"
    part-vn: "Trực quan hóa dữ liệu"
    part-fr: "Visualisation des données"
    part-es: "Visualización de datos"
    part-jp: "データの可視化"
    part-tr: "Veri Görselleştirme"
    part-pt: "Visualização de Dados"
    part-ru: "Визуализация данных"
    part-de: "Datenvisualisierung"
    chapters:
    - new_pages/tables_presentation.qmd  #done
    - new_pages/ggplot_basics.qmd #done
    #new_pages/plot_continuous.qmd,
    #new_pages/plot_discrete.qmd,
    - new_pages/ggplot_tips.qmd #done
    - new_pages/epicurves.qmd #done
    - new_pages/age_pyramid.qmd #done
    - new_pages/heatmaps.qmd   #done
    - new_pages/diagrams.qmd  #done
    - new_pages/combination_analysis.qmd #done
    - new_pages/transmission_chains.qmd #done
    - new_pages/phylogenetic_trees.qmd #done
    - new_pages/interactive_plots.qmd #done

  # REPORTS AND DASHBOARDS
  - part: "Reports and dashboards"
    part-vn: "Báo cáo và dashboards"
    part-fr: "Rapports et tableaux de bord"
    part-es: "Informes y Dashboards"
    part-jp: "レポートとダッシュボード"
    part-tr: "Raporlar ve gösterge panoları"
    part-pt: "Relatórios e dashboards"
    part-ru: "Отчеты и информационные панели"
    part-de: "Berichte und Dashboards"
    chapters:
    - new_pages/rmarkdown.qmd #done
    - new_pages/reportfactory.qmd #done
    - new_pages/flexdashboard.qmd #done
    - new_pages/shiny_basics.qmd #done

  # MISCELLANEOUS
  - part: "Miscellaneous"
    part-vn: "Các chủ điểm khác"
    part-fr: "Autres sujets"
    part-es: "Miscelánea"
    part-jp: "その他"
    part-tr: "Çeşitli"
    part-pt: "Miscelânea"
    part-ru: "Разное"
    part-de: "Verschiedenes"
    chapters:
    - new_pages/writing_functions.qmd #done
    - new_pages/directories.qmd #done
    - new_pages/collaboration.qmd #done
    - new_pages/errors.qmd #done
    - new_pages/help.qmd #done
    #new_pages/relational_databases.qmd,
    - new_pages/network_drives.qmd #done
    - new_pages/data_table.qmd #done
    # new_pages/rstudio_advanced.qmd

lightbox: true # Lightbox images allow a reader to click to see a larger version of the image (including any caption)

babelquarto:
  languagecodes:
  - name: vn
    text: "Tiếng Việt"
  - name: fr
    text: "Français"
  - name: es
    text: "Español"
  - name: jp
    text: "日本"
  - name: tr
    text: "Türkçe"
  - name: pt
    text: "Português"
  - name: ru
    text: "Русский"
  - name: de
    text: "Deutsch"
  - name: en
    text: "English"

  mainlanguage: 'en'
  languages: ['fr', 'es', 'vn', 'jp', 'pt', 'tr', 'ru']  #'de'  fr

title-vn: Cẩm nang dịch tễ học với R
title-fr: Le Epi R Handbook
title-es: EpiRhandbook en español
title-jp: 疫学のための R ハンドブック
title-tr: Epidemiyologun R Rehberi
title-pt: Manual de R para Epidemiologistas
title-ru: Справочник эпидемиолога R
title-de: EpiRhandbook auf Deutsch

lang: en

format:
  html: 
    include-in-header:
      - banner.html
    theme:
      light: cosmo
      dark: [darkly, theme-dark.scss] #superhero
maelle commented 5 months ago

On that CI build, are you using the latest versions of Quarto CLI and the R quarto package?

ntluong95 commented 5 months ago

Hi found the problem. It is due to yaml::read_yaml() function using readLines() function so special non UTF-8 characters from _quarto.yml were not parsed properly. I changed readLines() to readr::read_lines() and it solved the problem

maelle commented 5 months ago

Where was that code exactly?

ntluong95 commented 5 months ago

image

Hi, the one I am highlighting. Also, I just remembered that I also need to remove argument metadata in the function quarto::quarto_render(as_job = FALSE, metadata = metadata), not sure why but after removing it, I can run the code

maelle commented 5 months ago

wait so are you using a fork of the yaml package?

maybe there's an argument of that yaml function that we could use here?

maelle commented 5 months ago

or could you save your Quarto metadata with UTF8 encoding?

ntluong95 commented 5 months ago

save Quarto metadata with UTF-8 encoding does not help. What I did was re-defining render_book() function, in which I changed readLines() to readr::read_lines() when re-defining yaml::read_yaml() function, also I removed metadata = metadata argument in quarto::quarto_render() function

maelle commented 5 months ago

Could you share an example config that leads to this problem, maybe built from the example book of babelquarto? This way I could try and solve it on babelquarto's slide so you don't have to maintain a fork of babelquarto.

maelle commented 4 months ago

please open a new issue if you can share an example config :smile_cat: