-
Notifications
You must be signed in to change notification settings - Fork 90
146 lines (142 loc) Β· 4.24 KB
/
rust.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
name: Cargo & Clippy Test
on:
push:
branches: [master]
paths:
- src/**
- test_files/**
- .cargo/**
- Cargo.toml
- Cargo.lock
- rust-toolchain.toml
- flake.nix
- flake.lock
pull_request:
paths:
- src/**
- test_files/**
- .cargo/**
- Cargo.toml
- Cargo.lock
- rust-toolchain.toml
- flake.nix
- flake.lock
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Rust build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies installed with cargo
uses: actions/cache@v4
with:
path: |
./target/deps
~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Build binary
run: |
# the binary will be used by the cargo test
cargo build
cargo test --no-run --all-targets --all-features
- name: Compress before uploading artifact to preserve permissions # https://github.com/actions/upload-artifact/tree/v4.4.3#permission-loss
run: tar -cvzf target.tgz target/
- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: target
path: target.tgz
retention-days: 1
test:
name: Rust tests
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
bash_docker_image:
- "bash:5.2"
- "bash:5.1"
- "bash:5.0"
- "bash:4.4"
- "bash:4.3"
- "bash:4.2"
# - "bash:4.1"
# - "bash:4.0"
# - "bash:3.2"
sed:
- GNU sed
# Uncomment the next matrix when https://github.com/amber-lang/amber/issues/617 is resolved
# include:
# - sed: BusyBox sed
# bash_version: "bash:latest"
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: bc shfmt
version: 1.0
- name: Install bshchk
run: |
sudo curl https://github.com/b1ek/bshchk/releases/download/1.1/bshchk.linux.amd64 -L -o /usr/bin/bshchk
sudo chmod +x /usr/bin/bshchk
- uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies installed with cargo
uses: actions/cache@v4
with:
path: |
./target/deps
~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- uses: actions/download-artifact@v4
with:
name: target
path: artifact
- run: tar -xvzf artifact/target.tgz && rm artifact/target.tgz
- name: Run cargo tests
env:
AMBER_TEST_STRATEGY: docker
AMBER_TEST_ARGS:
# 405 is a non-root user(guest) for is_root() test
exec
--user 405
test_container
bash
run: |
echo "FROM ${{ matrix.bash_docker_image }}" > Dockerfile
# coreutils includes mktemp
apks="coreutils curl"
if [ "${{ matrix.sed }}" == "GNU sed" ]; then
apks="$apks sed"
fi
echo "RUN apk add $apks" >> Dockerfile
docker build -t testbash .
docker run --network host --detach --name test_container testbash sleep infinity
cargo test --all-targets --all-features
docker stop test_container -t 0
docker rm --force test_container
clippy:
name: Clippy tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: bc shfmt
version: 1.0
- uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies installed with cargo
uses: actions/cache@v4
with:
path: |
./target/deps
~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Run clippy check
run: cargo clippy --all-targets --all-features -- -D warnings