<?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: Kris Kaczor</title>
    <description>The latest articles on DEV Community by Kris Kaczor (@krzkaczor).</description>
    <link>https://dev.to/krzkaczor</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%2F112869%2Fa463817d-ad99-46df-bfb7-98b10608e9de.jpeg</url>
      <title>DEV Community: Kris Kaczor</title>
      <link>https://dev.to/krzkaczor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/krzkaczor"/>
    <language>en</language>
    <item>
      <title>Fixing GitHub Actions development using GitHub Actions</title>
      <dc:creator>Kris Kaczor</dc:creator>
      <pubDate>Wed, 06 Jan 2021 15:40:06 +0000</pubDate>
      <link>https://dev.to/krzkaczor/fixing-github-actions-development-using-github-actions-33mk</link>
      <guid>https://dev.to/krzkaczor/fixing-github-actions-development-using-github-actions-33mk</guid>
      <description>&lt;p&gt;If you ever browsed the source code of any GitHub Action that you had encountered in the wild, for sure you realized that most authors &lt;strong&gt;push bundled JavaScript code directly to a git repository&lt;/strong&gt;. Usually - it's a single file like &lt;code&gt;action.js&lt;/code&gt;, but in the worst case it's a set of files with the whole &lt;code&gt;node_modules&lt;/code&gt; committed directly to the git 😱&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is it a bad idea?
&lt;/h2&gt;

&lt;p&gt;There are various reasons why you might want to avoid that. First of all, it makes code reviews harder. Reviewers now have to take a look at the committed bundle or add additional tooling to verify if the user doesn't try pushing anything fishy instead of a proper bundle. It's a 10k line blob - who's gonna check it anyway?&lt;/p&gt;

&lt;p&gt;Bundled files can easily produce merge conflicts which add even more unnecessary work for maintainers. It's confusing for newcomers too, "should I commit this blob or what?". Not to mention, it's just plain ugly to keep these files in the git repo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9z37r0mpfsutak9c3n79.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9z37r0mpfsutak9c3n79.png" alt="node_modules meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Automation for the rescue
&lt;/h2&gt;

&lt;p&gt;Usually, committing anything that can be &lt;strong&gt;derived&lt;/strong&gt; from the source to the git repositories is a bad practice. Sadly, we can't get rid of pushing JavaScript bundles entirely because GitHub Actions Runner requires it but at least we can hide that fact.&lt;/p&gt;

&lt;p&gt;GitHub Actions are all about making developing code easier so &lt;strong&gt;let's use GitHub Actions to develop GitHub Actions&lt;/strong&gt;! &lt;/p&gt;

&lt;p&gt;The plan is to develop GitHub Actions as any other JavaScript code - with bundles/&lt;code&gt;node_modules&lt;/code&gt; git-ignored. Let's have another branch for build artifacts. This release branch will be automatically updated by GitHub Actions on every push to the main branch.&lt;/p&gt;

&lt;p&gt;To make this task easier I've created a helper action called: &lt;a href="https://github.com/ActionwareIO/branch-push-action" rel="noopener noreferrer"&gt;branch-push-action&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Here's the complete workflow:&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;Deploy&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;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;master&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;deploy&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@v1&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/setup-node@v1&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;node-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;12.x&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yarn --no-progress --non-interactive --frozen-lockfile&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yarn build&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;ActionwareIO/branch-push-action@action&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;branch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;action&lt;/span&gt;
          &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
            &lt;span class="s"&gt;README.md&lt;/span&gt;
            &lt;span class="s"&gt;action.yml&lt;/span&gt;
            &lt;span class="s"&gt;./dist/index.js&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;build&lt;/code&gt; task uses &lt;code&gt;ncc&lt;/code&gt; to produce a single file bundle. &lt;code&gt;branch-push-action&lt;/code&gt; will save specified files, checkout target branch (&lt;code&gt;action&lt;/code&gt; in this example), and commit updates. A branch will be automatically created if it doesn't exist and it will contain only necessary files. &lt;/p&gt;

&lt;p&gt;The last thing is that you need to point users of your GitHub Action to the branch with bundled code like:&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="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;your-awesome-action@action&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, you can tweak this workflow to your needs - use &lt;code&gt;dev&lt;/code&gt; and &lt;code&gt;master&lt;/code&gt; branches or even commit files to the same branch. I prefer to keep build artifacts on a separate branch as this allows me to completely git ignore any unnecessary files on the default branch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Now you can develop GitHub Actions without worrying about build artifacts. I prefer to use TypeScript while creating Actions and pushing compiled JavaScript code was messing up language statistics on GitHub. Now I can brag about that beautiful 100% TypeScript badge ;) &lt;/p&gt;

&lt;p&gt;In case you're wondering - yes, &lt;code&gt;branch-push-action&lt;/code&gt; is also deployed using itself ;) For the complete solution for automatic deployment browse its &lt;a href="https://github.com/ActionwareIO/branch-push-action/blob/master/.github/workflows/release.yml" rel="noopener noreferrer"&gt;source code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, you know how to continuously deploy GitHub Actions, but you wouldn't want to push a broken release, would you? In my next article, I will dive into testing GitHub Actions properly - given their nature, which is full of side effects, it's not that easy. If you don't want to miss it follow me on 🤜 &lt;a href="https://twitter.com/krzKaczor" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; 🤛!&lt;/p&gt;

</description>
      <category>github</category>
      <category>actions</category>
      <category>git</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
