<?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: emibcn</title>
    <description>The latest articles on DEV Community by emibcn (@emibcn).</description>
    <link>https://dev.to/emibcn</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%2F261262%2Fc56c9ba3-3d74-4eb0-afe0-1a52910898fd.jpeg</url>
      <title>DEV Community: emibcn</title>
      <link>https://dev.to/emibcn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emibcn"/>
    <language>en</language>
    <item>
      <title>Badge Action</title>
      <dc:creator>emibcn</dc:creator>
      <pubDate>Wed, 09 Sep 2020 12:24:36 +0000</pubDate>
      <link>https://dev.to/emibcn/badge-action-3ml3</link>
      <guid>https://dev.to/emibcn/badge-action-3ml3</guid>
      <description>&lt;h3&gt;
  
  
  My Workflow
&lt;/h3&gt;

&lt;p&gt;I have published a serverless SPA &amp;amp; PWA made with React, which is deployed directly to GitHub Pages using it's own GitHub Workflow. I wanted to generate a test coverage badge automatically during CI/CD, and store it into the same repository (no 3rd parties servers involved).&lt;/p&gt;

&lt;p&gt;First, I saw &lt;a href="https://github.com/demyanets/angular-coverage-badges-action"&gt;Angular Coverage Badges&lt;/a&gt;, which was mostly what I wanted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take a test coverage result file&lt;/li&gt;
&lt;li&gt;Extract relevant info from it&lt;/li&gt;
&lt;li&gt;Generate the badge&lt;/li&gt;
&lt;li&gt;Upload the badge to my repo, to the same branch that fired the build pipeline&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, I made some additions and created a &lt;a href="https://github.com/demyanets/angular-coverage-badges-action/pull/3"&gt;Pull Request&lt;/a&gt; to fulfill my needs (basically, parse test coverage XML files). After waiting for a response (still waiting), I decided it was not exactly what I wanted: I prefer to use mini-actions and re-use their results as inputs for other mini-actions. This way, I can easily change the pipeline, having code split into as small actions as possible and then compositing them, like &lt;a href="https://reactjs.org/docs/composition-vs-inheritance.html"&gt;the way React works&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So now, my &lt;a href="https://github.com/emibcn/Rac1.js/blob/master/.github/workflows/node.js.yml"&gt;workflow&lt;/a&gt; looks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build &amp;amp; test process (has not changed build nor deploy)&lt;/li&gt;
&lt;li&gt;Process XML coverage data using a mini PHP action &lt;a href="https://github.com/johanvanhelden/gha-clover-test-coverage-check"&gt;gha-clover-test-coverage-check&lt;/a&gt;. It needed some &lt;a href="https://github.com/johanvanhelden/gha-clover-test-coverage-check/pull/3"&gt;minimal additions&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Get processed data from previous Action Output into a self-made action to generate the badge &lt;a href="https://github.com/emibcn/badge-action"&gt;Badge Action&lt;/a&gt;. Here, coverage data is used to fill badge value (coverage percentage) and to decide value background color.&lt;/li&gt;
&lt;li&gt;Save generated badge into a dedicated branch, which stores the badges generated from testing any branch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Next steps&lt;/strong&gt;: Generate container actions (no other code than &lt;code&gt;action.yml&lt;/code&gt;) to join mini-actions and glue-actions (little &lt;code&gt;run&lt;/code&gt; to get, parse or adapt a value) and help me and others to do the same, in a much easier way, adaptable to everyone needs.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Maintainer Must-Haves&lt;/li&gt;
&lt;li&gt;DIY Deployments&lt;/li&gt;
&lt;li&gt;Phone Friendly&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Code of the first action I submitted code to: &lt;div class="ltag_github-liquid-tag"&gt;
  &lt;h1&gt;
    &lt;a href="https://github.com/demyanets/angular-coverage-badges-action/pull/3"&gt;
      &lt;img class="github-logo" alt="GitHub logo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg"&gt;
      &lt;span class="issue-title"&gt;
        Add ability to parse XML clover files
      &lt;/span&gt;
      &lt;span class="issue-number"&gt;#3&lt;/span&gt;
    &lt;/a&gt;
  &lt;/h1&gt;
  &lt;div class="github-thread"&gt;
    &lt;div class="timeline-comment-header"&gt;
      &lt;a href="https://github.com/emibcn"&gt;
        &lt;img class="github-liquid-tag-img" src="https://res.cloudinary.com/practicaldev/image/fetch/s--iRFGl6Yb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://avatars2.githubusercontent.com/u/693791%3Fv%3D4" alt="emibcn avatar"&gt;
      &lt;/a&gt;
      &lt;div class="timeline-comment-header-text"&gt;
        &lt;strong&gt;
          &lt;a href="https://github.com/emibcn"&gt;emibcn&lt;/a&gt;
        &lt;/strong&gt; posted on &lt;a href="https://github.com/demyanets/angular-coverage-badges-action/pull/3"&gt;&lt;time&gt;Jul 16, 2020&lt;/time&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag-github-body"&gt;
      &lt;p&gt;I have added:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;xml2json&lt;/code&gt; dependency in &lt;code&gt;package.json&lt;/code&gt;. It forces to add &lt;code&gt;dist/build/Release/node_expat.node&lt;/code&gt; to the repo&lt;/li&gt;
&lt;li&gt;TS models for the imported XML&lt;/li&gt;
&lt;li&gt;A translating function from the XML to the already used &lt;code&gt;coverage-summary.json&lt;/code&gt; structure&lt;/li&gt;
&lt;li&gt;Some tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I have changed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default file to parse:  coverage/clover.xml&lt;/li&gt;
&lt;li&gt;Github workflow to generate and parse self coverage test&lt;/li&gt;
&lt;li&gt;README, action.yml and package.json to reflect repo change and differences&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, the process has added automatically the coverage badges to &lt;code&gt;.github/badges/&lt;/code&gt; using the results from nuning &lt;code&gt;npm test -- --coverage&lt;/code&gt; ;)&lt;/p&gt;

&lt;p&gt;It will probably be better to make a generic parser dispatcher and put there the 2 existing parsers and the new ones. Also add an option to let the user force the parser type. Now it's autodetected by file extension: if file name ends with &lt;code&gt;.json&lt;/code&gt;, use original, if not, use clover XML parser.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;/div&amp;gt;
&amp;lt;div class="gh-btn-container"&amp;gt;&amp;lt;a class="gh-btn" href="https://github.com/demyanets/angular-coverage-badges-action/pull/3"&amp;gt;View on GitHub&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
&lt;li&gt;Code of the second action I submitted code to: &lt;div class="ltag_github-liquid-tag"&gt;
&lt;br&gt;
  &lt;h1&gt;
&lt;br&gt;
    &lt;a href="https://github.com/johanvanhelden/gha-clover-test-coverage-check/pull/3"&gt;&lt;br&gt;
      &lt;img class="github-logo" alt="GitHub logo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg"&gt;&lt;br&gt;
      &lt;span class="issue-title"&gt;&lt;br&gt;
        Fix #1 - Export processed value as GitHub Action Output&lt;br&gt;
      &lt;/span&gt;&lt;br&gt;
      &lt;span class="issue-number"&gt;#3&lt;/span&gt;&lt;br&gt;
    &lt;/a&gt;&lt;br&gt;
  &lt;/h1&gt;
&lt;br&gt;
  &lt;div class="github-thread"&gt;
&lt;br&gt;
    &lt;div class="timeline-comment-header"&gt;
&lt;br&gt;
      &lt;a href="https://github.com/emibcn"&gt;&lt;br&gt;
        &lt;img class="github-liquid-tag-img" src="https://res.cloudinary.com/practicaldev/image/fetch/s--iRFGl6Yb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://avatars2.githubusercontent.com/u/693791%3Fv%3D4" alt="emibcn avatar"&gt;&lt;br&gt;
      &lt;/a&gt;&lt;br&gt;
      &lt;div class="timeline-comment-header-text"&gt;
&lt;br&gt;
        &lt;strong&gt;&lt;br&gt;
          &lt;a href="https://github.com/emibcn"&gt;emibcn&lt;/a&gt;&lt;br&gt;
        &lt;/strong&gt; posted on &lt;a href="https://github.com/johanvanhelden/gha-clover-test-coverage-check/pull/3"&gt;&lt;time&gt;Sep 08, 2020&lt;/time&gt;&lt;/a&gt;&lt;br&gt;
      &lt;/div&gt;
&lt;br&gt;
    &lt;/div&gt;
&lt;br&gt;
    &lt;div class="ltag-github-body"&gt;
&lt;br&gt;
      &lt;p&gt;Fix #1&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;/div&amp;gt;
&amp;lt;div class="gh-btn-container"&amp;gt;&amp;lt;a class="gh-btn" href="https://github.com/johanvanhelden/gha-clover-test-coverage-check/pull/3"&amp;gt;View on GitHub&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
&lt;li&gt;Code of the action I made &lt;div class="ltag-github-readme-tag"&gt;
&lt;br&gt;
  &lt;div class="readme-overview"&gt;
&lt;br&gt;
    &lt;h2&gt;
&lt;br&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;&lt;br&gt;
      &lt;a href="https://github.com/emibcn"&gt;&lt;br&gt;
        emibcn&lt;br&gt;
      &lt;/a&gt; / &lt;a href="https://github.com/emibcn/badge-action"&gt;&lt;br&gt;
        badge-action&lt;br&gt;
      &lt;/a&gt;&lt;br&gt;
    &lt;/h2&gt;
&lt;br&gt;
    &lt;h3&gt;
&lt;br&gt;
      Create a badge using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers)&lt;br&gt;
    &lt;/h3&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="ltag-github-body"&gt;
&lt;br&gt;
    

&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/emibcn/badge-action/workflows/.github/workflows/test.yml/badge.svg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CxTcmGIs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/emibcn/badge-action/workflows/.github/workflows/test.yml/badge.svg" alt=".github/workflows/test.yml"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer" href="https://raw.githubusercontent.com/emibcn/badge-action/badges/master/test-badge.svg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BxBVn0es--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/emibcn/badge-action/badges/master/test-badge.svg" alt=".github/workflows/test.yml"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
Badge action&lt;/h1&gt;
&lt;p&gt;This action generates a SVG badge using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers). The badge is generated using the NPM package &lt;a href="https://github.com/bokub/gradient-badge"&gt;gradient-badge&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
Inputs&lt;/h2&gt;
&lt;h3&gt;
&lt;code&gt;label&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Required&lt;/strong&gt; The left label of the badge, usually static.&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;label-color&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Required&lt;/strong&gt; Hex or named color for the label. Default: &lt;code&gt;555&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;status&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Required&lt;/strong&gt; The right status as the badge, usually based on results.&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;color&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Required&lt;/strong&gt; An array (comma separated) with hex or named colors of the badge value background. More than one creates gradient background. Default: &lt;code&gt;blue&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;style&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Required&lt;/strong&gt; Badge style: flat or classic. Default: &lt;code&gt;classic&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;icon&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;Use icon.&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;icon-width&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;Set this if icon is not square. Default: &lt;code&gt;13&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;scale&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;Set badge scale. Default: &lt;code&gt;1&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;path&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;The file path to store the badge image file. Only output to &lt;code&gt;badge&lt;/code&gt; action output if not defined.&lt;/p&gt;
&lt;h2&gt;
Outputs&lt;/h2&gt;
&lt;h3&gt;
&lt;code&gt;badge&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;The badge SVG contents.&lt;/p&gt;
&lt;h2&gt;
Example usage&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;uses: emibcn/badge-action@v1
with
  label: 'Test coverage'&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/emibcn/badge-action"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;Code of the JS PWA app using those actions &lt;div class="ltag-github-readme-tag"&gt;
&lt;br&gt;
  &lt;div class="readme-overview"&gt;
&lt;br&gt;
    &lt;h2&gt;
&lt;br&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;&lt;br&gt;
      &lt;a href="https://github.com/emibcn"&gt;&lt;br&gt;
        emibcn&lt;br&gt;
      &lt;/a&gt; / &lt;a href="https://github.com/emibcn/Rac1.js"&gt;&lt;br&gt;
        Rac1.js&lt;br&gt;
      &lt;/a&gt;&lt;br&gt;
    &lt;/h2&gt;
&lt;br&gt;
    &lt;h3&gt;
&lt;br&gt;
      React.js app to play Rac1 radio station podcasts&lt;br&gt;
    &lt;/h3&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="ltag-github-body"&gt;
&lt;br&gt;
    

&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/emibcn/Rac1.js/workflows/Node.js%20CI/badge.svg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1NLqt2-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/emibcn/Rac1.js/workflows/Node.js%2520CI/badge.svg" alt="Node.js CI"&gt;&lt;/a&gt;
&lt;a href="https://travis-ci.com/emibcn/Rac1.js" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/fd9ac6ebabae4558d0d27e6f1d0416ae08016d07/68747470733a2f2f7472617669732d63692e636f6d2f656d6962636e2f526163312e6a732e7376673f6272616e63683d6d6173746572" alt="Build Status"&gt;&lt;/a&gt;
&lt;a href="https://raw.githubusercontent.com/emibcn/Rac1.js/badges/master/test-coverage.svg" rel="nofollow"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1FuD2F5f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/emibcn/Rac1.js/badges/master/test-coverage.svg" alt="coverage"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Web APP to listen to &lt;a href="https://www.rac1.cat/" rel="nofollow"&gt;Rac1 radio station&lt;/a&gt; podcasts. Uses React as JS frontend library and GitHub pages to publish it at &lt;strong&gt;&lt;a href="https://emibcn.github.io/Rac1.js/" rel="nofollow"&gt;Rac1 podcast player at Github Pages&lt;/a&gt;&lt;/strong&gt;. There, you will find &lt;a href="https://github.com/emibcn/Rac1.js/tree/gh-pages"&gt;this repo's &lt;code&gt;gh-pages&lt;/code&gt; branch&lt;/a&gt; contents, which are the results of executing &lt;code&gt;yarn build&lt;/code&gt; on &lt;a href="https://github.com/emibcn/Rac1.js/actions"&gt;this project's GitHub workflow/Actions&lt;/a&gt; using &lt;a href="https://github.com/emibcn/Rac1.js/tree/master/app"&gt;this project's source application&lt;/a&gt; (See more in the &lt;a href="https://github.com/emibcn/Rac1.js#install"&gt;Install&lt;/a&gt; section).&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://github.com/emibcn/Rac1.js/blob/master/app/src/Backends/"&gt;podcasts lister&lt;/a&gt; is a pure JS lib, which only depends on &lt;a href="https://github.com/mo/abortcontroller-polyfill"&gt;abortcontroller-polyfill&lt;/a&gt; to help GoogleBot execute modern JS, so you can easily re-use it for other JS projects.&lt;/p&gt;
&lt;h2&gt;
Motivation&lt;/h2&gt;
&lt;p&gt;I made this app for 3 reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I needed a better way to listen to those podcasts (because the &lt;a href="https://play.google.com/store/apps/details?id=com.grupogodo.rac1" rel="nofollow"&gt;official app&lt;/a&gt; is not useful to me) and I wanted it to be easily compatible with all my devices.&lt;/li&gt;
&lt;li&gt;Learn modern JavaScript (and some other modern stuff): I've been using JavaScript (mostly with JQuery) since a long time ago…&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/emibcn/Rac1.js"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;Production deploy of this &lt;a href="https://emibcn.github.io/Rac1.js/"&gt;app at GitHub Pages&lt;/a&gt;
&lt;/li&gt;
&lt;br&gt;


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

&lt;p&gt;The action I made is a KISS interface for a JS package that generates an SVG file from passed attributes. The JS package is &lt;a href="https://github.com/bokub/gradient-badge"&gt;gradient-badge&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>actionshackathon</category>
      <category>javascript</category>
      <category>react</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
