1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-16 23:08:36 +02:00
comprehensive-rust/.github/workflows/build.yml
Jooyung Han 1821a3fd12
Make i18n-helpers a requirement (#461)
* Make i18n-helpers a requirement

* Skip mdbook-gettext for mdbook-xgettext

* Gettext finds PO file based on `book.language`

* Update workflow

No need to set `preprocessor.gettext.po-file`.

---------

Co-authored-by: Jooyung Han <jooyung@google.com>
2023-02-28 22:05:09 +09:00

134 lines
3.4 KiB
YAML

name: Test
on:
pull_request:
push:
branches:
- main
env:
CARGO_TERM_COLOR: always
jobs:
mdbook:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
- name: Install mdbook
uses: ./.github/workflows/install-mdbook
- name: Test code snippets
run: mdbook test
cargo:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
- name: Build Rust code
run: cargo build
- name: Test Rust code
run: cargo test
i18n-helpers:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
- name: Install Gettext
run: sudo apt install gettext
- name: Install mdbook
uses: ./.github/workflows/install-mdbook
- name: Generate po/messages.pot
run: mdbook build -d po
env:
MDBOOK_OUTPUT: '{"xgettext": {"pot-file": "messages.pot"}}'
- name: Test messages.pot
run: msgfmt --statistics -o /dev/null po/messages.pot
- name: Expand includes without translation
run: mdbook build -d expanded
env:
MDBOOK_OUTPUT: '{"markdown": {}}'
- name: Expand includes with no-op translation
run: mdbook build -d no-op
env:
MDBOOK_OUTPUT: '{"markdown": {}}'
MDBOOK_PREPROCESSOR__GETTEXT__PO_FILE: po/messages.pot
- name: Compare no translation to no-op translation
run: diff --color=always --unified --recursive expanded no-op
find-translations:
runs-on: ubuntu-latest
outputs:
languages: ${{ steps.find-translations.outputs.languages }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Find translations
id: find-translations
shell: python
run: |
import os, json, pathlib
languages = [p.stem for p in pathlib.Path("po").iterdir() if p.suffix == ".po"]
github_output = open(os.environ["GITHUB_OUTPUT"], "a")
github_output.write("languages=")
json.dump(sorted(languages), github_output)
translations:
runs-on: ubuntu-latest
needs:
- find-translations
strategy:
matrix:
language: ${{ fromJSON(needs.find-translations.outputs.languages) }}
env:
MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
- name: Install Gettext
run: sudo apt install gettext
- name: Install mdbook
uses: ./.github/workflows/install-mdbook
- name: Test ${{ matrix.language }} translation
run: msgfmt --statistics -o /dev/null po/${{ matrix.language }}.po
- name: Build course with ${{ matrix.language }} translation
run: mdbook build
- name: Upload ${{ matrix.language }} translation
uses: actions/upload-artifact@v3
with:
name: comprehensive-rust-${{ matrix.language }}
path: book/
- name: Test code snippets with ${{ matrix.language }} translation
run: mdbook test