Error in passing multiline string to workflow_dispatch inputs #70754
Unanswered
Undertone0809
asked this question in
Actions
Replies: 1 comment
-
|
A practical workaround is to avoid interpolating the multiline value directly into the shell script body. Put the dispatch input into an environment variable first, then read that environment variable from Python or write it to a file. That avoids most quoting/newline surprises. on:
workflow_dispatch:
inputs:
raw_requirement:
description: user raw requirement
type: string
required: true
jobs:
chat:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Save dispatch input
env:
RAW_REQUIREMENT: ${{ inputs.raw_requirement }}
run: |
python - <<'PY'
import os
from pathlib import Path
Path("raw_requirement.txt").write_text(os.environ["RAW_REQUIREMENT"])
PY
- name: Use input
run: |
poetry run python your_script.py --requirement-file raw_requirement.txtIf you need to pass a multiline value between steps, use the documented environment-file delimiter form for {
echo "RAW_REQUIREMENT<<EOF"
cat raw_requirement.txt
echo "EOF"
} >> "$GITHUB_ENV"Two caveats:
Relevant docs: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#multiline-strings |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Bug
Body
So here is my yml
As you can see, my parameter "raw_requirement" is a string. An example like: I want to build a web app.
Expected command is
poetry run chat --raw_requirement "I want to build a web app".Actual command is
poetry run chat --raw_requirement I want to build a web app.An error will occur if not "". Therefore, the output result in this case is as follows:
Q1: Why
raw_requirementis not a string even if I settype: string?I realize I can use
poetry run chat --raw_requirement "${{ github.event.inputs.raw_requirement }}"to solve the problem. So another question is: It doesn't work if I have "" in my raw_requirement.Q2: Is there a solution in this case?
I know to can use
\"to replace it. But is there any better solution?Q3: What should I do if i want to pass a multiline string parameter in
inputs?Beta Was this translation helpful? Give feedback.
All reactions