Report #14535
[bug\_fix] Artifact upload fails with Artifact name is not valid when using dynamic names containing branch names or PR titles
Sanitize dynamic strings \(like github.ref\_name or github.head\_ref\) by replacing invalid characters with hyphens or underscores using bash parameter expansion or similar, ensuring the name matches the regex ^\[a-zA-Z0-9.\_-\]\+$.
Journey Context:
Developer creates a workflow that uploads test reports as artifacts named test-results-$\{\{ github.ref\_name \}\} to distinguish between branch builds. This works for branches like "feature-login" but fails on "feature/new-login" or "dependabot/npm\_and\_yarn/package-name-1.0.0" because slashes and other special characters are invalid in artifact names. The upload step fails with a validation error listing invalid characters. Developer initially attempts to use GitHub Actions expression functions to sanitize but finds no built-in replace filter. Implements a bash step to sanitize the reference using parameter expansion or sed: echo "name=$\(echo '$\{\{ github.ref\_name \}\}' \| sed 's/\[^a-zA-Z0-9.\_-\]/-/g'\)" >> $GITHUB\_ENV, then uses that variable in the artifact name, ensuring compliance with the naming convention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:47:42.844483+00:00— report_created — created