Skip to content

fix: multiline output #163

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

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,69 @@ permissions:
pull-requests: write

jobs:
output:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4

- name: "Use output"
id: use-output
uses: ./
with:
version: latest
verb: core
args: container from --address=alpine with-exec --args echo,-n,"hello world" stdout
- name: "Use output (check)"
run: |
target='${{ steps.use-output.outputs.output }}'
if [[ "$target" == "hello world" ]]; then
echo "matches"
exit 0
else
echo "does not match"
exit 1
fi

- name: "Use trailing output"
id: use-trailing-output
uses: ./
with:
version: latest
verb: core
args: container from --address=alpine with-exec --args echo,-n,-e,"hello world\n" stdout
- name: "Use output (check)"
run: |
target='${{ steps.use-trailing-output.outputs.output }}'
result='hello world
'
if [[ "$target" == "$result" ]]; then
echo "matches"
exit 0
else
echo "does not match"
exit 1
fi

- name: "Use multiline output"
id: use-multiline-output
uses: ./
with:
version: latest
verb: core
args: container from --address=alpine with-exec --args echo,-n,-e,"hello\nworld" stdout
- name: "Use output (check)"
run: |
target='${{ steps.use-multiline-output.outputs.output }}'
result='hello
world'
if [[ "$target" == "$result" ]]; then
echo "matches"
exit 0
else
echo "does not match"
exit 1
fi

version:
runs-on: "ubuntu-latest"
steps:
Expand Down
15 changes: 11 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,24 @@ runs:
INPUT_MODULE: ${{ inputs.module }}
run: |
tmpout=$(mktemp)
ARGS="${{ inputs.args }}"
ARGS="${ARGS:-"${{ inputs.call }}"}"
cd ${{ inputs.workdir }} && { \
DAGGER_CLOUD_TOKEN=${{ inputs.cloud-token }} \
dagger \
${{ inputs.dagger-flags }} \
${{ inputs.verb }} \
${INPUT_MODULE:+-m $INPUT_MODULE} \
$ARGS; } | tee "${tmpout}"
${{ inputs.args || inputs.call }}; } | tee "${tmpout}"

(echo -n "stdout=" && cat "${tmpout}") >> "$GITHUB_OUTPUT"
{
# we need a delim that doesn't appear in the output - a hash of the
# file itself *probably* won't (if it does, we have larger
# cryptographic problems)
delim="$(sha256sum $tmpout | cut -d " " -f1)"
echo "stdout<<${delim}"
cat "${tmpout}"
echo
echo "${delim}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is very creative

Copy link
Member Author

@jedevc jedevc Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😜 hehe ye, better suggestions appreciated if you have them, I didn't want to use a fixed EOF string on the off chance that that appeared in the output.

} >> "$GITHUB_OUTPUT"

- if: (inputs.call != '' || inputs.args != '') && inputs.engine-stop == 'true'
shell: bash
Expand Down