Skip to content

Commit b890003

Browse files
committed
Run the orchestrator unit tests in CI
Rework the build to use a separate Dockerfile — it was simply too complicated to have the nested scripts in YAML.
1 parent b67c737 commit b890003

File tree

5 files changed

+78
-83
lines changed

5 files changed

+78
-83
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -101,50 +101,22 @@ jobs:
101101
uses: dtolnay/rust-toolchain@stable
102102
with:
103103
components: rustfmt
104-
- name: Cache Cargo intermediate products
105-
uses: actions/cache@v3
106-
with:
107-
path: |-
108-
~/.cargo/registry
109-
~/.cargo/git
110-
ui/target
111-
key: "${{ runner.os }}-cargo-${{ hashFiles('ui/**/Cargo.lock') }}-2"
112104
- name: Format server
113105
run: cargo fmt --manifest-path ui/Cargo.toml --all --check
114106
- name: Format top-crates
115107
run: cargo fmt --manifest-path top-crates/Cargo.toml --check
116108
- name: Format orchestrator
117109
run: cargo fmt --manifest-path compiler/base/orchestrator/Cargo.toml --check
118110
- name: Build backend
119-
run: |-
120-
mkdir -p ui/target; docker run --rm -v $PWD/compiler/base/asm-cleanup:/compiler/base/asm-cleanup -v $PWD/compiler/base/orchestrator:/compiler/base/orchestrator -v $PWD/compiler/base/modify-cargo-toml:/compiler/base/modify-cargo-toml -v $PWD/ui:/ui -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry --workdir /ui rust:alpine sh -c '
121-
apk add musl-dev openssl-dev openssl-libs-static
122-
123-
# Adding -C relocation-model=static due to
124-
# https://github.com/rust-lang/rust/issues/95926
125-
126-
# Adding this to find the statically-built version
127-
export OPENSSL_NO_PKG_CONFIG=1 OPENSSL_STATIC=1 OPENSSL_DIR=/usr/
128-
129-
# Unit tests
130-
cargo rustc --tests --locked -- -C relocation-model=static;
131-
132-
test_bin=$(find target/debug/deps/ -name "ui*" -type f -perm -a=x);
133-
mv "${test_bin}" target/unit_tests;
134-
135-
# Primary binary
136-
cargo rustc --locked --release -- -C relocation-model=static;
137-
mv target/release/ui target/ui;
138-
'
139-
- name: Restore permissions
140-
run: sudo chown -R runner:docker ~/.cargo/ ui/target
111+
run: "./ci/build-backend.sh"
141112
- name: Save backend artifact
142113
uses: actions/upload-artifact@v3
143114
with:
144115
name: backend
145116
path: |
146-
ui/target/ui
147-
ui/target/unit_tests
117+
docker-output/ui
118+
docker-output/unit_tests_ui
119+
docker-output/unit_tests_orchestrator
148120
build_frontend:
149121
name: Build frontend
150122
runs-on: ubuntu-latest
@@ -249,8 +221,10 @@ jobs:
249221
with:
250222
name: frontend
251223
path: tests/server/build/
252-
- name: Run unit tests
253-
run: chmod +x ./server/unit_tests && ./server/unit_tests
224+
- name: Run orchestrator unit tests
225+
run: chmod +x ./server/unit_tests_orchestrator && ./server/unit_tests_orchestrator
226+
- name: Run ui unit tests
227+
run: chmod +x ./server/unit_tests_ui && ./server/unit_tests_ui
254228
- name: Run tests
255229
env:
256230
PLAYGROUND_UI_ROOT: server/build/

ci/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM rust:alpine
2+
3+
RUN apk add musl-dev openssl-dev openssl-libs-static
4+
5+
# Adding -C relocation-model=static due to
6+
# https://github.com/rust-lang/rust/issues/95926
7+
8+
# Adding this to find the statically-built version
9+
ENV OPENSSL_NO_PKG_CONFIG=1 OPENSSL_STATIC=1 OPENSSL_DIR=/usr/
10+
11+
RUN mkdir /output
12+
13+
COPY compiler/base/asm-cleanup /compiler/base/asm-cleanup
14+
COPY compiler/base/orchestrator /compiler/base/orchestrator
15+
COPY compiler/base/modify-cargo-toml /compiler/base/modify-cargo-toml
16+
COPY ui /ui
17+
18+
WORKDIR /compiler/base/orchestrator
19+
20+
RUN \
21+
cargo rustc --profile test --lib --locked -- --cfg force_docker -C relocation-model=static; \
22+
test_bin=$(find target/debug/deps/ -name "orchestrator*" -type f -perm -a=x); \
23+
mv "${test_bin}" /output/unit_tests_orchestrator;
24+
25+
WORKDIR /ui
26+
27+
RUN \
28+
cargo rustc --tests --locked -- -C relocation-model=static; \
29+
test_bin=$(find target/debug/deps/ -name "ui*" -type f -perm -a=x); \
30+
mv "${test_bin}" /output/unit_tests_ui;
31+
32+
RUN \
33+
cargo rustc --locked --release -- -C relocation-model=static; \
34+
mv target/release/ui /output/ui;

ci/Dockerfile.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*
2+
!compiler/base/asm-cleanup/**
3+
compiler/base/asm-cleanup/target
4+
!compiler/base/orchestrator/**
5+
compiler/base/orchestrator/target
6+
!compiler/base/modify-cargo-toml/**
7+
compiler/base/modify-cargo-toml/target
8+
!ui/**
9+
ui/frontend
10+
ui/target

ci/build-backend.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
IMAGE_NAME=backend-build
6+
OUTPUT_DIR=docker-output
7+
8+
docker build -t "${IMAGE_NAME}" -f ci/Dockerfile .
9+
10+
mkdir -p "${OUTPUT_DIR}"
11+
12+
container_id=$(docker create "${IMAGE_NAME}")
13+
for f in unit_tests_orchestrator unit_tests_ui ui; do
14+
docker cp "${container_id}:/output/${f}" "${OUTPUT_DIR}"
15+
done
16+
docker rm -f "${container_id}"

ci/workflows.yml

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,6 @@ workflows:
177177
with:
178178
components: rustfmt
179179

180-
- name: "Cache Cargo intermediate products"
181-
uses: actions/cache@v3
182-
with:
183-
path: |-
184-
~/.cargo/registry
185-
~/.cargo/git
186-
ui/target
187-
key: ${{ runner.os }}-cargo-${{ hashFiles('ui/**/Cargo.lock') }}-2
188-
189180
- name: "Format server"
190181
run: cargo fmt --manifest-path ui/Cargo.toml --all --check
191182

@@ -196,50 +187,16 @@ workflows:
196187
run: cargo fmt --manifest-path compiler/base/orchestrator/Cargo.toml --check
197188

198189
- name: "Build backend"
199-
run: >-
200-
mkdir -p ui/target;
201-
docker
202-
run
203-
--rm
204-
-v $PWD/compiler/base/asm-cleanup:/compiler/base/asm-cleanup
205-
-v $PWD/compiler/base/orchestrator:/compiler/base/orchestrator
206-
-v $PWD/compiler/base/modify-cargo-toml:/compiler/base/modify-cargo-toml
207-
-v $PWD/ui:/ui
208-
-v ~/.cargo/git:/root/.cargo/git
209-
-v ~/.cargo/registry:/root/.cargo/registry
210-
--workdir /ui
211-
rust:alpine
212-
sh -c '
213-
apk add musl-dev openssl-dev openssl-libs-static
214-
215-
# Adding -C relocation-model=static due to
216-
# https://github.com/rust-lang/rust/issues/95926
217-
218-
# Adding this to find the statically-built version
219-
export OPENSSL_NO_PKG_CONFIG=1 OPENSSL_STATIC=1 OPENSSL_DIR=/usr/
220-
221-
# Unit tests
222-
cargo rustc --tests --locked -- -C relocation-model=static;
223-
224-
test_bin=$(find target/debug/deps/ -name "ui*" -type f -perm -a=x);
225-
mv "${test_bin}" target/unit_tests;
226-
227-
# Primary binary
228-
cargo rustc --locked --release -- -C relocation-model=static;
229-
mv target/release/ui target/ui;
230-
'
231-
232-
- name: "Restore permissions"
233-
run: >-
234-
sudo chown -R runner:docker ~/.cargo/ ui/target
190+
run: ./ci/build-backend.sh
235191

236192
- name: "Save backend artifact"
237193
uses: actions/upload-artifact@v3
238194
with:
239195
name: backend
240196
path: |
241-
ui/target/ui
242-
ui/target/unit_tests
197+
docker-output/ui
198+
docker-output/unit_tests_ui
199+
docker-output/unit_tests_orchestrator
243200
244201
build_frontend:
245202
name: "Build frontend"
@@ -354,9 +311,13 @@ workflows:
354311
name: frontend
355312
path: tests/server/build/
356313

357-
- name: "Run unit tests"
314+
- name: "Run orchestrator unit tests"
315+
run: |-
316+
chmod +x ./server/unit_tests_orchestrator && ./server/unit_tests_orchestrator
317+
318+
- name: "Run ui unit tests"
358319
run: |-
359-
chmod +x ./server/unit_tests && ./server/unit_tests
320+
chmod +x ./server/unit_tests_ui && ./server/unit_tests_ui
360321
361322
- name: "Run tests"
362323
env:

0 commit comments

Comments
 (0)