-
Notifications
You must be signed in to change notification settings - Fork 25
ci(publish): add packages input for batched publishing #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,11 @@ on: | |
| required: true | ||
| type: string | ||
| default: latest | ||
| packages: | ||
| description: "Space-separated list of packages to publish" | ||
| required: false | ||
| type: string | ||
| default: "bitwarden-api-api bitwarden-api-identity bitwarden-cli bitwarden-core bitwarden-crypto bitwarden-encoding bitwarden-error bitwarden-error-macro bitwarden-generators bitwarden-sm bitwarden-state bitwarden-threading bitwarden-uuid bitwarden-uuid-macro" | ||
|
|
||
| jobs: | ||
| setup: | ||
|
|
@@ -121,23 +126,10 @@ jobs: | |
| env: | ||
| PUBLISH_GRACE_SLEEP: 10 | ||
| CARGO_REGISTRY_TOKEN: ${{ steps.retrieve-secrets.outputs.cratesio-api-token }} | ||
| PACKAGES_INPUT: ${{ inputs.packages }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security: Potential Command Injection Vulnerability The Issue: If malicious input contains backticks, Example Attack: Recommendation: Quote the variable assignment: PACKAGES_INPUT: "${{ inputs.packages }}"Or validate input against an allowlist pattern before use. |
||
| run: | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Best Practice: Add Script Debugging and Safety The bash script lacks safety flags and debugging output. Recommendations:
set -euo pipefail
echo "Input packages: $PACKAGES_INPUT"
echo "Parsed package count: ${#PACKAGES[@]}"
echo "Package list: ${PACKAGES[*]}"
if [[ ${#PACKAGES[@]} -eq 0 ]]; then
echo "Error: No packages to publish"
exit 1
fiExample improved script: run: |
set -euo pipefail
# Validate input
if [[ -z "${PACKAGES_INPUT// /}" ]]; then
echo "Error: packages input cannot be empty"
exit 1
fi
# Convert space-separated string to array
IFS=' ' read -ra PACKAGES <<< "$PACKAGES_INPUT"
# Filter empty elements
PACKAGES_FILTERED=()
for pkg in "${PACKAGES[@]}"; do
[[ -n "$pkg" ]] && PACKAGES_FILTERED+=("$pkg")
done
# Validate non-empty
if [[ ${#PACKAGES_FILTERED[@]} -eq 0 ]]; then
echo "Error: No valid packages after parsing"
exit 1
fi
echo "Publishing ${#PACKAGES_FILTERED[@]} packages: ${PACKAGES_FILTERED[*]}"
# Build flags and execute
PACKAGE_FLAGS=$(printf -- '-p %s ' "${PACKAGES_FILTERED[@]}")
cargo-release release publish $PACKAGE_FLAGS --execute --no-confirm |
||
| PACKAGES=( | ||
| bitwarden-api-api | ||
| bitwarden-api-identity | ||
| bitwarden-cli | ||
| bitwarden-core | ||
| bitwarden-crypto | ||
| bitwarden-encoding | ||
| bitwarden-error | ||
| bitwarden-error-macro | ||
| bitwarden-generators | ||
| bitwarden-sm | ||
| bitwarden-state | ||
| bitwarden-threading | ||
| bitwarden-uuid | ||
| bitwarden-uuid-macro | ||
| ) | ||
| # Convert space-separated string to array | ||
| IFS=' ' read -ra PACKAGES <<< "$PACKAGES_INPUT" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edge Case: Whitespace Handling Issues The
Impact: Could result in invalid package flags like Recommendation: Use a more robust parsing approach: # Normalize whitespace and filter empty elements
PACKAGES_INPUT=$(echo "$PACKAGES_INPUT" | xargs)
IFS=' ' read -ra PACKAGES <<< "$PACKAGES_INPUT"Or use array filtering: IFS=' ' read -ra PACKAGES_RAW <<< "$PACKAGES_INPUT"
PACKAGES=()
for pkg in "${PACKAGES_RAW[@]}"; do
[[ -n "$pkg" ]] && PACKAGES+=("$pkg")
done |
||
| PACKAGE_FLAGS=$(printf -- '-p %s ' "${PACKAGES[@]}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security: Unvalidated Package Names Package names from user input are used directly to construct command-line flags without validation. This creates risks:
Impact: Could publish wrong packages, fail the workflow, or in worst case, execute unintended commands. Recommendation: Validate package names against a known allowlist: # Define allowed packages
ALLOWED_PACKAGES="bitwarden-api-api bitwarden-api-identity bitwarden-cli bitwarden-core bitwarden-crypto bitwarden-encoding bitwarden-error bitwarden-error-macro bitwarden-generators bitwarden-sm bitwarden-state bitwarden-threading bitwarden-uuid bitwarden-uuid-macro"
# Validate each package
for pkg in "${PACKAGES[@]}"; do
if ! echo "$ALLOWED_PACKAGES" | grep -qw "$pkg"; then
echo "Error: Invalid package name: $pkg"
exit 1
fi
doneOr use workspace member validation: WORKSPACE_MEMBERS=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].name')
for pkg in "${PACKAGES[@]}"; do
if ! echo "$WORKSPACE_MEMBERS" | grep -qx "$pkg"; then
echo "Error: Package not in workspace: $pkg"
exit 1
fi
done |
||
| cargo-release release publish $PACKAGE_FLAGS --execute --no-confirm | ||
addisonbeck marked this conversation as resolved.
Show resolved
Hide resolved
addisonbeck marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Robustness: Missing Error Handling Several error conditions are not handled:
Impact: Could publish unintended packages or fail silently. Recommendations:
if [[ -z "$PACKAGES_INPUT" || "$PACKAGES_INPUT" =~ ^[[:space:]]*$ ]]; then
echo "Error: packages input cannot be empty"
exit 1
fi
if [[ ${#PACKAGES[@]} -eq 0 ]]; then
echo "Error: No valid packages to publish"
exit 1
fi
echo "Publishing packages: ${PACKAGES[*]}"
echo "Package flags: $PACKAGE_FLAGS"
cargo-release release publish $PACKAGE_FLAGS --execute --no-confirmShould be: # Or better, use array directly:
cargo-release release publish "${PACKAGES[@]/#/-p }" --execute --no-confirm |
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design: Input Validation at Workflow Level
While GitHub Actions
type: stringprevents some injection, it doesn't validate:Recommendation: Consider adding a description that documents expected format:
Note: This doesn't prevent issues but improves UX. The bash script must still validate input.