<?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: Eric Wooley</title>
    <description>The latest articles on DEV Community by Eric Wooley (@ericwooley).</description>
    <link>https://dev.to/ericwooley</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%2F7845%2F1930227.jpeg</url>
      <title>DEV Community: Eric Wooley</title>
      <link>https://dev.to/ericwooley</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ericwooley"/>
    <language>en</language>
    <item>
      <title>Keeping Node Dependencies Up to Date, Automagically!</title>
      <dc:creator>Eric Wooley</dc:creator>
      <pubDate>Tue, 10 Dec 2019 18:13:38 +0000</pubDate>
      <link>https://dev.to/ericwooley/keeping-node-dependencies-up-to-date-automagically-1kfj</link>
      <guid>https://dev.to/ericwooley/keeping-node-dependencies-up-to-date-automagically-1kfj</guid>
      <description>&lt;h2&gt;
  
  
  Obligatory intro paragraph
&lt;/h2&gt;

&lt;p&gt;Maintaining projects is hard. There is a ton to do, and often upgrading dependencies is neglected, or put on the back burner. It's hard to justify spending a few hours upgrading a bunch of libraries that already work. If you have ever had to go back and upgrade a few dozen (hundred??) dependencies that have been neglected for a few year(s), you know how much easier to keep up to date consistently.&lt;/p&gt;

&lt;p&gt;A giant dependency upgrade is hard, a sure fire way to ship some bugs, and, in the meantime, you will probably be insecure. &lt;a href="https://dependabot.com/blog/why-bother/"&gt;There&lt;/a&gt; &lt;a href="https://depfu.com/blog/2016/12/01/why-you-should-keep-your-dependencies-up-to-date"&gt;are&lt;/a&gt; &lt;a href="https://nullbeans.com/9-reasons-for-keeping-software-dependencies-up-to-date/"&gt;a&lt;/a&gt; &lt;a href="https://snyk.io/blog/keep-your-dependencies-up-to-date-enable-auto-upgrades-with-snyk/"&gt;lot&lt;/a&gt; &lt;a href="https://dependabot.com/blog/why-bother/"&gt;of&lt;/a&gt; &lt;a href="https://hackernoon.com/psa-upgrading-out-of-date-dependencies-is-one-of-the-most-important-things-you-can-do-a9e65e28a786"&gt;reasons&lt;/a&gt; &lt;a href="http://blog.js-republic.com/keep-npm-dependencies-up-to-date/"&gt;to&lt;/a&gt; &lt;a href="https://buttercms.com/blog/strategies-for-keeping-your-packages-and-dependencies-updated"&gt;upgrade.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Forever ago, I discovered greenkeeper.io, which automatically creates pull requests for dependencies which when they get out of date. Unfortunately, it doesn't seem to play nice with Github actions. Maybe it does, IDK, I gave up on it. It occured to me, that this could be a simple github action... Does a premade one already exist? &lt;a href="https://github.com/taichi/actions-package-update"&gt;Yep&lt;/a&gt;... BRILLIANT.&lt;/p&gt;

&lt;p&gt;Anytime you run this github action, a pull request is made to upgrade dependencies in your package.json files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get to the action!
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;...sorry, sometimes puns &lt;strong&gt;must&lt;/strong&gt; be made&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Lets install our github action:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a &lt;a href="https://github.com/settings/tokens"&gt;personal access token&lt;/a&gt;, with repository access, and add it to your &lt;code&gt;secrets&lt;/code&gt; in the settings section of your github repository.

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;DO NOT LOSE THIS OR LET ANYONE SEE IT&lt;/em&gt;. Your access token is a second github password to your account.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/taichi/actions-package-update"&gt;The example recommends naming your secret &lt;code&gt;GITHUB_TOKEN&lt;/code&gt;&lt;/a&gt;. I named mine githubAccessToken, since the recommended name does not seem to be valid.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Create a file in your repo, &lt;code&gt;.github/workflows/update_node_deps.yml&lt;/code&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Configuring your setup.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;I used the yarn version, because I use &lt;a href="https://yarnpkg.com/lang/en/docs/workspaces/"&gt;yarn workspaces&lt;/a&gt;, and yarn upgrade will update all the packages as well.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&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;package-update&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;taichi/actions-package-update@master&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;AUTHOR_EMAIL&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;john@example.com&lt;/span&gt;
    &lt;span class="na"&gt;AUTHOR_NAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;John&lt;/span&gt;
    &lt;span class="na"&gt;EXECUTE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true"&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="na"&gt;UPDATE_COMMAND&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yarn&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;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;upgrade --latest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Configuration for &lt;a href="https://github.com/ericwooley/action-packed-react"&gt;Action Packed React&lt;/a&gt;:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&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="s1"&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;9&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="c1"&gt;# https://jasonet.co/posts/scheduled-actions/&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;Update&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;package-update&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@master&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 remote url&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;git remote set-url --push origin https://$GITHUB_ACTOR:${{ secrets.githubAccessToken }}@github.com/$GITHUB_REPOSITORY&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;package-update&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;taichi/actions-package-update@master&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;AUTHOR_EMAIL&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ericwooley@gmail.com&lt;/span&gt;
        &lt;span class="na"&gt;AUTHOR_NAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Eric Wooley&lt;/span&gt;
        &lt;span class="na"&gt;EXECUTE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true"&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.githubAccessToken }}&lt;/span&gt;
        &lt;span class="na"&gt;LOG_LEVEL&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;debug&lt;/span&gt;
        &lt;span class="na"&gt;UPDATE_COMMAND&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yarn&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;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;upgrade --latest --ignore-engines&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's mostly stolen from the readme, but it's &lt;em&gt;&lt;strong&gt;mine&lt;/strong&gt;&lt;/em&gt;, and I love it. Here is what I changed and why.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change &lt;code&gt;secrets.GITHUB_TOKEN&lt;/code&gt; -&amp;gt; &lt;code&gt;secrets.githubAccessToken&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It's set to run on a schedule, of every morning at 9am. See &lt;a href="https://jasonet.co/posts/scheduled-actions/"&gt;this guide to cron with github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&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="s1"&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;9&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="c1"&gt;# https://jasonet.co/posts/scheduled-actions/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;(optional) Use &lt;code&gt;yarn upgrade&lt;/code&gt; instead of &lt;a href="https://www.npmjs.com/package/npm-check-updates"&gt;ncu&lt;/a&gt;, so that workspaces will be updated as well.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;        &lt;span class="c1"&gt;# ...&lt;/span&gt;
        &lt;span class="na"&gt;UPDATE_COMMAND&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yarn&lt;/span&gt; &lt;span class="c1"&gt;# This says to use yarn as your upgrade tool.&lt;/span&gt;
&lt;span class="err"&gt;      &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;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;upgrade --latest --ignore-engines&lt;/span&gt; &lt;span class="c1"&gt;# extra args for yarn&lt;/span&gt;
              &lt;span class="c1"&gt;# --latest means use the latest versions of the pages.&lt;/span&gt;
              &lt;span class="c1"&gt;# ignore engines, means ignore which version of yarn is performing this upgrade.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's it! Every day at 9:00am, you should get a pull request, which updates all your node dependencies. Make sure your running CI!&lt;/p&gt;

</description>
      <category>node</category>
      <category>actions</category>
      <category>yarn</category>
      <category>npm</category>
    </item>
  </channel>
</rss>
