1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-07 10:06:22 +02:00

Simplify GitHub actions (#621)

* 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: https://github.com/actions-rs/toolchain/issues/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.
This commit is contained in:
Martin Geisler 2023-05-08 16:32:25 +02:00 committed by GitHub
parent 661f51b06b
commit e19fc8bfd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,23 +10,7 @@ env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
jobs: 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: format:
name: Format
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
@ -51,7 +35,6 @@ jobs:
run: cargo test run: cargo test
bare-metal: bare-metal:
name: Build bare-metal Rust examples
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
@ -77,40 +60,37 @@ jobs:
run: sudo apt update && sudo apt install gcc-aarch64-linux-gnu run: sudo apt update && sudo apt install gcc-aarch64-linux-gnu
- name: Install toolchain - name: Install toolchain
uses: actions-rs/toolchain@v1 run: rustup target add ${{ matrix.target }}
with:
toolchain: stable
target: ${{ matrix.target }}
- name: Build Rust code - name: Build Rust code
working-directory: ${{ matrix.directory }} working-directory: ${{ matrix.directory }}
run: cargo build run: cargo build
find-translations: find-languages:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
languages: ${{ steps.find-translations.outputs.languages }} languages: ${{ steps.find-languages.outputs.languages }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Find translations - name: Find languages
id: find-translations id: find-languages
shell: python shell: python
run: | run: |
import os, json, pathlib 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 = open(os.environ["GITHUB_OUTPUT"], "a")
github_output.write("languages=") github_output.write("languages=")
json.dump(sorted(languages), github_output) json.dump(sorted(languages), github_output)
translations: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: needs:
- find-translations - find-languages
strategy: strategy:
matrix: matrix:
language: ${{ fromJSON(needs.find-translations.outputs.languages) }} language: ${{ fromJSON(needs.find-languages.outputs.languages) }}
env: env:
MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }} MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }}
steps: steps:
@ -121,25 +101,34 @@ jobs:
uses: ./.github/workflows/setup-rust-cache uses: ./.github/workflows/setup-rust-cache
- name: Install Gettext - name: Install Gettext
if: matrix.language != 'en'
run: sudo apt install gettext run: sudo apt install gettext
- name: Install mdbook - name: Install mdbook
uses: ./.github/workflows/install-mdbook uses: ./.github/workflows/install-mdbook
- name: Test ${{ matrix.language }} translation - name: Test ${{ matrix.language }} translation
if: matrix.language != 'en'
run: msgfmt --statistics -o /dev/null po/${{ matrix.language }}.po run: msgfmt --statistics -o /dev/null po/${{ matrix.language }}.po
- name: Build course with ${{ matrix.language }} translation - name: Build course
run: mdbook build run: mdbook build
- name: Zip exercise templates for ${{ matrix.language }} translation - name: Zip exercise templates
run: cd book/exerciser && zip --recurse-paths ../html/comprehensive-rust-exercises.zip comprehensive-rust-exercises/ run: zip --recurse-paths ../html/comprehensive-rust-exercises.zip comprehensive-rust-exercises/
working-directory: book/exerciser
- name: Upload ${{ matrix.language }} translation - 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 uses: actions/upload-artifact@v3
with: with:
name: comprehensive-rust-${{ matrix.language }} name: comprehensive-rust-${{ matrix.language }}
path: book/ path: book/
- name: Test code snippets with ${{ matrix.language }} translation - name: Test code snippets
run: mdbook test run: mdbook test