Skip to content

Commit b583cf2

Browse files
authored
Merge pull request #3111 from iosh/githubTest
feat: add GitHub Actions workflow for running tests
2 parents 4eddc55 + 3fa1d57 commit b583cf2

File tree

3 files changed

+104
-11
lines changed

3 files changed

+104
-11
lines changed

.github/workflows/docs.Dockerfile renamed to .github/dockers/base.Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ RUN apt-get update && \
2020
rm -rf /var/lib/apt/lists/* && \
2121
rm llvm.sh
2222

23+
WORKDIR /app
24+
25+
COPY rust-toolchain.toml .
26+
2327
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-host x86_64-unknown-linux-gnu -y && \
2428
. ~/.cargo/env && \
25-
rustup default nightly-2024-01-29 && \
26-
git config --global --add safe.directory '*'
29+
git config --global --add safe.directory /app && \
30+
cargo install cargo-nextest --version "0.9.85" --locked
2731

2832
ENV PATH="/root/.cargo/bin:/home/builder/.cargo/bin:${PATH}"
2933
ENV CC=clang-18
3034
ENV CXX=clang++-18
3135
ENV CXXFLAGS="-std=c++11 -stdlib=libc++"
3236
ENV LDFLAGS="-stdlib=libc++"
3337

34-
WORKDIR /app
35-
36-
COPY . .

.github/workflows/docs.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,39 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16+
- name: Cache Docker layers
17+
uses: actions/cache@v3
18+
with:
19+
path: /tmp/.buildx-cache
20+
key: ${{ runner.os }}-buildx-base-${{ hashFiles('.github/dockers/base.Dockerfile') }}
21+
restore-keys: |
22+
${{ runner.os }}-buildx-base-
23+
1624
- name: Set up Docker Buildx
1725
uses: docker/setup-buildx-action@v3
1826

1927
- name: Build docker image
2028
uses: docker/build-push-action@v5
2129
with:
2230
context: .
23-
file: .github/workflows/docs.Dockerfile
31+
file: .github/dockers/base.Dockerfile
2432
load: true
25-
tags: doc-builder:latest
33+
tags: base-builder:latest
34+
cache-from: type=local,src=/tmp/.buildx-cache
35+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
2636

2737
- name: Generate documentation
2838
run: |
29-
mkdir -p target
30-
chmod -R 777 target
31-
docker run --rm -v $(pwd)/target:/app/target -w /app doc-builder:latest \
32-
bash -c "RUSTDOCFLAGS='--enable-index-page -Z unstable-options' cargo +nightly-2024-01-29 doc --no-deps"
39+
docker run --rm -v $(pwd):/app -w /app base-builder:latest \
40+
bash -c "rustup default nightly-2024-01-29 && RUSTDOCFLAGS='--enable-index-page -Z unstable-options' cargo +nightly-2024-01-29 doc --no-deps"
3341
3442
- name: Deploy
3543
uses: peaceiris/actions-gh-pages@v3
3644
with:
3745
github_token: ${{ secrets.GITHUB_TOKEN }}
3846
publish_dir: ./target/doc
47+
48+
- name: Move cache to the correct location
49+
run: |
50+
rm -rf /tmp/.buildx-cache
51+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.github/workflows/test.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Free up space
16+
run: |
17+
sudo rm -rf /usr/share/dotnet /usr/local/lib/android
18+
19+
- name: Cache Cargo and build artifacts
20+
uses: actions/cache@v4
21+
with:
22+
path: |
23+
~/.cargo/registry
24+
~/.cargo/git
25+
target/release
26+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-cargo-
29+
30+
- name: Cache Docker layers
31+
uses: actions/cache@v4
32+
with:
33+
path: /tmp/.buildx-cache
34+
key: ${{ runner.os }}-buildx-base-${{ hashFiles('.github/dockers/base.Dockerfile') }}
35+
restore-keys: |
36+
${{ runner.os }}-buildx-base-
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v3
40+
41+
- name: Build docker image
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
file: .github/dockers/base.Dockerfile
46+
load: true
47+
tags: base-builder:latest
48+
cache-from: type=local,src=/tmp/.buildx-cache
49+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
50+
51+
- name: Run workspace tests
52+
run: |
53+
docker run --rm \
54+
-v $(pwd):/app \
55+
-v ~/.cargo/registry:/root/.cargo/registry \
56+
-v ~/.cargo/git:/root/.cargo/git \
57+
-e RUST_BACKTRACE=1 \
58+
-w /app base-builder:latest \
59+
cargo nextest run --no-fail-fast --release --workspace
60+
61+
- name: Run cfx-addr
62+
run: |
63+
docker run --rm \
64+
-v $(pwd):/app \
65+
-v ~/.cargo/registry:/root/.cargo/registry \
66+
-v ~/.cargo/git:/root/.cargo/git \
67+
-e RUST_BACKTRACE=1 \
68+
-w /app base-builder:latest \
69+
cargo nextest run --no-fail-fast -p cfx-addr --no-default-features
70+
71+
- name: Ensure cache files are accessible
72+
run: |
73+
sudo chown -R $(id -u):$(id -g) target/release
74+
sudo chown -R $(id -u):$(id -g) ~/.cargo
75+
76+
- name: Move cache to the correct location
77+
run: |
78+
rm -rf /tmp/.buildx-cache
79+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 commit comments

Comments
 (0)