Skip to content

Commit 0f9229d

Browse files
committed
feat(workflows): add smart detection for script names vs commands in provenance workflow
Update setup-script, publish-script, and access-script to accept both: - Script names (e.g., "ci:validate", "publish:ci") - automatically prefixed with "pnpm run" - Commands (e.g., "pnpm run build", "npm publish --access public") - run as-is Detection logic: - If value contains spaces or shell operators (&&, ||, ;, |) -> run as command - Otherwise -> treat as script name and prefix with "pnpm run" - Trim whitespace from all inputs for safety Benefits: - Backward compatible with existing usage - Supports both simple script names and complex commands - Prevents argument parsing issues with shell operators - More flexible for different publishing scenarios Changes: - Add whitespace trimming using xargs - Add space/operator detection with regex - Update input descriptions to document both patterns - Apply to all three script inputs consistently
1 parent 89c1d6d commit 0f9229d

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

.github/workflows/provenance.yml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_call:
88
inputs:
99
access-script:
10-
description: 'pnpm script to run for access control (e.g., "package-npm-access")'
10+
description: 'Package access control script - either a pnpm script name (e.g., "package-npm-access") or a command'
1111
required: false
1212
type: string
1313
default: ''
@@ -47,7 +47,7 @@ on:
4747
type: string
4848
default: ''
4949
publish-script:
50-
description: 'pnpm script to run for publishing (e.g., "package-npm-publish")'
50+
description: 'Publishing script - either a pnpm script name (e.g., "publish:ci") or a command (e.g., "npm publish --access public")'
5151
required: false
5252
type: string
5353
default: ''
@@ -67,7 +67,7 @@ on:
6767
type: string
6868
default: ''
6969
setup-script:
70-
description: 'Setup script before publishing (e.g., "pnpm run build")'
70+
description: 'Setup script before publishing - either a pnpm script name (e.g., "ci:validate") or a command (e.g., "pnpm run build")'
7171
required: false
7272
type: string
7373
default: ''
@@ -132,7 +132,18 @@ jobs:
132132
if: inputs.setup-script != ''
133133
env:
134134
SETUP_SCRIPT: ${{ inputs.setup-script }}
135-
run: $SETUP_SCRIPT
135+
run: |
136+
# Trim whitespace
137+
SETUP_SCRIPT=$(echo "$SETUP_SCRIPT" | xargs)
138+
139+
# Detect if it contains spaces or shell operators (command) vs script name
140+
if [[ "$SETUP_SCRIPT" =~ ( |&&|\|\||;|\|) ]]; then
141+
# Contains space or shell operators - run as command
142+
$SETUP_SCRIPT
143+
else
144+
# Script name only - run as pnpm script
145+
pnpm run $SETUP_SCRIPT
146+
fi
136147
137148
- name: Publish with custom script
138149
if: inputs.publish-script != ''
@@ -143,6 +154,9 @@ jobs:
143154
FORCE_REGISTRY: ${{ inputs.force-registry }}
144155
SKIP_NPM_PACKAGES: ${{ inputs.skip-npm-packages }}
145156
run: |
157+
# Trim whitespace
158+
PUBLISH_SCRIPT=$(echo "$PUBLISH_SCRIPT" | xargs)
159+
146160
FLAGS=""
147161
if [ "$FORCE_PUBLISH" = "true" ]; then
148162
FLAGS="$FLAGS --force-publish"
@@ -153,10 +167,18 @@ jobs:
153167
if [ "$SKIP_NPM_PACKAGES" = "true" ]; then
154168
FLAGS="$FLAGS --skip-npm-packages"
155169
fi
156-
if [ -n "$FLAGS" ]; then
157-
pnpm run $PUBLISH_SCRIPT -- $FLAGS
170+
171+
# Detect if it contains spaces or shell operators (command) vs script name
172+
if [[ "$PUBLISH_SCRIPT" =~ ( |&&|\|\||;|\|) ]]; then
173+
# Contains space or shell operators - run as command
174+
$PUBLISH_SCRIPT
158175
else
159-
pnpm run $PUBLISH_SCRIPT
176+
# Script name only - run as pnpm script
177+
if [ -n "$FLAGS" ]; then
178+
pnpm run $PUBLISH_SCRIPT -- $FLAGS
179+
else
180+
pnpm run $PUBLISH_SCRIPT
181+
fi
160182
fi
161183
162184
- name: Publish package
@@ -170,7 +192,18 @@ jobs:
170192
if: inputs.access-script != ''
171193
env:
172194
ACCESS_SCRIPT: ${{ inputs.access-script }}
173-
run: pnpm run $ACCESS_SCRIPT
195+
run: |
196+
# Trim whitespace
197+
ACCESS_SCRIPT=$(echo "$ACCESS_SCRIPT" | xargs)
198+
199+
# Detect if it contains spaces or shell operators (command) vs script name
200+
if [[ "$ACCESS_SCRIPT" =~ ( |&&|\|\||;|\|) ]]; then
201+
# Contains space or shell operators - run as command
202+
$ACCESS_SCRIPT
203+
else
204+
# Script name only - run as pnpm script
205+
pnpm run $ACCESS_SCRIPT
206+
fi
174207
175208
- name: Set MFA automation
176209
if: inputs.access-script == '' && inputs.package-name != ''

0 commit comments

Comments
 (0)