Skip to content
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

add result output #11

Closed

Conversation

thattommyhall
Copy link

I am using this to do chat-ops with peter-evans/{slash-command-dispatch|create-or-update-comment}

      - name: Apply
        id: apply
        uses: ./.github/actions/octodns-sync
        env:
          DNSIMPLE_TOKEN:  ${{ secrets.DNSIMPLE_TOKEN }}
        with:
          config_path: config.yaml

      - name: Add reaction
        uses: peter-evans/create-or-update-comment@v1
        with:
          token: ${{ secrets.PAT }}
          repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
          issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
          body: |
            DID IT!

            ```
            ${{ steps.apply.outputs.result }}
            ```

Comment on lines -42 to +46
octodns-sync --config-file="${_config_path}" --doit
RESULT=$(octodns-sync --config-file="${_config_path}" --log-stream-stdout --doit)
else
octodns-sync --config-file="${_config_path}"
RESULT=$(octodns-sync --config-file="${_config_path}" --log-stream-stdout)
fi
echo "$RESULT"
Copy link
Owner

Choose a reason for hiding this comment

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

Here, rather than route the output through an environment variable will it work to store it in a file? For example:

octodns-sync --config-file="${_config_path}" --log-stream-stdout | tee /tmp/octodns-sync.log

Then you could use the Setting the comment body from a file approach to use the output in the next step of your job.

This way octodns-sync would still output directly for the Actions log and the unmodified output would remain available for other uses in addition to this specific case with peter-evans' Actions.

I'll setup a test for this later today or tomorrow. If you happen to check it in the meantime, @thattommyhall, I'll be curious to hear what you find.

Copy link
Owner

Choose a reason for hiding this comment

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

🎉

@thattommyhall to illustrate that ☝️ I made an example in https://github.com/solvaholic/ideal-octo-pancake.

I pushed a new version of the solvaholic/octodns-sync container to Docker hub that writes the octodns-sync output to a file:

# Run octodns-sync.
echo "INFO: _config_path: ${_config_path}"
if [ "${_doit}" = "--doit" ]; then
  octodns-sync --config-file="${_config_path}" \
  --log-stream-stdout --doit | tee ${GITHUB_WORKSPACE}/octodns-sync.log
else
  octodns-sync --config-file="${_config_path}" \
  --log-stream-stdout | tee ${GITHUB_WORKSPACE}/octodns-sync.log
fi

And added a step to the workflow job to parse the output from the file:

      - id: get-comment-body
        run: |
          body=$(cat ${GITHUB_WORKSPACE}/octodns-sync.log)
          body="${body//'%'/'%25'}"
          body="${body//$'\n'/'%0A'}"
          body="${body//$'\r'/'%0D'}" 
          echo ::set-output name=body::$body

The automation added this: https://github.com/solvaholic/ideal-octo-pancake/pull/1#issuecomment-706599506

Would that approach meet your needs?

@solvaholic solvaholic self-assigned this Oct 8, 2020
@solvaholic solvaholic added the enhancement New feature or request label Oct 8, 2020
@solvaholic solvaholic mentioned this pull request Oct 11, 2020
@solvaholic solvaholic changed the base branch from master to main November 3, 2020 17:18
@solvaholic
Copy link
Owner

In #24 I switched this to use screen rather than tee, and preserve the exit code.

@thattommyhall I'll mark this pull request closed. Please do re-open if the log file won't meet your needs or we've more to discuss.

Thank you 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants