<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Taras Savchyn</title>
    <description>The latest articles on DEV Community by Taras Savchyn (@trsvchn).</description>
    <link>https://dev.to/trsvchn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F267761%2F021f6964-0b57-49ee-bfc1-c17b29ca2a98.png</url>
      <title>DEV Community: Taras Savchyn</title>
      <link>https://dev.to/trsvchn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/trsvchn"/>
    <language>en</language>
    <item>
      <title>Jupyter &amp; Co: GitHub Action For Colab Badges Generation </title>
      <dc:creator>Taras Savchyn</dc:creator>
      <pubDate>Thu, 09 Dec 2021 07:07:59 +0000</pubDate>
      <link>https://dev.to/trsvchn/jupyter-co-github-action-for-colab-badges-generation-5d7p</link>
      <guid>https://dev.to/trsvchn/jupyter-co-github-action-for-colab-badges-generation-5d7p</guid>
      <description>&lt;h3&gt;
  
  
  My Workflow
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;GitHub, take these badges off of me I can't use them anymore...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The following workflow aims to help you to organize your data science/machine learning code. If you maintain the project on GitHub with dozens of Jupyter notebooks, and in addition, you or your target audience are active Google Colab users there is a non-zero chance that you will find this action pretty useful. At least it will help you to reduce some boilerplating by introducing some automation to "Open in Colab" badge generation.&lt;/p&gt;

&lt;p&gt;&lt;a href=""&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cw8uDh-t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" width="117" height="20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Colab Badge Action
&lt;/h4&gt;

&lt;p&gt;The usage is extremely straightforward, you just need to add the following badge tag: &lt;code&gt;{{ badge }}&lt;/code&gt; to the notebook (think of it like Liquid or Jinja), and action will generate a valid "Open in Colab" badge for that notebook. For example, you added the badge tag to the &lt;code&gt;my_notebook.ipynb&lt;/code&gt;, during the run action will find that tag and replace it with the badge containing a link for that notebook. Now you are able to open &lt;code&gt;my_notebook.ipynb&lt;/code&gt; in Colab by pressing on that badge.&lt;/p&gt;

&lt;p&gt;In addition, action tracks the changes, and if the file was moved or renamed, action will update the badge information of that particular notebook.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; you can use this tag only inside markdown cells, all the &lt;code&gt;code&lt;/code&gt; and &lt;code&gt;raw&lt;/code&gt; cells are ignored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Before the version 4 release, only one option was available - to generate a badge for the notebook pointing to itself (self linking). In other words, it wasn't possible to generate a badge for &lt;code&gt;notebook2&lt;/code&gt; and put it inside &lt;code&gt;notebook1&lt;/code&gt; and vice versa (cross-linking).&lt;/p&gt;

&lt;h4&gt;
  
  
  Announcing Colab Badge Action v4!
&lt;/h4&gt;

&lt;p&gt;The new release of Colab Badge Action introduces some major changes. First of all, support for cross-linking and markdown files. Now you can generate a badge for any notebook hosted on GitHub, or Google Drive, and insert it not only in the markdown cell of your notebook but in plain markdown files, for example in &lt;code&gt;README.md&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's a take look at how it works with the examples.&lt;/p&gt;

&lt;p&gt;This update introduces an argument &lt;code&gt;notebook_path&lt;/code&gt; to the already known &lt;code&gt;{{ badge }}&lt;/code&gt; tag: &lt;code&gt;{{ badge &amp;lt;notebook_path&amp;gt; }}&lt;/code&gt;. Where &lt;code&gt;&amp;lt;notebook_path&amp;gt;&lt;/code&gt; can be a local path: &lt;code&gt;{{ badge notebooks/my_nb.ipynb }}&lt;/code&gt;, a link to the notebook from another repo &lt;code&gt;{{ badge https://github.com/not_me/not_my_repo/not_my_notebooks/blob/main/not_my_nb.ipynb }}&lt;/code&gt; or Google Drive id with &lt;code&gt;//drive&lt;/code&gt; prepended: &lt;code&gt;{{ badge //drive/112345 }}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For the 2nd example you can omit &lt;code&gt;https://github.com&lt;/code&gt; part and simply do &lt;code&gt;{{ badge /not_me/not_my_repo/not_my_notebooks/blob/main/not_my_nb.ipynb }}&lt;/code&gt;. But it is important to keep the leading &lt;code&gt;/&lt;/code&gt;, it indicates that the notebook is not local (no leading &lt;code&gt;/&lt;/code&gt;, and as you may also notice local path has no repo name, no branch name, cwd is a repo dir, so there is need to specify) and not from Google Drive (&lt;code&gt;//drive&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;In all cases (except drive) you can omit file extension, action will append it for you: &lt;code&gt;{{ badge notebooks/my_nb }}&lt;/code&gt; and &lt;code&gt;{{ badge /not_me/not_my_repo/not_my_notebooks/blob/main/not_my_nb }}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Another useful feature added in this release is that during the badge generation procedure action now will verify the existence of the provided &lt;code&gt;&amp;lt;notebook_path&amp;gt;&lt;/code&gt;. This feature works for notebooks hosted on GitHub and currently is not supported for notebooks from Google Drive.&lt;/p&gt;

&lt;p&gt;In this case, when the file was found, action will provide information about the problem:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XMuJzSVj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4uq2hhbne4cd57liu6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XMuJzSVj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4uq2hhbne4cd57liu6s.png" alt="Example error" width="570" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and point to the exact file and line using the awesome GitHub Actions Annotations feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XYioGk1V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4mh1w0gjnfuqursr5pw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XYioGk1V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4mh1w0gjnfuqursr5pw.png" alt="Example error in PR" width="625" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, Colab Badge Action does only one thing: "Open in Colab" badge creation. To get it to work you need checkout action - to pull a repo and commit&amp;amp;push action - to push the updated notebooks. You can find example workflows below.&lt;/p&gt;

&lt;h3&gt;
  
  
  Submission Category:
&lt;/h3&gt;

&lt;p&gt;Maintainer Must-Haves&lt;/p&gt;

&lt;h3&gt;
  
  
  Yaml File or Link to Code
&lt;/h3&gt;

&lt;p&gt;Here is how to use the action in general, for example, if you want to adopt it to your existing workflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; use newly released version &lt;code&gt;v4&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
      &lt;span class="c1"&gt;# First do checkout&lt;/span&gt;
      &lt;span class="s"&gt;...&lt;/span&gt;
      &lt;span class="s"&gt;- name&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Add Colab Badges&lt;/span&gt;
        &lt;span class="s"&gt;uses&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s"&gt;trsvchn/colab-badge-action@v4&lt;/span&gt;
        &lt;span class="s"&gt;with&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;all"&lt;/span&gt;
          &lt;span class="na"&gt;target_branch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
          &lt;span class="na"&gt;target_repository&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my_user_name/my_repo&lt;/span&gt;
          &lt;span class="na"&gt;update&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
      &lt;span class="s"&gt;...&lt;/span&gt;
      &lt;span class="s"&gt;# Use your favorite action for push and commit changes after&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A complete end-to-end example, with required checkout and push steps, looks like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Add Colab Badges&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Trigger workflow only for notebooks or md file changes&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;**.ipynb"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;**.md"&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# The same for PR&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;**.ipynb"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;**.md"&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;badges&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Colab Badge&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# First do checkout&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v2&lt;/span&gt;

      &lt;span class="c1"&gt;# Then launch the colab-badge-action (v4)&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Add/Update badges&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;trsvchn/colab-badge-action@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;target_branch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
          &lt;span class="na"&gt;target_repository&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;usr/repo&lt;/span&gt;
          &lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;all"&lt;/span&gt;  &lt;span class="c1"&gt;# Check all notebook/md files&lt;/span&gt;
          &lt;span class="na"&gt;update&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;  &lt;span class="c1"&gt;# Update self-badges for renamed/moved notebooks&lt;/span&gt;
          &lt;span class="na"&gt;verbose&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;  &lt;span class="c1"&gt;# Print some info during the run&lt;/span&gt;

      &lt;span class="c1"&gt;# After that we have to commit and push changes&lt;/span&gt;
      &lt;span class="c1"&gt;# Note: this step requires GitHub token&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Commit and Push&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;stefanzweifel/git-auto-commit-action@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;commit_message&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Add&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Colab&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Badges"&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;GITHUB_TOKEN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GITHUB_TOKEN }}&lt;/span&gt;

      &lt;span class="c1"&gt;# And that's it!&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/trsvchn"&gt;
        trsvchn
      &lt;/a&gt; / &lt;a href="https://github.com/trsvchn/colab-badge-action"&gt;
        colab-badge-action
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      GitHub Action that generates "Open In Colab" Badges for you
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Colab Badge GitHub Action&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://github.com/trsvchn/colab-badge-action/actions/workflows/unit-tests.yml"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4k7DDCs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/trsvchn/colab-badge-action/actions/workflows/unit-tests.yml/badge.svg" alt="Unit Tests"&gt;&lt;/a&gt;
&lt;a href="https://codecov.io/gh/trsvchn/colab-badge-action" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/7558517190ea432f0c433e04dd5cc61d18d5d95690cc60e345dcab44fea50dfd/68747470733a2f2f636f6465636f762e696f2f67682f7472737663686e2f636f6c61622d62616467652d616374696f6e2f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d3257364352465a374342" alt="codecov"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Adds "Open in Colab" badges to Jupyter Notebooks and Markdown files. Updates badges for renamed or moved notebooks.&lt;/p&gt;
&lt;h2&gt;
Usage&lt;/h2&gt;
&lt;h3&gt;
Badge Tag&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;{{ badge }}&lt;/code&gt; tag  to generate a badge for the notebook containing this tag (self-linking). Works only for Jupyter notebooks.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following options work for bath Jupyter and Markdown files (new in &lt;code&gt;v4&lt;/code&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;{{ badge nb_path }}&lt;/code&gt; tag to generate a badge for a local notebook &lt;code&gt;nb_path&lt;/code&gt;, and insert it to the file containing that tag (tag will be replaced with generated badge code). e.g. &lt;code&gt;{{ badge dir1/di2/nb.ipynb }}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;{{ badge /nb_path }}&lt;/code&gt; tag to generate a badge for a remote (located in another repo) notebook &lt;code&gt;/nb_path&lt;/code&gt;, and insert it to the file containing that tag. e.g. &lt;code&gt;{{ badge /usr2/repo/blob/main/nb.ipynb }}&lt;/code&gt;. You can use full link (url) as well: &lt;code&gt;{{ badge https://github.com/usr2/repo/blob/main/nb.ipynb }}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;{{ badge&lt;/code&gt;…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/trsvchn/colab-badge-action"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;h4&gt;
  
  
  Open source projects that are using Colab Badge Action
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/huggingface/workshops"&gt;huggingface/workshops&lt;/a&gt; Materials for workshops on the Hugging Face ecosystem.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/UT-Covid/episimlab"&gt;UT-Covid/episimlab&lt;/a&gt; Framework for development of epidemiological models.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/ulissigroup/math-methods-chemical-engineering"&gt;ulissigroup/math-methods-chemical-engineering
&lt;/a&gt; Course notes for the CMU course 06-262 Math Methods of Chemical Engineering (ODE's, linear algebra, PDEs, stats) in the form of jupyter notebooks.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>actionshackathon21</category>
      <category>jupyter</category>
      <category>datascience</category>
      <category>python</category>
    </item>
  </channel>
</rss>
