Skip to content
  • Computer & Technology
  • SEO
  • Technology
  • About Us
    • Contact Us
    • Advertise Here
    • Disclosure Policy
    • Sitemap
  • SEO

JS monorepos in prod 7: Continuous Integration and Continuous Deployment with GitHub Actions

April 11, 2022
evan
0 Comments

Table of Contents

  • Create your first CI workflow with GitHub and GitHub Actions
  • View your workflow results
  • Continuous Delivery with GitHub Actions
  • Cheatsheet
  • Conclusion


The value of CI/CD lies in the ability to control and coordinate changes and feature addition in multiple, iterative releases while simultaneously having multiple services being actively developed in parallel. In the previous article of this series, we showed how to implement continuous integration using Travis CI. In this article, we illustrate how to achieve the same result using another continuous integration solution, GitHub Actions.

This article is part of a series relative to JS monorepos best practices:

Related Posts:

  • Crypto as a weapon in the fight for Ukraine

Create your first CI workflow with GitHub and GitHub Actions

GitHub Actions allows you to automate, customize, and execute your software development workflows directly in your GitHub repository. GitHub Actions are event-driven, meaning that you can run a series of commands after a specified event has occurred. For instance, every time someone pushes a commit to a branch, you automatically run all unit tests associated with the branch. You only need an existing GitHub repository to create and run a GitHub Actions workflow.

At the root of your repository, create a new file in the .github/workflows directory named node.js.yml. Next, copy the following YAML contents into the node.js.yml file.

name: Node.js CI
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
    - uses: actions/setup-[email protected]
      with:
        node-version: '14.x'
    - run: yarn
    - run: yarn run test

Let’s take a closer look at what this workflow actually does and what it’s composed of:

  • events: activities that trigger the workflow. They are represented by the on property. In our case, any push on any branch will trigger this workflow;
  • jobs: set of steps that execute on the same runner. Here, we only run unit tests;
  • steps: task that can run commands in a job. Our workflow is composed of multiple steps:
    • clone the remote repository;
    • setup a specific NodeJS version (14 in our case);
    • install dependencies;
    • execute unit tests.
  • actions: commands that are combined into steps to create a job. For instance, run executes shell commands. The uses keyword gets default actions defined in this repository and executes them.

Committing the workflow file in your repository triggers the push event and runs your workflow.

View your workflow results

On your GitHub repository, click on the Actions tab. Click on the workflow on the left sidebar. You can see the status of your workflow as well as detailed logs of the run.


Build status success

Continuous Delivery with GitHub Actions

Now that you’ve set up automated testing on every build, you might want to automate deployments. As explained in the previous article, the lerna publish from-git command comes in handy if you want to easily deploy your packages.

Create a new file in the .github/workflows folder called publish.yml. Copy the following piece of code into the file.

name: Node.js CD
on:
  release:
    types: [created]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
    - uses: actions/setup-[email protected]
      with:
        node-version: '14.x'
        registry-url: 'https://registry.npmjs.org'
    - run: yarn
    - run: yarn publish
      env:
        NODE_AUTH_TOKEN: $ secrets.NPM_TOKEN 

The workflow above runs when the release event triggers. The workflow publishes the package to the npm registry if CI tests pass. To perform authenticated operations against the npm registry in your workflow, you’ll need to store your npm authentication token as a secret. If you already deployed packages from your machine, the NPM_TOKEN value can be read from your local .npmrc and reported to your project settings. Extract your npm credential:

cat ~/.npmrc | egrep '^//registry.npmjs.org' | sed 's/.*=//'

Otherwise, you can navigate to the npm registry website and generate a new token manually (recommanded).


npm new token


npm token list

Copy the value and paste it to Settings > Secrets > New repository secret in the GitHub repository.


Github add secret

A new entry is created.


Github view secret

This workflow builds on existing Node.js tools to simplify the process of publishing to the npm Registry. Your package is now available for the entire Open Source community to look at.

Cheatsheet

  • At the root of your repository, create a new file in the .github/workflows directory named node.js.yml. Next, copy the following YAML contents into the node.js.yml file.
    name: Node.js CI
    on: push
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/[email protected]
        - uses: actions/setup-[email protected]
          with:
            node-version: '14.x'
        - run: yarn
        - run: yarn run test
  • Create a new file in the .github/workflows folder called publish.yml. Copy the following piece of code into the file.
    name: Node.js CD
    on:
      release:
        types: [created]
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/[email protected]
        - uses: actions/setup-[email protected]
          with:
            node-version: '14.x'
            registry-url: 'https://registry.npmjs.org'
        - run: yarn
        - run: yarn publish
          env:
            NODE_AUTH_TOKEN: $ secrets.NPM_TOKEN 
  • Get your NPM_TOKEN.
    cat ~/.npmrc | egrep '^//registry.npmjs.org' | sed 's/.*=//'

    Copy the value and paste it to ‘Settings > Secrets > New repository secret’ in the GitHub repository.

Conclusion

CI using GitHub Actions offers workflows that build code in your repository and run unit tests very easily. You can publish your work to a registry as part of your continuous integration workflow. GitHub Actions is available with every GitHub offers. With GitHub Free for user accounts, you have access to 2,000 GitHub Actions minutes which is sufficient for most Open Source projects.



Source link

All Tek Information Technology Amish Use Of Technology Amr Technology Safe Applications Of Finfet Technology Braddon Cornish Technology West Business And Technology Major Uci Cross-Device Technology Residence Cti Concret Technology Youtube Defence Laser Technology Melts Mortar Defensive Soundwave Technology Define Specification Information N Technology Firsthand Technology Opportunity Fund Fish Processing Technology Gmhall Gage Information Technology Director Linkedin Ihs Markit Technology Research Portfolio Indian Institute Of Technology Mathematics Juan Torres Science And Technology Livewire Communications And Technology Medical Device Scam Technology Nasa Technology For Mars New Technology For Draw New Technology In Information Security New Technology Michigan Nike Technology Summer Internships Philus Technology Philippines Policy Issues In Technology Powerpoint Quiz Technology In Action Technology Actuary Consulting Technology Advancement In Ford Cars Technology And Womens Voices Summary Technology Commercialization Syllabus Technology In Medicak Technology In Saving Lives Technology Makes Escape Technology Next Generation Technology Opens Choices Technology Pitch Deck Outline Technology Super Heros The Hill Technology Reporter The Technology Industry 2017 Think Tanks - Technology Governance Trade Market For Technology Using Technology At A Bbq Visit Institute Of Military Technology Wearable Technology Doctors What Is Assitive Technology Elmo What Isnexus Technology What Technology Creates Autopsy Women Email Newsletters Technology World Wide Technology Mumbai

« Tips To Win The Mobile SEO Game In 2022 And Beyond
Despite railing against Big Tech and Big Pharma, records show Dr. Oz has invested millions in both »
Sidebar

Recent Posts

  • Mesh Wi-Fi Systems 101: The Best Tips
  • League City DNA tool helping to solve cold cases
  • ROG Rapture GT-AX6000 Router review – Is a non-mesh router worth $799.00?
  • 6 Tech Stocks for Bargain-Hunting Investors
  • Comparison of database architectures: data warehouse, data lake and data lakehouse
Intellifluence Trusted Blogger

Archives

Categories

May 2022
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« Apr    

BL

LP

TL

Visit Now

signature health
pixliv Digitally first class

Theme by The WP Club . Proudly powered by WordPress

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT