<?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>Forem: Natig Babayev</title>
    <description>The latest articles on Forem by Natig Babayev (@natiginfo).</description>
    <link>https://forem.com/natiginfo</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%2F62212%2F19488ac5-42ba-49e9-a0e6-1d389e75b0f3.png</url>
      <title>Forem: Natig Babayev</title>
      <link>https://forem.com/natiginfo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/natiginfo"/>
    <language>en</language>
    <item>
      <title>Automating releases of Github Action that depends on another repository</title>
      <dc:creator>Natig Babayev</dc:creator>
      <pubDate>Wed, 16 Sep 2020 07:33:55 +0000</pubDate>
      <link>https://forem.com/natiginfo/automating-releases-of-github-action-that-depends-on-another-repository-2mgh</link>
      <guid>https://forem.com/natiginfo/automating-releases-of-github-action-that-depends-on-another-repository-2mgh</guid>
      <description>&lt;p&gt;Performing repetitive tasks is time-consuming and can be tedious. Luckily, we have tools that we can leverage to do repetitive tasks for us and save time. Recently, I decided to automate the release process in &lt;a href="https://github.com/natiginfo/action-detekt-all" rel="noopener noreferrer"&gt;one of my repositories&lt;/a&gt;. In this submission, I will share my journey of automating the release process using &lt;a href="https://github.com/features/actions" rel="noopener noreferrer"&gt;GitHub Actions&lt;/a&gt; and &lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;Python&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The problem
&lt;/h3&gt;

&lt;p&gt;I maintain a &lt;a href="https://github.com/natiginfo/action-detekt-all" rel="noopener noreferrer"&gt;repository&lt;/a&gt; that depends on new releases of &lt;code&gt;Detekt CLI&lt;/code&gt;. When there is a new version of &lt;code&gt;Detekt CLI&lt;/code&gt;, I receive email and make a new release of my repository whenever I have free time. With this approach, I used to make new releases by following the steps below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receive an e-mail about the new release of Detekt.&lt;/li&gt;
&lt;li&gt;Update version in &lt;code&gt;Dockerfile&lt;/code&gt; and &lt;code&gt;README.md&lt;/code&gt; whenever I have free time.&lt;/li&gt;
&lt;li&gt;Commit changes.&lt;/li&gt;
&lt;li&gt;Create a new tag.&lt;/li&gt;
&lt;li&gt;Push changes.&lt;/li&gt;
&lt;li&gt;Publish the release.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Although the timing of new releases is critical, it is clear that the time difference from &lt;strong&gt;step 1&lt;/strong&gt; to &lt;strong&gt;step 2&lt;/strong&gt; can vary depending on my situation that might not make users happy. Besides the timing of new releases and keeping the users of my repository happy, personal time is also important which can be spent on more exciting things than just doing some work manually that can be automated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;As we know the problem and we have the steps written down, we can think of a way to approach this problem. The solution I wanted to make needed the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check new releases of &lt;code&gt;Detekt CLI&lt;/code&gt; every 24 hours.&lt;/li&gt;
&lt;li&gt;If the latest release of &lt;code&gt;Detekt CLI&lt;/code&gt; is different than the latest tag of my repository,

&lt;ul&gt;
&lt;li&gt;Update the &lt;code&gt;Detekt CLI&lt;/code&gt; version in &lt;code&gt;Dockerfile&lt;/code&gt; and &lt;code&gt;README.md&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Commit changes&lt;/li&gt;
&lt;li&gt;Create a new tag&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Create a release branch&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Push changes&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;When the new release branch is created, create a new pull request.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Creating a new release branch and a new pull request is something that I did not do when I used to make releases manually. I added the aforementioned steps to ensure that I can review changes so that broken code is not merged to the master branch. For checking new releases and running &lt;a href="https://github.com/natiginfo/action-detekt-all/tree/master/.release-manager" rel="noopener noreferrer"&gt;my Python script&lt;/a&gt;, I created two workflows where &lt;a href="https://github.com/natiginfo/action-detekt-all/blob/master/.github/workflows/create_new_release.yml" rel="noopener noreferrer"&gt;the first workflow&lt;/a&gt; runs the script every 24 hours, and &lt;a href="https://github.com/natiginfo/action-detekt-all/blob/master/.github/workflows/create_release_pr.yml" rel="noopener noreferrer"&gt;the second workflow&lt;/a&gt; creates a pull request when a new release branch is created. Besides the workflow which runs the release script every 24 hours, I noticed that &lt;code&gt;workflow_dispatch&lt;/code&gt; trigger in GitHub actions can be used for running a workflow manually. &lt;/p&gt;

&lt;p&gt;According to the release history of &lt;code&gt;Detekt&lt;/code&gt;, there are approximately two to three new releases each month. With the simple solution I created by using GitHub Actions and Python, my goal is to save at least 20 to 30 minutes each month. Besides, I can use the solution in other projects that can save a more significant amount of time in total.&lt;/p&gt;

&lt;h3&gt;
  
  
  My Workflow
&lt;/h3&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;Create Release&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;schedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;cron&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;0&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*"&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&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;check_release&lt;/span&gt;&lt;span class="pi"&gt;:&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="pi"&gt;-&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="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;Set up Python&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/setup-python@v2&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;python-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3.8&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;Install dependencies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;git config --local user.email "action@github.com"&lt;/span&gt;
          &lt;span class="s"&gt;git config --local user.name "GitHub Action"&lt;/span&gt;
          &lt;span class="s"&gt;python -m pip install --upgrade pip&lt;/span&gt;
          &lt;span class="s"&gt;if [ -f .release-manager/requirements.txt ]; then pip install -r .release-manager/requirements.txt; fi&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;Run script&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;python .release-manager/create_release.py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/natiginfo" rel="noopener noreferrer"&gt;
        natiginfo
      &lt;/a&gt; / &lt;a href="https://github.com/natiginfo/action-detekt-all" rel="noopener noreferrer"&gt;
        action-detekt-all
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Run detekt for all files
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;GitHub Action: Detekt All&lt;/h1&gt;

&lt;/div&gt;

&lt;p&gt;GitHub Action for running &lt;a href="https://github.com/detekt/detekt" rel="noopener noreferrer"&gt;detekt&lt;/a&gt; checks to enforce best practices. Detekt is a static code analysis tool for Kotlin.&lt;/p&gt;

&lt;p&gt;Version of the action is aligned with &lt;a href="https://github.com/detekt/detekt/releases" rel="noopener noreferrer"&gt;detekt versions&lt;/a&gt;.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Example usage&lt;/h2&gt;

&lt;/div&gt;

&lt;div class="highlight highlight-source-yaml notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;detekt&lt;/span&gt;

&lt;span class="pl-ent"&gt;on&lt;/span&gt;:
  &lt;span class="pl-ent"&gt;push&lt;/span&gt;:
    &lt;span class="pl-ent"&gt;branches&lt;/span&gt;: &lt;span class="pl-s"&gt;[ master ]&lt;/span&gt;

 &lt;span class="pl-ent"&gt;jobs&lt;/span&gt;:
   &lt;span class="pl-ent"&gt;detekt&lt;/span&gt;:
     &lt;span class="pl-ent"&gt;runs-on&lt;/span&gt;: &lt;span class="pl-s"&gt;ubuntu-latest&lt;/span&gt;

     &lt;span class="pl-ent"&gt;steps&lt;/span&gt;:
       - &lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;&lt;span class="pl-pds"&gt;"&lt;/span&gt;checkout&lt;span class="pl-pds"&gt;"&lt;/span&gt;&lt;/span&gt;
         &lt;span class="pl-ent"&gt;uses&lt;/span&gt;: &lt;span class="pl-s"&gt;actions/checkout@v2&lt;/span&gt;

       - &lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;&lt;span class="pl-pds"&gt;"&lt;/span&gt;detekt&lt;span class="pl-pds"&gt;"&lt;/span&gt;&lt;/span&gt;
         &lt;span class="pl-ent"&gt;uses&lt;/span&gt;: &lt;span class="pl-s"&gt;natiginfo/action-detekt-all@2.0.0-alpha.1&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Usage with &lt;a href="https://detekt.github.io/detekt/cli.html#use-the-cli" rel="nofollow noopener noreferrer"&gt;CLI parameters&lt;/a&gt;
&lt;/h2&gt;

&lt;/div&gt;

&lt;div class="highlight highlight-source-yaml notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;detekt&lt;/span&gt;

&lt;span class="pl-ent"&gt;on&lt;/span&gt;:
  &lt;span class="pl-ent"&gt;push&lt;/span&gt;:
    &lt;span class="pl-ent"&gt;branches&lt;/span&gt;: &lt;span class="pl-s"&gt;[ master ]&lt;/span&gt;

 &lt;span class="pl-ent"&gt;jobs&lt;/span&gt;:
   &lt;span class="pl-ent"&gt;detekt&lt;/span&gt;:
     &lt;span class="pl-ent"&gt;runs-on&lt;/span&gt;: &lt;span class="pl-s"&gt;ubuntu-latest&lt;/span&gt;

     &lt;span class="pl-ent"&gt;steps&lt;/span&gt;:
       - &lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;&lt;span class="pl-pds"&gt;"&lt;/span&gt;checkout&lt;span class="pl-pds"&gt;"&lt;/span&gt;&lt;/span&gt;
         &lt;span class="pl-ent"&gt;uses&lt;/span&gt;: &lt;span class="pl-s"&gt;actions/checkout@v2&lt;/span&gt;

       - &lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;&lt;span class="pl-pds"&gt;"&lt;/span&gt;detekt&lt;span class="pl-pds"&gt;"&lt;/span&gt;&lt;/span&gt;
         &lt;span class="pl-ent"&gt;uses&lt;/span&gt;: &lt;span class="pl-s"&gt;natiginfo/action-detekt-all@2.0.0-alpha.1&lt;/span&gt;
         &lt;span class="pl-ent"&gt;with&lt;/span&gt;:
          &lt;span class="pl-ent"&gt;args&lt;/span&gt;:  &lt;span class="pl-s"&gt;--config detekt.yml&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You can check available CLI parameters &lt;a href="https://detekt.github.io/detekt/cli.html#use-the-cli" rel="nofollow noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;

  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/natiginfo/action-detekt-all" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  Ending
&lt;/h3&gt;

&lt;p&gt;The purpose of this submission is to encourage you to leverage existing tools and save time by automating tasks. As you can see, once you write down the steps, automation is easy with the tools you use. I believe by checking existing &lt;a href="https://github.com/marketplace?type=actions" rel="noopener noreferrer"&gt;actions&lt;/a&gt;, you can create workflow that works for your need.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>actionshackathon</category>
      <category>github</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
