1+ #! /bin/bash
2+ set -euo
3+
4+ # Check if we are running in a GitHub Actions environment
5+ CI=${GITHUB_ACTIONS:- false}
6+
7+ # List of ignored modules
8+ ignored_folders=(" dora-parler" " dora-opus" " dora-internvl" " dora-magma" )
9+
10+ # Skip test
11+ skip_test_folders=(" dora-internvl" " dora-parler" " dora-keyboard" " dora-microphone" " terminal-input" " dora-magma" )
12+
13+ # Get current working directory
14+ dir=$( pwd)
15+
16+ # Get the base name of the directory (without the path)
17+ base_dir=$( basename " $dir " )
18+
19+ export GIT_LFS_SKIP_SMUDGE=1
20+ # Large node list requiring space cleanup
21+ large_node=(" dora-phi4" )
22+
23+ export PYTEST_ADDOPTS=" -x"
24+
25+ # Check if the current directory is in the large node list and if we're in the CI environment
26+ if [[ " ${large_node[@]} " =~ " ${base_dir} " ]] && [[ " $CI " == " true" ]]; then
27+ echo " Running cleanup for $base_dir ..."
28+ sudo rm -rf /opt/hostedtoolcache/CodeQL || :
29+ # 1.4GB
30+ sudo rm -rf /opt/hostedtoolcache/go || :
31+ # 489MB
32+ sudo rm -rf /opt/hostedtoolcache/PyPy || :
33+ # 376MB
34+ sudo rm -rf /opt/hostedtoolcache/node || :
35+ # Remove Web browser packages
36+ sudo apt purge -y \
37+ firefox \
38+ google-chrome-stable \
39+ microsoft-edge-stable
40+ sudo rm -rf /usr/local/lib/android/
41+ sudo rm -rf /usr/share/dotnet/
42+ sudo rm -rf /opt/ghc/
43+ fi
44+
45+ # Check if the directory name is in the ignored list
46+ if [[ " ${ignored_folders[@]} " =~ " ${base_dir} " ]]; then
47+ echo " Skipping $base_dir as we cannot test it on the CI..."
48+ else
49+ # IF job is mixed rust-python job and is on linux
50+ if [[ -f " Cargo.toml" && -f " pyproject.toml" && " $( uname) " = " Linux" ]]; then
51+ echo " Running build and tests for Rust project in $dir ..."
52+
53+ cargo check
54+ cargo clippy
55+ cargo build
56+ cargo test
57+
58+ pip install " maturin[zig, patchelf]"
59+ maturin build --release --compatibility manylinux_2_28 --zig
60+ # If GITHUB_EVENT_NAME is release or workflow_dispatch, publish the wheel on multiple platforms
61+ if [ " $GITHUB_EVENT_NAME " == " release" ] || [ " $GITHUB_EVENT_NAME " == " workflow_dispatch" ]; then
62+ # Free up ubuntu space
63+ sudo apt-get clean
64+ sudo rm -rf /usr/local/lib/android/
65+ sudo rm -rf /usr/share/dotnet/
66+ sudo rm -rf /opt/ghc/
67+
68+ maturin publish --skip-existing --compatibility manylinux_2_28 --zig
69+ # aarch64-unknown-linux-gnu
70+ rustup target add aarch64-unknown-linux-gnu
71+ maturin publish --target aarch64-unknown-linux-gnu --skip-existing --zig --compatibility manylinux_2_28
72+
73+ # armv7-unknown-linux-musleabihf
74+ rustup target add armv7-unknown-linux-musleabihf
75+ # If GITHUB_EVENT_NAME is release or workflow_dispatch, publish the wheel
76+ maturin publish --target armv7-unknown-linux-musleabihf --skip-existing --zig
77+
78+ # x86_64-pc-windows-gnu
79+ rustup target add x86_64-pc-windows-gnu
80+ # If GITHUB_EVENT_NAME is release or workflow_dispatch, publish the wheel
81+ maturin publish --target x86_64-pc-windows-gnu --skip-existing
82+ fi
83+
84+ elif [[ -f " Cargo.toml" && -f " pyproject.toml" && " $( uname) " = " Darwin" ]]; then
85+ pip install " maturin[zig, patchelf]"
86+ # aarch64-apple-darwin
87+ maturin build --release
88+ # If GITHUB_EVENT_NAME is release or workflow_dispatch, publish the wheel
89+ if [ " $GITHUB_EVENT_NAME " == " release" ] || [ " $GITHUB_EVENT_NAME " == " workflow_dispatch" ]; then
90+ maturin publish --skip-existing
91+ fi
92+
93+ elif [[ " $( uname) " = " Linux" ]] || [[ " $CI " == " false" ]]; then
94+ if [ -f " $dir /Cargo.toml" ]; then
95+ echo " Running build and tests for Rust project in $dir ..."
96+ cargo check
97+ cargo clippy
98+ cargo build
99+ cargo test
100+
101+ if [ " $GITHUB_EVENT_NAME " == " release" ] || [ " $GITHUB_EVENT_NAME " == " workflow_dispatch" ]; then
102+ cargo publish
103+ fi
104+ else
105+ if [ -f " $dir /pyproject.toml" ]; then
106+ echo " CI: Installing in $dir ..."
107+ uv venv --seed -p 3.11
108+ uv pip install .
109+ echo " CI: Running Linting in $dir ..."
110+ uv run ruff check .
111+ echo " CI: Running Pytest in $dir ..."
112+ # Skip test for some folders
113+ if [[ " ${skip_test_folders[@]} " =~ " ${base_dir} " ]]; then
114+ echo " Skipping tests for $base_dir ..."
115+ else
116+ uv run pytest
117+ fi
118+ if [ " ${GITHUB_EVENT_NAME:- false} " == " release" ] || [ " ${GITHUB_EVENT_NAME:- false} " == " workflow_dispatch" ]; then
119+ uv build
120+ uv publish --check-url https://pypi.org/simple
121+ fi
122+ fi
123+ fi
124+ fi
125+ fi
0 commit comments