koenrh / dnscontrol-action

Deploy your DNS configuration using GitHub Actions using DNSControl.
ISC License
80 stars 38 forks source link

Define an output in the action file #26

Closed svenluijten closed 4 years ago

svenluijten commented 4 years ago

We'll set an output in the Actions metadata file (link) so users can do something with that output.


My specific usecase was that I want my own GitHub action to comment the diff of dnscontrol preview on the PR, instead of having to dig down into the "Checks" tab after every push. I'm open to other names than "output", but I wanted to keep it nice and generic, as "diff" wouldn't be suitable for commands like dnscontrol push or check.

koenrh commented 4 years ago

Thank you for the suggestion. That seems very useful.

If I understand it correctly, this PR only defines the output parameter, and we would still need to set the parameter value to the out put of the dnscontrol command.

https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter

Not tested, but looks like something like this should work:

dnsc_out="$(dnscontrol $*)"
echo "::set-output name=output::${dnsc_out}"
echo "$dnsc_out"
svenluijten commented 4 years ago

I was under the impression that anything that lands in stdout will be piped to the output automatically, and ::set-output (and those other "workflow commands") should only be used in workflows, not in the actions themselves.

From the page you linked:

image

But as you said, that's completely untested and only based on what I've read in the docs. I will do some testing later today/over the weekend and get back to you actually. This was just a late night idea anyway 😛

koenrh commented 4 years ago

I think you are right.

This example seems to confirm that:

https://github.com/actions/cache/blob/b8204782bbb5f872091ecc5eb9cb7d004e35b1fa/action.yml#L14-L16

And then use the output (e.g. steps.restore-cache.outputs.cache-hit) in a workflow step:

# Re-export dependencies if anything has changed or if it is the first time
- name: Setting dependency cache 
  run: |
    esy export-dependencies
  if: steps.restore-cache.outputs.cache-hit != 'true'

https://github.com/actions/cache/blob/eed9cfe64d00dd64cbb36bec915d41dd6fab9f6c/examples.md#ocamlreason---esy

svenluijten commented 4 years ago

Turns out that's enough for Javascript actions, but for Docker ones (like this one), you'd still need to manually set the output parameter in entrypoint.sh: https://github.com/actions/hello-world-docker-action/blob/b136eb8894c5cb1dd5807da824be97ccdf9b5423/entrypoint.sh 😄

This seems to work now, the output of the dnscontrol command is piped out to the output parameter correctly. I'm open to changing the name though, outputs.output isn't very telling at the moment. 😛

svenluijten commented 4 years ago

Messed up the git history a bit, but it's good now. You can see it (and its "work in progress" 😅 ) at https://github.com/svenluijten/dns/pull/3.

svenluijten commented 4 years ago

Thanks for the merge @koenrh! 🎉

Could you also tag a version? 😬 Don't really wanna use @master for obvious reasons haha. Or did you want to wait for #28? Can I help?

koenrh commented 4 years ago

Both done! Use the specific version v3.3.0 or the major version v3.

svenluijten commented 4 years ago

🙌 Thank you!