The above answers all had pieces, but this is what worked for me in a github composite action. It should work in a regular workflow too.
As @lorenzo-bettini said, if you want everything to be on one line, use what @Josue Alexander Ibarra called a Folded Block Scalar
.
run: >
xvfb-run
./mvnw -f my/pom.xml
clean verify
-DskipTests
newlines will be replaced with spaces so the above is equivalent to
run: xvfb-run ./mvnw -f my/pom.xml clean verify -DskipTests
If you want new lines to be preserved, use what @Josue Alexander Ibarra called a Literal Block Scalar
.
run: |
FILE=./package.json
if test -f "$FILE"
then
echo "$FILE exists."
else
echo "File does not exist"
fi
When you do a multi-line run, though, you have to make sure you indent correctly, otherwise step
will think that shell: bash
is part of the run: |
string.
WRONG:
steps:
- run: |
FILE=./package.json
if test -f "$FILE"
then
echo "$FILE exists."
else
echo "File does not exist"
fi
shell: bash
RIGHT:
steps:
- run: |
FILE=./package.json
if test -f "$FILE"
then
echo "$FILE exists."
else
echo "File does not exist"
fi
shell: bash