update workflow file #99
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Book with Babel Quarto | |
on: | |
pull_request: | |
branches: | |
- crowdin_integration | |
push: | |
branches: | |
- crowdin_integration | |
workflow_dispatch: | |
env: | |
PR_AUTHOR_EMAIL: molunorichie@gmail.com | |
PR_AUTHOR_NAME: Richie | |
NEW_BRANCH: build_book- | |
DESTINATION_BRANCH: book | |
CONFIG_PATH: ./config.json # Path to config file for jsquarto | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: true | |
- name: Setup R and Node.js | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y r-base r-base-core libssl-dev libcurl4-openssl-dev libxml2-dev | |
npm install -g npm@latest | |
- name: Extract config variables from config file | |
id: read_config | |
run: | | |
JSON_FILE="$CONFIG_PATH" | |
JSON_CONTENT=$(cat "$JSON_FILE") | |
LANGUAGES=$(echo "$JSON_CONTENT" | jq -r '.languages | join(",")') | |
OUTPUT_DIR=$(echo "$JSON_CONTENT" | jq -r '.outputDirectory') | |
SOURCE_DIR=$(echo "$JSON_CONTENT" | jq -r '.sourceDirectory') | |
TUTORIALS_DIR=$(echo "$JSON_CONTENT" | jq -r '.tutorialDirectory') | |
echo "LANGUAGES=$LANGUAGES" >> $GITHUB_ENV | |
echo "OUTPUT_DIR=$OUTPUT_DIR" >> $GITHUB_ENV | |
echo "SOURCE_DIR=$SOURCE_DIR" >> $GITHUB_ENV | |
echo "TUTORIALS_DIR=$TUTORIALS_DIR" >> $GITHUB_ENV | |
install_dependencies: | |
runs-on: ubuntu-latest | |
needs: setup | |
steps: | |
- name: Setup quarto | |
uses: quarto-dev/quarto-actions/setup@v2 | |
- name: Install PAK | |
run: Rscript -e "install.packages('pak', lib='./my_R_library')" | |
- name: Install Babel quarto | |
run: Rscript -e ".libPaths(c('./my_R_library', .libPaths())); library(pak); pak::pak('ropensci-review-tools/babelquarto', lib='./my_R_library')" | |
- name: Install Node.js dependencies | |
run: npm install | |
prepare_translations: | |
runs-on: ubuntu-latest | |
needs: [setup, install_dependencies] | |
steps: | |
- name: Prepare crowdin translations | |
run: npm run fix:crowdin_files languages="$LANGUAGES" | |
build_book: | |
runs-on: ubuntu-latest | |
needs: [setup, install_dependencies, prepare_translations] | |
steps: | |
- name: Build book | |
run: | | |
Rscript -e ".libPaths(c('./my_R_library', .libPaths())); library(babelquarto); project_dir <- '$OUTPUT_DIR'; babelquarto::render_book(project_path = project_dir)" | |
- name: Fix built book | |
run: | | |
tree docs | |
npm run fix:all languages="$LANGUAGES" | |
merge_updates: | |
runs-on: ubuntu-latest | |
needs: build_book | |
steps: | |
- name: Commit changes | |
run: | | |
git config --global user.email $PR_AUTHOR_EMAIL | |
git config --global user.name $PR_AUTHOR_NAME | |
git checkout -b $NEW_BRANCH | |
git status | |
git add . | |
git commit -m "Build book with babelquarto" | |
git push origin $NEW_BRANCH | |
- name: Create Pull Request | |
id: create_pr | |
uses: repo-sync/pull-request@v2 | |
with: | |
source_branch: ${{ env.NEW_BRANCH }} | |
destination_branch: ${{ env.DESTINATION_BRANCH }} | |
pr_title: New book build with babelquarto | |
pr_body: | | |
:crown: *An automated PR* | |
Automated PR build book with babel-quarto | |
_Created by [repo-sync/pull-request](https://github.com/repo-sync/pull-request)_ | |
pr_label: "auto-pr" | |
pr_draft: false | |
pr_allow_empty: true | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Approve pull Request | |
if: steps.create_pr.outputs.pull_request_number | |
uses: hmarr/auto-approve-action@v2 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
pull-request-number: ${{ steps.create_pr.outputs.pull_request_number }} |