mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-16 14:53:28 +02:00
aaca44f62b
The dprint formatter is a flexible system which will use sandboxed WebAssembly formatters to format our code (mostly: it calls out to `rustfmt` for Rust code). A particularly interesting feature is that dprint can format Rust code blocks in the Markdown files. However, before we turn that on, we need to have a way to normalize the Markdown text as it is extracted[1]. That is so that the word put into the translations is kept after the reformatting. [1]: https://github.com/google/mdbook-i18n-helpers/issues/19
144 lines
3.7 KiB
YAML
144 lines
3.7 KiB
YAML
name: Test
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
|
|
jobs:
|
|
format:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Install nightly rustfmt
|
|
run: |
|
|
rustup default nightly
|
|
rustup component add rustfmt
|
|
|
|
- name: Check formatting
|
|
uses: dprint/check@v2.2
|
|
|
|
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
|
|
|
|
bare-metal:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- directory: src/bare-metal/alloc-example
|
|
target: aarch64-unknown-none
|
|
- directory: src/bare-metal/aps/examples
|
|
target: aarch64-unknown-none
|
|
- directory: src/bare-metal/microcontrollers/examples
|
|
target: thumbv7em-none-eabihf
|
|
- directory: src/exercises/bare-metal/compass
|
|
target: thumbv7em-none-eabihf
|
|
- directory: src/exercises/bare-metal/rtc
|
|
target: aarch64-unknown-none
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Setup Rust cache
|
|
uses: ./.github/workflows/setup-rust-cache
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
sudo apt update
|
|
sudo apt install gcc-aarch64-linux-gnu
|
|
|
|
- name: Install toolchain
|
|
run: rustup target add ${{ matrix.target }}
|
|
|
|
- name: Build Rust code
|
|
working-directory: ${{ matrix.directory }}
|
|
run: cargo build
|
|
|
|
find-languages:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
languages: ${{ steps.find-languages.outputs.languages }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Find languages
|
|
id: find-languages
|
|
shell: python
|
|
run: |
|
|
import os, json, pathlib
|
|
languages = ["en"] + [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)
|
|
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- find-languages
|
|
strategy:
|
|
matrix:
|
|
language: ${{ fromJSON(needs.find-languages.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
|
|
if: matrix.language != 'en'
|
|
run: |
|
|
sudo apt update
|
|
sudo apt install gettext
|
|
|
|
- name: Install mdbook
|
|
uses: ./.github/workflows/install-mdbook
|
|
|
|
- name: Test ${{ matrix.language }} translation
|
|
if: matrix.language != 'en'
|
|
run: msgfmt --statistics -o /dev/null po/${{ matrix.language }}.po
|
|
|
|
- name: Build course
|
|
run: mdbook build
|
|
|
|
- name: Zip exercise templates
|
|
run: zip --recurse-paths ../html/comprehensive-rust-exercises.zip comprehensive-rust-exercises/
|
|
working-directory: book/exerciser
|
|
|
|
- name: Prepare book for upload
|
|
run: |
|
|
mv book/html book/comprehensive-rust-${{ matrix.language }}
|
|
rm -r book/exerciser
|
|
|
|
# Upload the book now to retain it in case mdbook test fails.
|
|
- name: Upload book
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: comprehensive-rust-${{ matrix.language }}
|
|
path: book/
|
|
|
|
- name: Test code snippets
|
|
run: mdbook test
|