Skip to content

Commit c3aed58

Browse files
committed
Added: packages input for selective package testing
Add a new `packages` input that accepts a multi-line list of package names to test. When provided, uses `-p <pkg>` flags instead of `--all`, allowing selective testing of specific packages. This solves the issue where --exclude doesn't prevent compilation of excluded packages as dependencies, which is problematic when packages have mutually exclusive features. Changes: - Add `packages` input parameter - Update tarpaulin, cargo test, and cross test commands - Add test workflow with fixture workspace
1 parent f7d1d74 commit c3aed58

11 files changed

Lines changed: 250 additions & 4 deletions

File tree

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Test Packages Input
2+
3+
# This workflow is a black-box integration test for the action's `packages` input.
4+
#
5+
# The fixture workspace contains three crates (package-a/package-b/package-c). Each crate writes a
6+
# marker file (marker-package-*) when its tests run. We assert marker presence/absence to prove
7+
# that:
8+
# - when `packages` is empty, the action runs the whole workspace (`--all`)
9+
# - when `packages` is provided, the action uses `-p <pkg>` and only runs those packages
10+
#
11+
# The fixture workspace also sets `default-members = ["package-a"]` to catch regressions where
12+
# the action accidentally stops passing `--all` for the default (empty packages) case.
13+
14+
on:
15+
workflow_dispatch:
16+
pull_request:
17+
branches: [v1-master]
18+
paths:
19+
- "action.yml"
20+
- "README.MD"
21+
- ".github/workflows/test-packages-input.yml"
22+
- "tests/fixtures/packages-input-workspace/**"
23+
24+
jobs:
25+
packages-input:
26+
name: Packages Input - ${{ matrix.name }}
27+
runs-on: ubuntu-latest
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
include:
32+
- name: cargo empty (default all)
33+
target: x86_64-unknown-linux-gnu
34+
use_cross: false
35+
use_tarpaulin: false
36+
packages: ""
37+
expect: "marker-package-a marker-package-b marker-package-c"
38+
forbid: ""
39+
40+
- name: cargo single
41+
target: x86_64-unknown-linux-gnu
42+
use_cross: false
43+
use_tarpaulin: false
44+
packages: |
45+
package-b
46+
expect: "marker-package-b"
47+
forbid: "marker-package-a marker-package-c"
48+
49+
- name: cargo multiple
50+
target: x86_64-unknown-linux-gnu
51+
use_cross: false
52+
use_tarpaulin: false
53+
packages: |
54+
package-a
55+
package-c
56+
expect: "marker-package-a marker-package-c"
57+
forbid: "marker-package-b"
58+
59+
- name: cross multiple
60+
target: aarch64-unknown-linux-gnu
61+
use_cross: true
62+
use_tarpaulin: false
63+
packages: |
64+
package-a
65+
package-c
66+
expect: "marker-package-a marker-package-c"
67+
forbid: "marker-package-b"
68+
69+
- name: tarpaulin single
70+
target: x86_64-unknown-linux-gnu
71+
use_cross: false
72+
use_tarpaulin: true
73+
packages: |
74+
package-b
75+
expect: "marker-package-b"
76+
forbid: "marker-package-a marker-package-c"
77+
78+
steps:
79+
- name: Checkout Action Repository
80+
uses: actions/checkout@v6
81+
82+
- name: Clean package markers
83+
shell: bash
84+
run: rm -f tests/fixtures/packages-input-workspace/marker-package-*
85+
86+
- name: Run action
87+
uses: ./
88+
with:
89+
rust-project-path: tests/fixtures/packages-input-workspace
90+
rust-toolchain: stable
91+
target: ${{ matrix.target }}
92+
use-cross: ${{ matrix.use_cross }}
93+
use-tarpaulin: ${{ matrix.use_tarpaulin }}
94+
upload-coverage: false
95+
packages: ${{ matrix.packages }}
96+
97+
- name: Assert markers
98+
shell: bash
99+
run: |
100+
set -euo pipefail
101+
root="tests/fixtures/packages-input-workspace"
102+
expect="${{ matrix.expect }}"
103+
forbid="${{ matrix.forbid }}"
104+
105+
for f in $expect; do
106+
test -f "$root/$f" || { echo "Missing marker: $f"; exit 1; }
107+
done
108+
109+
if [ -n "$forbid" ]; then
110+
for f in $forbid; do
111+
test ! -f "$root/$f" || { echo "Unexpected marker: $f"; exit 1; }
112+
done
113+
fi

README.MD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ To use this action in your GitHub workflow, add the following step:
4646
codecov-flags: 'unittests'
4747
codecov-name: 'codecov-umbrella'
4848
features: 'feature1 feature2'
49+
packages: |
50+
package-a
51+
package-b
4952
no-default-features: false
5053
use-cross: false
5154
additional-test-args: '--ignored --test-threads=1'
@@ -70,6 +73,7 @@ To use this action in your GitHub workflow, add the following step:
7073
| `codecov-flags` | Flags to pass to Codecov | No | `'unittests'` |
7174
| `codecov-name` | Custom defined name for the upload | No | `'codecov-umbrella'` |
7275
| `features` | Space-separated list of features to enable during testing | No | `''` |
76+
| `packages` | Multi-line list of package names to test (one per line). If empty, tests all packages in workspace | No | `''` |
7377
| `no-default-features` | Disable default features during testing | No | `false` |
7478
| `use-cross` | Use cross-rs for testing. If false, use cargo. | No | `false` |
7579
| `additional-test-args` | Additional arguments to pass to the cargo test command | No | `''` |
@@ -204,4 +208,4 @@ rust-toolchain: 'beta'
204208

205209
This GitHub Action is released under the [MIT License](LICENSE).
206210

207-
[rust-lw-binary]: https://github.com/Reloaded-Project/devops-rust-lightweight-binary
211+
[rust-lw-binary]: https://github.com/Reloaded-Project/devops-rust-lightweight-binary

action.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ inputs:
7777
required: false
7878
default: ""
7979

80+
packages:
81+
description: "Multi-line list of package names to test (one per line). If empty, tests all packages in workspace (--all)"
82+
required: false
83+
default: ""
84+
8085
runs:
8186
using: "composite"
8287
steps:
@@ -90,6 +95,27 @@ runs:
9095
fi
9196
echo "SAFE_ADDITIONAL_TEST_ARGS=${SAFE_ADDITIONAL_TEST_ARGS}" >> $GITHUB_ENV
9297
98+
# Process packages input - convert multiline to space-separated, clean whitespace
99+
SAFE_PACKAGES=$(echo "${{ inputs.packages }}" | tr -d '\r' | tr '\n\t' ' ' | tr -s ' ' | sed 's/^ *//;s/ *$//')
100+
echo "SAFE_PACKAGES=${SAFE_PACKAGES}" >> $GITHUB_ENV
101+
102+
# Build packages argument once and reuse across steps
103+
if [ -n "$SAFE_PACKAGES" ]; then
104+
PACKAGES_ARG=""
105+
for pkg in $SAFE_PACKAGES; do
106+
if [ -n "$pkg" ]; then
107+
if [ -z "$PACKAGES_ARG" ]; then
108+
PACKAGES_ARG="-p $pkg"
109+
else
110+
PACKAGES_ARG="$PACKAGES_ARG -p $pkg"
111+
fi
112+
fi
113+
done
114+
else
115+
PACKAGES_ARG="--all"
116+
fi
117+
echo "PACKAGES_ARG=${PACKAGES_ARG}" >> $GITHUB_ENV
118+
93119
- name: Install Rust Toolchain
94120
if: inputs.install-rust-toolchain == 'true'
95121
uses: actions-rust-lang/setup-rust-toolchain@v1
@@ -164,7 +190,7 @@ runs:
164190
shell: bash
165191
working-directory: ${{ inputs.rust-project-path }}
166192
run: |
167-
cargo +${{ inputs.rust-toolchain }} tarpaulin --all --out xml --engine llvm \
193+
cargo +${{ inputs.rust-toolchain }} tarpaulin $PACKAGES_ARG --out xml --engine llvm \
168194
--features "${{ inputs.features }}" \
169195
${{ inputs.no-default-features == 'true' && '--no-default-features' || '' }} \
170196
${{ inputs.target != '' && format('--target "{0}"', inputs.target) || '' }} \
@@ -177,7 +203,7 @@ runs:
177203
shell: bash
178204
working-directory: ${{ inputs.rust-project-path }}
179205
run: |
180-
cargo +${{ inputs.rust-toolchain }} test --all \
206+
cargo +${{ inputs.rust-toolchain }} test $PACKAGES_ARG \
181207
--features "${{ inputs.features }}" \
182208
${{ inputs.no-default-features == 'true' && '--no-default-features' || '' }} \
183209
${{ inputs.target != '' && format('--target "{0}"', inputs.target) || '' }} \
@@ -190,7 +216,7 @@ runs:
190216
# the RUSTFLAGS are a hack around cross build errors on certain setups
191217
# https://github.com/cross-rs/cross/issues/1561
192218
run: |
193-
RUSTFLAGS="" cross +${{ inputs.rust-toolchain }} test --all \
219+
RUSTFLAGS="" cross +${{ inputs.rust-toolchain }} test $PACKAGES_ARG \
194220
--features "${{ inputs.features }}" \
195221
${{ inputs.no-default-features == 'true' && '--no-default-features' || '' }} \
196222
${{ inputs.target != '' && format('--target "{0}"', inputs.target) || '' }} \

tests/fixtures/packages-input-workspace/Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"package-a",
5+
"package-b",
6+
"package-c",
7+
]
8+
9+
# If the action accidentally drops `--all`, this makes the default behavior
10+
# run only package-a. Our CI checks rely on this to detect regressions.
11+
default-members = [
12+
"package-a",
13+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "package-a"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[lib]
8+
path = "src/lib.rs"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use std::fs;
4+
use std::path::PathBuf;
5+
6+
fn workspace_root() -> PathBuf {
7+
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
8+
.parent()
9+
.expect("package directory should have a workspace root parent")
10+
.to_path_buf()
11+
}
12+
13+
#[test]
14+
fn writes_marker() {
15+
fs::write(workspace_root().join("marker-package-a"), "ok\n").unwrap();
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "package-b"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[lib]
8+
path = "src/lib.rs"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use std::fs;
4+
use std::path::PathBuf;
5+
6+
fn workspace_root() -> PathBuf {
7+
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
8+
.parent()
9+
.expect("package directory should have a workspace root parent")
10+
.to_path_buf()
11+
}
12+
13+
#[test]
14+
fn writes_marker() {
15+
fs::write(workspace_root().join("marker-package-b"), "ok\n").unwrap();
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "package-c"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[lib]
8+
path = "src/lib.rs"

0 commit comments

Comments
 (0)