-
Notifications
You must be signed in to change notification settings - Fork 1.7k
198 lines (163 loc) · 5.27 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Test
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install formatting dependencies
run: |
sudo apt update
sudo apt install gettext yapf3
- name: Install nightly rustfmt
run: |
rustup default nightly
rustup component add rustfmt
- name: Check formatting
uses: dprint/check@v2.2
typos:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for typos
uses: crate-ci/typos@v1.24.1
with:
config: ./.github/typos.toml
cargo:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- 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@v4
- 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@v4
- 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) }}
fail-fast: false
env:
# Opt-in for checking links in translations - add the language below.
LINK_CHECKED_LANGUAGES: '["en", "fa"]'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # We need the full history for build.sh below.
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
with:
key: ${{ contains(fromJSON(env.LINK_CHECKED_LANGUAGES), matrix.language) }}
- name: Install Gettext
run: |
sudo apt update
sudo apt install gettext
- name: Install mdbook
uses: ./.github/workflows/install-mdbook
- name: Test format of ${{ matrix.language }} translation
if: matrix.language != 'en'
run: msgfmt --statistics -o /dev/null po/${{ matrix.language }}.po
- name: Test extracting English strings
if: matrix.language == 'en'
run: |
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' mdbook build -d po
msgfmt -o /dev/null --statistics po/messages.pot
- name: Install mdbook-linkcheck
if: contains(fromJSON(env.LINK_CHECKED_LANGUAGES), matrix.language)
run: cargo install mdbook-linkcheck --locked --version 0.7.7
- name: Build ${{ matrix.language }} translation
run: |
.github/workflows/build.sh ${{ matrix.language }} book/comprehensive-rust-${{ matrix.language }}
# Upload the book now to retain it in case mdbook test fails.
- name: Upload book
uses: actions/upload-artifact@v4
with:
name: comprehensive-rust-${{ matrix.language }}
path: book/
- name: Test code snippets
env:
MDBOOK_BOOK__LANGUAGE: ${{ matrix.language }}
run: mdbook test
po-diff:
name: Translation diff
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
- name: Install mdbook
uses: ./.github/workflows/install-mdbook
- name: Copy latest version of translations
run: cp -r po new-po
- name: Checkout base version
run: git checkout ${{ github.event.pull_request.base.sha }}
- name: Translation diff
run: i18n-report diff po/ new-po/ > $GITHUB_STEP_SUMMARY