Skip to content

Commit 37704c6

Browse files
committed
workflow: Introduce CI workflow for pre-commit checks
Introduce a GitHub Actions workflow that performs pre-commit checks, including build and test steps to ensure code quality before merging. Signed-off-by: Steven Lee <steven_lee@aspeedtech.com>
1 parent 6d89d61 commit 37704c6

File tree

5 files changed

+117
-7
lines changed

5 files changed

+117
-7
lines changed

.github/rust-toolchain.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Licensed under the Apache-2.0 license
2+
3+
[toolchain]
4+
channel = "1.85.1"
5+
components = ["rustfmt", "clippy"] # Add any additional components you need
6+
profile = "minimal" # Optional: You can set this to "minimal", "default", or "complete"

.github/workflows/build-test.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Licensed under the Apache-2.0 license
2+
3+
name: Build and Test
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
13+
jobs:
14+
precommit:
15+
runs-on: ubuntu-22.04
16+
17+
env:
18+
CARGO_INCREMENTAL: 0
19+
SCCACHE_VERSION: 0.8.2
20+
SCCACHE_GHA_CACHE_TO: sccache-aspeed-ddk
21+
SCCACHE_GHA_CACHE_FROM: sccache-aspeed-ddk
22+
SCCACHE_C_CUSTOM_CACHE_BUSTER: a1b2c3d4e5
23+
EXTRA_CARGO_CONFIG: "target.'cfg(all())'.rustflags = [\"-Dwarnings\"]"
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
submodules: recursive
30+
31+
- name: Install packages
32+
run: |
33+
sudo apt-get update -qq
34+
sudo apt-get install -y build-essential curl gcc-arm-none-eabi llvm clang pkg-config libudev-dev
35+
rustup component add clippy rustfmt llvm-tools-preview
36+
37+
- name: Install sccache
38+
uses: mozilla-actions/sccache-action@v0.0.1
39+
with:
40+
version: ${{ env.SCCACHE_VERSION }}
41+
42+
- name: Configure sccache
43+
run: |
44+
echo "RUSTC_WRAPPER=$(which sccache)" >> $GITHUB_ENV
45+
46+
- name: Verify Cargo.lock is up to date
47+
run: |
48+
cargo tree --locked > /dev/null || (
49+
echo "Please update Cargo.lock"
50+
cargo tree
51+
git diff Cargo.lock
52+
exit 1
53+
)
54+
55+
- name: Run precommit checks (build/format/lint)
56+
run: |
57+
cargo --config "$EXTRA_CARGO_CONFIG" xtask precommit
58+
59+
- name: Show sccache stats
60+
run: sccache --show-stats
61+

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ version = "0.1.0"
1515
edition = "2021"
1616

1717
[features]
18+
default = []
1819
std = []
20+
test-rsa = []
21+
test-ecdsa = []
22+
test-hmac = []
23+
test-hash = []
1924

2025
[dependencies]
2126
ast1060-pac = { git = "https://github.com/rusty1968/ast1060-pac.git", features = ["rt"] }
@@ -30,5 +35,3 @@ cortex-m = { version = "0.7.5" }
3035
cortex-m-rt = { version = "0.6.5", features = ["device"] }
3136
panic-halt = "1.0.0"
3237

33-
34-

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ fn main() -> ! {
143143
syscon.enable_hace();
144144

145145
let mut hace_controller = HaceController::new(&hace);
146+
146147
run_hash_tests(&mut uart_controller, &mut hace_controller);
148+
147149
run_hmac_tests(&mut uart_controller, &mut hace_controller);
148150

149151
// Enable RSA and ECC

xtask/src/test.rs

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ fn run_unit_tests() -> Result<()> {
3636

3737
let status = Command::new("cargo")
3838
.current_dir(&*PROJECT_ROOT)
39-
.args(["test", "--lib", "--bins"])
39+
// FIXME: Temporarily exclude `aspeed-ddk` since it's a no_std bare-metal crate.
40+
// Once an emulator is available or host-side unit tests are added for aspeed-ddk,
41+
// this exclusion should be removed.
42+
.args([
43+
"test",
44+
"--workspace",
45+
"--exclude",
46+
"aspeed-ddk",
47+
"--target",
48+
"x86_64-unknown-linux-gnu",
49+
])
4050
.status()?;
4151

4252
if !status.success() {
@@ -52,7 +62,17 @@ fn run_integration_tests() -> Result<()> {
5262

5363
let status = Command::new("cargo")
5464
.current_dir(&*PROJECT_ROOT)
55-
.args(["test", "--test", "*"])
65+
// FIXME: Temporarily exclude `aspeed-ddk` since it's a no_std bare-metal crate.
66+
// Once an emulator is available or host-side unit tests are added for aspeed-ddk,
67+
// this exclusion should be removed.
68+
.args([
69+
"test",
70+
"--workspace",
71+
"--exclude",
72+
"aspeed-ddk",
73+
"--target",
74+
"x86_64-unknown-linux-gnu",
75+
])
5676
.status()?;
5777

5878
if !status.success() {
@@ -146,10 +166,28 @@ fn run_hardware_test_suite(uart: &str, suite: &str) -> Result<()> {
146166
}
147167

148168
// Generate UART boot image
149-
let binary_path = PROJECT_ROOT.join("target/thumbv7em-none-eabihf/release/aspeed-ddk");
150-
let boot_image_path = PROJECT_ROOT.join(format!("target/{}-test-boot.img", suite));
169+
// let binary_path = PROJECT_ROOT.join("target/thumbv7em-none-eabihf/release/aspeed-ddk");
170+
let elf_path = PROJECT_ROOT.join("target/thumbv7em-none-eabihf/release/aspeed-ddk");
171+
assert!(elf_path.exists(), "ELF file not found: {:?}", elf_path);
172+
println!("ELF binary path: {:?}", elf_path);
173+
let bin_path = PROJECT_ROOT.join(format!("target/{}-test-{}.bin", suite, "release"));
174+
println!("Binary path: {:?}", bin_path);
175+
176+
let _status = Command::new("cargo")
177+
.args([
178+
"objcopy",
179+
"--target",
180+
"thumbv7em-none-eabihf",
181+
"--release",
182+
"--",
183+
"-O",
184+
"binary",
185+
bin_path.to_str().unwrap(),
186+
])
187+
.status()?;
151188

152-
crate::build::gen_boot_image(&binary_path, &boot_image_path)?;
189+
let boot_image_path = PROJECT_ROOT.join(format!("target/{}-test-boot.img", suite));
190+
crate::build::gen_boot_image(&bin_path, &boot_image_path)?;
153191

154192
// TODO: Add actual hardware test execution here
155193
// This would involve sending the boot image to the hardware via UART

0 commit comments

Comments
 (0)