-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
152 lines (142 loc) · 5.41 KB
/
action.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
147
148
149
150
151
152
name: 'Test Rust Library and Upload Coverage'
description: 'Runs tests for a Rust library using Tarpaulin and uploads the coverage to Codecov.'
branding:
icon: 'check'
color: 'green'
inputs:
rust-project-path:
description: 'Path to the Rust project'
required: false
default: '.'
rust-toolchain:
description: 'Rust toolchain to use for building and testing (e.g., stable, nightly)'
required: false
default: 'stable'
target:
description: 'The target platform for the Rust compiler'
required: false
default: ''
install-rust-toolchain:
description: 'Whether to install the specified Rust toolchain'
required: false
default: true
setup-rust-cache:
description: 'Whether to set up Rust caching'
required: false
default: true
use-tarpaulin:
description: 'Whether to use Tarpaulin for code coverage. If false, only runs tests.'
required: false
default: true
upload-coverage:
description: 'Whether to upload coverage to Codecov'
required: false
default: true
codecov-token:
description: 'Codecov token for uploading coverage'
required: false
codecov-flags:
description: 'Flags to pass to Codecov'
required: false
default: 'unittests'
codecov-name:
description: 'Custom defined name for the upload'
required: false
default: 'codecov-umbrella'
features:
description: 'Space-separated list of features to enable during testing'
required: false
default: ''
no-default-features:
description: 'Disable default features during testing'
required: false
default: false
use-cross:
description: 'Use cross-rs for testing. If false, use cargo.'
required: false
default: false
additional-test-args:
description: 'Additional arguments to pass to the cargo test command'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Install Rust Toolchain
if: inputs.install-rust-toolchain == 'true'
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ inputs.rust-toolchain }}
target: ${{ inputs.target }}
cache: false
- name: Setup Rust Caching
if: inputs.setup-rust-cache == 'true'
uses: Swatinem/rust-cache@v2
with:
key: ${{ inputs.rust-project-path }}+${{ inputs.target }}
cache-on-failure: true
workspaces: |
${{ inputs.rust-project-path }} -> target
- name: Install gcc-multilib (if on Ubuntu based System, and Target is not Host)
if: inputs.use-cross == 'false' && runner.os == 'Linux'
shell: bash
run: |
# Get host triple
HOST_TARGET=$(rustc -vV | sed -n 's|host: ||p')
echo "Host target: $HOST_TARGET"
echo "Target: ${{ inputs.target }}"
if [ "$HOST_TARGET" != "${{ inputs.target }}" ]; then
echo "Target is different from host. Installing gcc-multilib..."
sudo apt-get update || true
sudo apt-get install -y gcc-multilib || true
else
echo "Target is the same as host. Skipping gcc-multilib installation."
fi
- name: Install cross
if: inputs.use-cross == 'true'
shell: bash
run: RUSTFLAGS="" cargo install cross --git https://github.com/cross-rs/cross
- name: Run Tarpaulin
if: inputs.use-cross == 'false' && inputs.use-tarpaulin == 'true'
shell: bash
working-directory: ${{ inputs.rust-project-path }}
run: |
cargo +${{ inputs.rust-toolchain }} install cargo-tarpaulin
cargo +${{ inputs.rust-toolchain }} tarpaulin --all --out xml --engine llvm \
--features "${{ inputs.features }}" \
${{ inputs.no-default-features == 'true' && '--no-default-features' || '' }} \
${{ inputs.target != '' && format('--target "{0}"', inputs.target) || '' }} \
--skip-clean \
${{ inputs.additional-test-args }}
- name: Run Tests with cargo
if: inputs.use-cross == 'false' && inputs.use-tarpaulin == 'false'
shell: bash
working-directory: ${{ inputs.rust-project-path }}
run: |
cargo +${{ inputs.rust-toolchain }} test --all \
--features "${{ inputs.features }}" \
${{ inputs.no-default-features == 'true' && '--no-default-features' || '' }} \
${{ inputs.target != '' && format('--target "{0}"', inputs.target) || '' }} \
${{ inputs.additional-test-args }}
- name: Run Tests with cross
if: inputs.use-cross == 'true'
shell: bash
working-directory: ${{ inputs.rust-project-path }}
# the RUSTFLAGS are a hack around cross build errors on certain setups
# https://github.com/cross-rs/cross/issues/1561
run: |
RUSTFLAGS="" cross +${{ inputs.rust-toolchain }} test --all \
--features "${{ inputs.features }}" \
${{ inputs.no-default-features == 'true' && '--no-default-features' || '' }} \
${{ inputs.target != '' && format('--target "{0}"', inputs.target) || '' }} \
${{ inputs.additional-test-args }}
- name: Upload Coverage to Codecov
if: inputs.upload-coverage == 'true' && inputs.use-cross == 'false' && inputs.use-tarpaulin == 'true'
uses: codecov/codecov-action@v5
with:
files: ${{ inputs.rust-project-path }}/cobertura.xml
flags: ${{ inputs.codecov-flags }}
name: ${{ inputs.codecov-name }}
token: ${{ inputs.codecov-token }}
fail_ci_if_error: true
verbose: true