<?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: swfz</title>
    <description>The latest articles on DEV Community by swfz (@swfz).</description>
    <link>https://dev.to/swfz</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%2F42108%2Facb553d4-49d4-4111-b0c4-b908d4243b1e.png</url>
      <title>DEV Community: swfz</title>
      <link>https://dev.to/swfz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/swfz"/>
    <language>en</language>
    <item>
      <title>I made a CLI extension to get the Annotation list of GitHub Actions.</title>
      <dc:creator>swfz</dc:creator>
      <pubDate>Tue, 27 Dec 2022 09:56:43 +0000</pubDate>
      <link>https://dev.to/swfz/i-made-a-cli-extension-to-get-the-annotation-list-of-github-actions-5abm</link>
      <guid>https://dev.to/swfz/i-made-a-cli-extension-to-get-the-annotation-list-of-github-actions-5abm</guid>
      <description>&lt;h2&gt;
  
  
  Background, Purpose
&lt;/h2&gt;

&lt;p&gt;Some time ago, GitHub Actions started sending warnings to Annotation that actions using Node version 12 would be deprecated.&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%2Fuploads%2Farticles%2Fklq5c6baqjqfsmb13t8u.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%2Fuploads%2Farticles%2Fklq5c6baqjqfsmb13t8u.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the repository is well maintained, it's good to notice and respond, but I felt that there might be some omissions...&lt;/p&gt;

&lt;p&gt;To find them, you can look at the summary on the web page of each Actions, but it takes time to go to the page every time when the number of repositories to manage increases.&lt;/p&gt;

&lt;p&gt;That's why&lt;/p&gt;

&lt;p&gt;I made a GitHub CLI extension to get the list of annotations of GitHub Actions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/swfz/gh-annotations" rel="noopener noreferrer"&gt;swfz/gh-annotations: list of annotations from the recently executed Workflow&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;I'm trying to look at annotations from the latest execution of each Workflow in the repository, since I have to hit the API quite a bit.&lt;/p&gt;

&lt;p&gt;So you can't get annotations from a specific Workflow that was executed a while ago.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

gh annotations &lt;span class="nt"&gt;-repo&lt;/span&gt; swfz/til | jq
&lt;span class="o"&gt;[&lt;/span&gt;
  &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"repository"&lt;/span&gt;: &lt;span class="s2"&gt;"swfz/til"&lt;/span&gt;,
    &lt;span class="s2"&gt;"workflow_name"&lt;/span&gt;: &lt;span class="s2"&gt;"slack notification"&lt;/span&gt;,
    &lt;span class="s2"&gt;"workflow_event"&lt;/span&gt;: &lt;span class="s2"&gt;"workflow_run"&lt;/span&gt;,
    &lt;span class="s2"&gt;"workflow_path"&lt;/span&gt;: &lt;span class="s2"&gt;".github/workflows/slack.yml"&lt;/span&gt;,
    &lt;span class="s2"&gt;"workflow_url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://github.com/swfz/til/actions/runs/3697438928"&lt;/span&gt;,
    &lt;span class="s2"&gt;"job_name"&lt;/span&gt;: &lt;span class="s2"&gt;"main"&lt;/span&gt;,
    &lt;span class="s2"&gt;"job_conclusion"&lt;/span&gt;: &lt;span class="s2"&gt;"success"&lt;/span&gt;,
    &lt;span class="s2"&gt;"annotation_level"&lt;/span&gt;: &lt;span class="s2"&gt;"warning"&lt;/span&gt;,
    For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: swfz/slack-workflow-status@feature/follow-workflow-run&lt;span class="s2"&gt;"
  }
  {
    "&lt;/span&gt;repository&lt;span class="s2"&gt;": "&lt;/span&gt;swfz/til&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_name&lt;span class="s2"&gt;": "&lt;/span&gt;ci&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_event&lt;span class="s2"&gt;": "&lt;/span&gt;push&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_path&lt;span class="s2"&gt;": "&lt;/span&gt;.github/workflows/ci.yml&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_url&lt;span class="s2"&gt;": "&lt;/span&gt;https://github.com/swfz/til/actions/runs/3697430624&lt;span class="s2"&gt;",
    "&lt;/span&gt;job_name&lt;span class="s2"&gt;": "&lt;/span&gt;build&lt;span class="s2"&gt;",
    "&lt;/span&gt;job_conclusion&lt;span class="s2"&gt;": "&lt;/span&gt;failure&lt;span class="s2"&gt;",
    "&lt;/span&gt;annotation_level&lt;span class="s2"&gt;": "&lt;/span&gt;failure&lt;span class="s2"&gt;",
    "&lt;/span&gt;message&lt;span class="s2"&gt;": "&lt;/span&gt;Process completed with &lt;span class="nb"&gt;exit &lt;/span&gt;code 1.&lt;span class="s2"&gt;"
  }
  {
    "&lt;/span&gt;repository&lt;span class="s2"&gt;": "&lt;/span&gt;swfz/til&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_name&lt;span class="s2"&gt;": "&lt;/span&gt;lint content&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_event&lt;span class="s2"&gt;": "&lt;/span&gt;push&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_path&lt;span class="s2"&gt;": "&lt;/span&gt;.github/workflows/lint.yml&lt;span class="s2"&gt;",
    "&lt;/span&gt;workflow_url&lt;span class="s2"&gt;": "&lt;/span&gt;https://github.com/swfz/til/actions/runs/3694817234&lt;span class="s2"&gt;",
    "&lt;/span&gt;job_name&lt;span class="s2"&gt;": "&lt;/span&gt;run textlint&lt;span class="s2"&gt;",
    "&lt;/span&gt;job_conclusion&lt;span class="s2"&gt;": "&lt;/span&gt;failure&lt;span class="s2"&gt;",
    "&lt;/span&gt;annotation_level&lt;span class="s2"&gt;": "&lt;/span&gt;failure&lt;span class="s2"&gt;",
    "&lt;/span&gt;message&lt;span class="s2"&gt;": "&lt;/span&gt;Process completed with &lt;span class="nb"&gt;exit &lt;/span&gt;code 1.&lt;span class="s2"&gt;"
  }
]


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  install
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

gh extension install swfz/gh-annotations


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

&lt;/div&gt;

&lt;p&gt;This is just because it's a GitHub CLI Extension, but you can use it with just the above command.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to operate
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

gh annotations | jq


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

&lt;/div&gt;

&lt;p&gt;Execute against the repository in your current directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

gh annotations -repo swfz/sample | jq


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

&lt;/div&gt;

&lt;p&gt;You can also specify a repository like &lt;code&gt;gh annotations -repo&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you don't specify anything, it will target the directory you are in.&lt;/p&gt;

&lt;p&gt;If you want to get information on all repositories maintained at the beginning, use&lt;/p&gt;

&lt;p&gt;You can get a list of repositories and run &lt;code&gt;gh annotations&lt;/code&gt; on each of them to output annotations for all repositories by using a one-liner.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;p&gt;gh repo list &lt;span class="nt"&gt;--limit&lt;/span&gt; 200 &lt;span class="nt"&gt;--json&lt;/span&gt; &lt;span class="s1"&gt;'nameWithOwner'&lt;/span&gt; | jq &lt;span class="nt"&gt;-rc&lt;/span&gt; &lt;span class="s1"&gt;'. []|.nameWithOwner'&lt;/span&gt; | xargs &lt;span class="nt"&gt;-i&lt;/span&gt; sh &lt;span class="nt"&gt;-lc&lt;/span&gt; &lt;span class="s2"&gt;"gh annotations -repo {}"&lt;/span&gt; | &lt;span class="nb"&gt;tee&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; annotations.json&lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  End&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;This was a story about creating a GitHub CLI extension to get the results of GitHub Actions annotations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Catch and notify when any annotations occur by integrating it into CI.&lt;/li&gt;
&lt;li&gt;Periodically output and check the results of all repositories you are managing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I think it can be used for such purposes.&lt;/p&gt;

&lt;p&gt;In development, I was going to implement list output in addition to JSON output, but I ran out of energy, so I decided to write the article in this state.&lt;/p&gt;

&lt;p&gt;You can use it if you like!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/swfz/gh-annotations" rel="noopener noreferrer"&gt;swfz/gh-annotations: list of annotations from a recently executed Workflow&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>githubactions</category>
      <category>githubcli</category>
      <category>githubcliextension</category>
    </item>
    <item>
      <title>Handling command line arguments in zx</title>
      <dc:creator>swfz</dc:creator>
      <pubDate>Mon, 31 Oct 2022 09:24:39 +0000</pubDate>
      <link>https://dev.to/swfz/handling-command-line-arguments-in-zx-1aee</link>
      <guid>https://dev.to/swfz/handling-command-line-arguments-in-zx-1aee</guid>
      <description>&lt;p&gt;Not only zx, but when you refer to a command line argument list in node&lt;/p&gt;

&lt;p&gt;If you are not using a library to parse command line arguments, the list is taken from process.argv.&lt;/p&gt;

&lt;p&gt;I thought I could simply use this for zx as well, but the order in which zx options are passed to process.argv changes, so if I try to use it as-is, the behavior changes, as a matter of course.&lt;/p&gt;

&lt;h2&gt;
  
  
  minimist
&lt;/h2&gt;

&lt;p&gt;In zx, minimist is included by default, and you can refer to the list of arguments parsed by minimist from the beginning (argv).&lt;/p&gt;

&lt;p&gt;If you don't use other libraries, it seems to be a good idea to refer to argv from the beginning.&lt;/p&gt;

&lt;p&gt;However, this alone is a little subtle and changes the contents of the command line argument list in the following two patterns&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No options, when you pass a set of key/value options

&lt;ul&gt;
&lt;li&gt;eg) --shell=/bin/bash&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;when passing options that can be represented by (true/false)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;eg) --quiet&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;sample.mjs&lt;br&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env zx

console.log(argv);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ zx sample.mjs a b c
{ _: [ 'sample.mjs', 'a', 'b', 'c' ] }

$ zx --shell=/bin/bash sample.mjs a b c
{ _: [ 'sample.mjs', 'a', 'b', 'c' ], shell: '/bin/bash' }

$ zx --quiet sample.mjs a b c
{ _: [ 'a', 'b', 'c' ], quiet: 'sample.mjs' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;even if your file name is in the list of command line arguments, exclude it to prevent the command line argument list from being changed by options at runtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  path
&lt;/h2&gt;

&lt;p&gt;zx also includes path by default, so it is not affected by the runtime options if you exclude your filename from the command line argument list.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sample.mjs
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env zx

console.log(path.basename(__filename));
console.log(argv);
console.log(argv._.filter(a =&amp;gt; a !== path.basename(__filename)));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ zx sample.mjs a b
sample.mjs
{ _: [ 'sample.mjs', 'a', 'b' ] }
[ 'a', 'b' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ zx --quite sample.mjs a b
sample.mjs
{ _: [ 'a', 'b' ], quite: 'sample.mjs' }
[ 'a', 'b' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should no longer affect behavior due to options, etc.&lt;/p&gt;

</description>
      <category>zx</category>
      <category>node</category>
    </item>
  </channel>
</rss>
