Skip to content

Commit 2499a60

Browse files
authored
Merge pull request #16 from Reloaded-Project/add-artifact-name-exclude-features
Added: artifact-name-exclude-features parameter for selective feature filtering
2 parents 44a42d6 + f92c5f2 commit 2499a60

File tree

4 files changed

+199
-12
lines changed

4 files changed

+199
-12
lines changed

.github/workflows/test-artifact-names.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,123 @@ jobs:
311311
exit 1
312312
fi
313313
echo "artifact-prefix correctly takes precedence: $ARTIFACT_NAME"
314+
315+
# Test artifact-name-exclude-features functionality
316+
test-artifact-name-exclude-features:
317+
runs-on: ubuntu-latest
318+
steps:
319+
- name: Checkout Action
320+
uses: actions/checkout@v4
321+
322+
- name: Test partial exclusion keeps non-excluded features
323+
shell: bash
324+
run: |
325+
ARTIFACT_NAME=$(./scripts/get-artifact-name.sh \
326+
--artifact-prefix "MyApp" \
327+
--target x86_64-unknown-linux-gnu \
328+
--features "c-exports,simd" \
329+
--exclude-features "c-exports" \
330+
--use-friendly-target-names true \
331+
--artifact-type binary)
332+
EXPECTED="MyApp-linux-x64-simd"
333+
echo "ARTIFACT_NAME=$ARTIFACT_NAME"
334+
if [[ "$ARTIFACT_NAME" != "$EXPECTED" ]]; then
335+
echo "::error::Expected '$EXPECTED' but got '$ARTIFACT_NAME' (only c-exports should be excluded)"
336+
exit 1
337+
fi
338+
echo "Partial exclusion works: $ARTIFACT_NAME"
339+
340+
- name: Test all features excluded produces no suffix
341+
shell: bash
342+
run: |
343+
ARTIFACT_NAME=$(./scripts/get-artifact-name.sh \
344+
--artifact-prefix "MyApp" \
345+
--target x86_64-unknown-linux-gnu \
346+
--features "foo,bar" \
347+
--exclude-features "foo,bar" \
348+
--use-friendly-target-names true \
349+
--artifact-type binary)
350+
EXPECTED="MyApp-linux-x64"
351+
echo "ARTIFACT_NAME=$ARTIFACT_NAME"
352+
if [[ "$ARTIFACT_NAME" != "$EXPECTED" ]]; then
353+
echo "::error::Expected '$EXPECTED' but got '$ARTIFACT_NAME' (all features should be excluded)"
354+
exit 1
355+
fi
356+
echo "All features excluded works: $ARTIFACT_NAME"
357+
358+
- name: Test whitespace trimmed from exclude list
359+
shell: bash
360+
run: |
361+
ARTIFACT_NAME=$(./scripts/get-artifact-name.sh \
362+
--artifact-prefix "MyApp" \
363+
--target x86_64-unknown-linux-gnu \
364+
--features "c-exports,simd" \
365+
--exclude-features " c-exports , simd " \
366+
--use-friendly-target-names true \
367+
--artifact-type binary)
368+
EXPECTED="MyApp-linux-x64"
369+
echo "ARTIFACT_NAME=$ARTIFACT_NAME"
370+
if [[ "$ARTIFACT_NAME" != "$EXPECTED" ]]; then
371+
echo "::error::Expected '$EXPECTED' but got '$ARTIFACT_NAME' (whitespace should be trimmed)"
372+
exit 1
373+
fi
374+
echo "Whitespace trimming works: $ARTIFACT_NAME"
375+
376+
- name: Test empty exclude list includes all features
377+
shell: bash
378+
run: |
379+
ARTIFACT_NAME=$(./scripts/get-artifact-name.sh \
380+
--artifact-prefix "MyApp" \
381+
--target x86_64-unknown-linux-gnu \
382+
--features "c-exports" \
383+
--exclude-features "" \
384+
--use-friendly-target-names true \
385+
--artifact-type binary)
386+
EXPECTED="MyApp-linux-x64-c-exports"
387+
echo "ARTIFACT_NAME=$ARTIFACT_NAME"
388+
if [[ "$ARTIFACT_NAME" != "$EXPECTED" ]]; then
389+
echo "::error::Expected '$EXPECTED' but got '$ARTIFACT_NAME' (empty exclude list should include all features)"
390+
exit 1
391+
fi
392+
echo "Empty exclude list works: $ARTIFACT_NAME"
393+
394+
- name: Test exact match only - c-exports does not exclude c-exports-extended
395+
shell: bash
396+
run: |
397+
ARTIFACT_NAME=$(./scripts/get-artifact-name.sh \
398+
--artifact-prefix "MyApp" \
399+
--target x86_64-unknown-linux-gnu \
400+
--features "c-exports-extended" \
401+
--exclude-features "c-exports" \
402+
--use-friendly-target-names true \
403+
--artifact-type binary)
404+
EXPECTED="MyApp-linux-x64-c-exports-extended"
405+
echo "ARTIFACT_NAME=$ARTIFACT_NAME"
406+
if [[ "$ARTIFACT_NAME" != "$EXPECTED" ]]; then
407+
echo "::error::Expected '$EXPECTED' but got '$ARTIFACT_NAME' (c-exports should NOT exclude c-exports-extended - exact match only)"
408+
exit 1
409+
fi
410+
echo "Exact match only works: $ARTIFACT_NAME"
411+
412+
- name: Test action.yml integration pattern with whitespace in exclude-features
413+
shell: bash
414+
run: |
415+
# Simulates the pattern used in action.yml where --exclude-features value is quoted
416+
ARTIFACT_SCRIPT="./scripts/get-artifact-name.sh"
417+
EXCLUDE_FEATURES_INPUT="c-exports, foo"
418+
419+
# This is the fixed pattern from action.yml: --exclude-features "value" (quoted)
420+
ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" \
421+
--artifact-prefix "MyApp" \
422+
--target x86_64-unknown-linux-gnu \
423+
--features "c-exports,foo" \
424+
--use-friendly-target-names true \
425+
--exclude-features "$EXCLUDE_FEATURES_INPUT" \
426+
--artifact-type binary)
427+
EXPECTED="MyApp-linux-x64"
428+
echo "ARTIFACT_NAME=$ARTIFACT_NAME"
429+
if [[ "$ARTIFACT_NAME" != "$EXPECTED" ]]; then
430+
echo "::error::Expected '$EXPECTED' but got '$ARTIFACT_NAME' (action.yml integration with whitespace should work)"
431+
exit 1
432+
fi
433+
echo "action.yml integration pattern with whitespace works: $ARTIFACT_NAME"

README.MD

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ To use this action in your own repository:
108108

109109
#### Artifact & Output Settings
110110

111-
| Input | Required | Default | Description |
112-
| --------------------------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------- |
113-
| `upload-artifacts` | No | `true` | Upload the built artifacts as a GitHub Actions artifact |
114-
| `upload-symbols-separately` | No | `true` | Upload debug symbol files (.pdb, .dwp, .dSYM) as separate artifacts instead of bundling with main artifacts |
115-
| `use-friendly-target-names` | No | `true` | Transform target triples to user-friendly names (e.g., `x86_64-unknown-linux-gnu` -> `linux-x64`) in artifact names. |
111+
| Input | Required | Default | Description |
112+
| -------------------------------- | -------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
113+
| `upload-artifacts` | No | `true` | Upload the built artifacts as a GitHub Actions artifact |
114+
| `upload-symbols-separately` | No | `true` | Upload debug symbol files (.pdb, .dwp, .dSYM) as separate artifacts instead of bundling with main artifacts |
115+
| `use-friendly-target-names` | No | `true` | Transform target triples to user-friendly names (e.g., `x86_64-unknown-linux-gnu` -> `linux-x64`) in artifact names. |
116+
| `artifact-name-exclude-features` | No | `c-exports` | Comma-separated list of features to exclude from artifact names. Features are still built but not included in artifact names. Set to empty string to include all. |
116117

117118
#### Advanced / Low-Level
118119

@@ -296,6 +297,21 @@ When `use-friendly-target-names` is enabled (default), the target triple is repl
296297
user-friendly platform identifier (e.g., `x86_64-unknown-linux-gnu` becomes `linux-x64`,
297298
`aarch64-apple-darwin` becomes `macos-arm64`). Unmapped targets fall back to the raw target triple.
298299

300+
#### Excluding Features from Artifact Names
301+
302+
Use `artifact-name-exclude-features` to exclude specific features from artifact names while still building them.
303+
This is useful when features are already distinguished by `artifact-prefix` (e.g., C library builds).
304+
305+
| Features | Exclude List | Resulting Suffix |
306+
| ---------------- | ------------ | ---------------- |
307+
| `c-exports` | `c-exports` | (none) |
308+
| `c-exports,simd` | `c-exports` | `-simd` |
309+
| `foo,bar` | `foo,bar` | (none) |
310+
| `bar,foo` | `foo,bar` | (none) |
311+
312+
The default exclusion is `c-exports`, which is commonly redundant for C library builds in Reloaded projects;
313+
where often the prefix is something like `c-library`. To include all features in names, set to an empty string `""`.
314+
299315
When `upload-symbols-separately` is enabled (default), debug symbols are uploaded as separate artifacts
300316
with a `.symbols` suffix:
301317

action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ inputs:
108108
'MyApp-linux-x64'). If empty, no prefix is used."
109109
required: false
110110
default: ""
111+
artifact-name-exclude-features:
112+
description: "Comma-separated list of features to exclude from artifact names. Set to empty string to include all."
113+
required: false
114+
default: "c-exports"
111115

112116
# ============================================================================
113117
# Advanced / Low-Level
@@ -260,10 +264,10 @@ runs:
260264
CRATE_NAME_ARG="--crate-name ${{ inputs.crate-name }}"
261265
fi
262266
263-
BINARY_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --artifact-type binary)
264-
BINARY_SYMBOLS_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --artifact-type binary-symbols)
265-
LIBRARY_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --artifact-type library)
266-
LIBRARY_SYMBOLS_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --artifact-type library-symbols)
267+
BINARY_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --exclude-features "${{ inputs.artifact-name-exclude-features }}" --artifact-type binary)
268+
BINARY_SYMBOLS_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --exclude-features "${{ inputs.artifact-name-exclude-features }}" --artifact-type binary-symbols)
269+
LIBRARY_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --exclude-features "${{ inputs.artifact-name-exclude-features }}" --artifact-type library)
270+
LIBRARY_SYMBOLS_ARTIFACT_NAME=$("$ARTIFACT_SCRIPT" --artifact-prefix "${{ inputs.artifact-prefix }}" $CRATE_NAME_ARG --target "${{ inputs.target }}" $FEATURES_ARG --use-friendly-target-names "${{ inputs.use-friendly-target-names }}" --exclude-features "${{ inputs.artifact-name-exclude-features }}" --artifact-type library-symbols)
267271
268272
echo "BINARY_ARTIFACT_NAME=${BINARY_ARTIFACT_NAME}" >> $GITHUB_ENV
269273
echo "BINARY_SYMBOLS_ARTIFACT_NAME=${BINARY_SYMBOLS_ARTIFACT_NAME}" >> $GITHUB_ENV

scripts/get-artifact-name.sh

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# Generates artifact names for Rust builds.
3-
# Usage: ./get-artifact-name.sh --target <target> --artifact-type <type> [--artifact-prefix <prefix>] [--crate-name <name>] [--features <features>] [--use-friendly-target-names <true|false>]
3+
# Usage: ./get-artifact-name.sh --target <target> --artifact-type <type> [--artifact-prefix <prefix>] [--crate-name <name>] [--features <features>] [--use-friendly-target-names <true|false>] [--exclude-features <features>]
44
# Outputs the artifact name to stdout.
55

66
set -euo pipefail
@@ -14,6 +14,7 @@ TARGET=""
1414
FEATURES=""
1515
USE_FRIENDLY_TARGET_NAMES="true"
1616
ARTIFACT_TYPE=""
17+
EXCLUDE_FEATURES=""
1718

1819
# Parse named parameters
1920
while [[ $# -gt 0 ]]; do
@@ -42,6 +43,10 @@ while [[ $# -gt 0 ]]; do
4243
ARTIFACT_TYPE="$2"
4344
shift 2
4445
;;
46+
--exclude-features)
47+
EXCLUDE_FEATURES="$2"
48+
shift 2
49+
;;
4550
*)
4651
echo "Unknown parameter: $1" >&2
4752
exit 1
@@ -77,9 +82,51 @@ else
7782
TARGET_FOR_ARTIFACT="$TARGET"
7883
fi
7984

85+
# Filter features by excluding specified features from the list
86+
# Args: $1 = features string (comma-separated), $2 = exclude list (comma-separated)
87+
# Returns: filtered features (comma-separated) or empty string
88+
filter_features() {
89+
local features="$1"
90+
local exclude_list="$2"
91+
92+
# If no features or no exclude list, return features as-is
93+
if [[ -z "$features" ]] || [[ -z "$exclude_list" ]]; then
94+
echo "$features"
95+
return
96+
fi
97+
98+
# Build associative array of features to exclude (with whitespace trimming)
99+
declare -A exclude_map
100+
IFS=',' read -ra exclude_array <<< "$exclude_list"
101+
for item in "${exclude_array[@]}"; do
102+
# Trim leading/trailing whitespace
103+
trimmed=$(echo "$item" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
104+
if [[ -n "$trimmed" ]]; then
105+
exclude_map["$trimmed"]=1
106+
fi
107+
done
108+
109+
# Filter features, keeping only those not in exclude list
110+
local result=()
111+
IFS=',' read -ra features_array <<< "$features"
112+
for feature in "${features_array[@]}"; do
113+
# Trim leading/trailing whitespace
114+
trimmed=$(echo "$feature" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
115+
if [[ -n "$trimmed" ]] && [[ -z "${exclude_map[$trimmed]:-}" ]]; then
116+
result+=("$trimmed")
117+
fi
118+
done
119+
120+
# Join result with commas
121+
local IFS=','
122+
echo "${result[*]}"
123+
}
124+
80125
# Generate feature suffix: -features if set, empty if not
81-
if [[ -n "$FEATURES" ]]; then
82-
FEATURE_SUFFIX="-$FEATURES"
126+
# Apply exclusion filter before generating suffix
127+
FILTERED_FEATURES=$(filter_features "$FEATURES" "$EXCLUDE_FEATURES")
128+
if [[ -n "$FILTERED_FEATURES" ]]; then
129+
FEATURE_SUFFIX="-$FILTERED_FEATURES"
83130
else
84131
FEATURE_SUFFIX=""
85132
fi

0 commit comments

Comments
 (0)