Skip to content

Commit

Permalink
Simplify GitHub actions (#621)
Browse files Browse the repository at this point in the history
* Remove unnecessary jobs names

They are inconsistent with the rest of the jobs and they overflow the
horizontal space in the GitHub UI.

* Remove unnecessary toolchain action

The GitHub runners include rustup and a recent stable Rust. We only
need to add the necessary target and we’re good to go.

This removes a lot of warnings because the action used an outdated
GitHub API: actions-rs/toolchain#219

* Simplify job name

The job is testing a single translation, so it should be singular.

* Test English source with translations

This simplifies the workflow a little and ensures that we get
artifacts uploaded of the English version for every PR.

* Avoid shell command chain

GitHub actions supports setting the working directory directly.

* Upload only the book artifact

Right now, the artifacts all contain the same two top-level folders:
html/ and exerciser/. The former is what we actually deploy, the
second is a side-effect of the exerciser plugin.

With this change, we only upload the HTML and we ensure the zip file
for the xx language has a top-level comprehensive-rust-xx/ folder.
This makes it much nicer to use the generated artifacts.
  • Loading branch information
mgeisler authored May 8, 2023
1 parent 661f51b commit e19fc8b
Showing 1 changed file with 23 additions and 34 deletions.
57 changes: 23 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,7 @@ 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

format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -51,7 +35,6 @@ jobs:
run: cargo test

bare-metal:
name: Build bare-metal Rust examples
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -77,40 +60,37 @@ jobs:
run: sudo apt update && sudo apt install gcc-aarch64-linux-gnu

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}

- name: Build Rust code
working-directory: ${{ matrix.directory }}
run: cargo build

find-translations:
find-languages:
runs-on: ubuntu-latest
outputs:
languages: ${{ steps.find-translations.outputs.languages }}
languages: ${{ steps.find-languages.outputs.languages }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Find translations
id: find-translations
- name: Find languages
id: find-languages
shell: python
run: |
import os, json, pathlib
languages = [p.stem for p in pathlib.Path("po").iterdir() if p.suffix == ".po"]
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)
translations:
build:
runs-on: ubuntu-latest
needs:
- find-translations
- find-languages
strategy:
matrix:
language: ${{ fromJSON(needs.find-translations.outputs.languages) }}
language: ${{ fromJSON(needs.find-languages.outputs.languages) }}
env:
MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }}
steps:
Expand All @@ -121,25 +101,34 @@ jobs:
uses: ./.github/workflows/setup-rust-cache

- name: Install Gettext
if: matrix.language != 'en'
run: 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 with ${{ matrix.language }} translation
- name: Build course
run: mdbook build

- name: Zip exercise templates for ${{ matrix.language }} translation
run: cd book/exerciser && zip --recurse-paths ../html/comprehensive-rust-exercises.zip comprehensive-rust-exercises/
- 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
- name: Upload ${{ matrix.language }} translation
# 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 with ${{ matrix.language }} translation
- name: Test code snippets
run: mdbook test

0 comments on commit e19fc8b

Please sign in to comment.