DEV Community

Cover image for 🤖 Learning GitHub Actions: Creating Beautiful PR Comments
Ivan Shcheklein
Ivan Shcheklein

Posted on

🤖 Learning GitHub Actions: Creating Beautiful PR Comments

You've probably seen the services that automatically generate GitHub PR comments with tables, images, links? Something like these two:

Codecov and Calibre reports

Magic, right ✨? Let's see how it can be done. We won't even need to use command line or offline editors this time!. This post covers:

  • How to create a "Hello world!" GitHub action online
  • Use CML scripts to generate comments with a custom Markdown that includes a picture 🖼.

Read more about CML. Besides GitHub comments, it can do the same for GitLab. Also, it's important that it was built with Machine Learning workflow in mind and automates a lot of tedious tasks in ML. besides simple reports.


Step 1: Create Action File

You can do this using GitHub online UI! Add the file .github/workflows/cml.yaml to your repo like this:

Btw, I've forked the DVC example get started repo to play with actions in this tutorial - feel free to do the same 😊

Create GitHub Action


Step 2: Add "Hello world!" Action

Feel free to copy-paste it from this gist:

Hello World Action


Step 3: Add Images 🖼️

That's where the the magic ✨ happens! Let's update a few lines of code like this (copy-paste from this gist):

Magic

cml-publish prc.svg --md >> report.md
cml-send-comment report.md

That's pretty all you need if you use the CML docker to run the action!

We specifically don't focus on the other three lines of the action, those that generate the image. It's out of scope of this post and it's specific to the repository. We definitely recommend reading it and DVC docs if you are machine learning practitioner.

cml-publish - saves an image and creates an ![Image](link) entry in the Markdown file report.md

cml-send-comment - sends the comment to GitHub to get the result 👇

Step 4: Profit 💥

Profit

The result looks like this:

Result

In this case it includes a precision-recall curve which is a fundamental and useful characteristic for a binary classifier. But you can include any images, any text using Markdown markup to create your own unique and useful report!


That's it for today 👌

We've just barely scratched the surface of the GitHub actions and CML capabilities! We definitely recommend taking a look at the actions marketplace.

And of course, read more about CML. Besides GitHub comments, it can do the same for GitLab. It was built with Machine Learning workflow in mind and automates a lot of tedious tasks in ML - like running training remotely.

Oldest comments (5)

Collapse
 
drelleobrien profile image
Elle O'Brien

The gifs are awesome- how did you make zoom-in and zoom-out effects???

Collapse
 
shcheklein profile image
Ivan Shcheklein

Hey, thanks! :)

Thanks 🙏 ! :) I made them using a few tools (all free):

Collapse
 
igcp profile image
Igor Conde • Edited

Thank you very much, for the tips I tested some repos and it works perfectly.
Only one thing the gist link is incorrect, I ended up managing to do the tests because I went to the profile I got the right link, both links the same

Collapse
 
shcheklein profile image
Ivan Shcheklein

Omg 😱 ! Thanks for the comment! I've fixed the link. And sorry about that.

Collapse
 
mustafaydemir profile image
Mustafa Aydemir

Thanks!