<?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>Forem: Thierry Ntirandekura</title>
    <description>The latest articles on Forem by Thierry Ntirandekura (@thiernope).</description>
    <link>https://forem.com/thiernope</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%2F519320%2Ff302b142-f6f1-4cda-8fce-46db02783008.jpeg</url>
      <title>Forem: Thierry Ntirandekura</title>
      <link>https://forem.com/thiernope</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/thiernope"/>
    <language>en</language>
    <item>
      <title>Trigger Netlify Deployments Using Github Workflow  (CI/CD)</title>
      <dc:creator>Thierry Ntirandekura</dc:creator>
      <pubDate>Fri, 03 Dec 2021 18:04:48 +0000</pubDate>
      <link>https://forem.com/thiernope/trigger-netlify-deploys-using-github-workflow-cicd-lcm</link>
      <guid>https://forem.com/thiernope/trigger-netlify-deploys-using-github-workflow-cicd-lcm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Submission category&lt;/strong&gt;&lt;br&gt;
This is my submission to &lt;a href="https://dev.to/devteam/join-us-for-the-2021-github-actions-hackathon-on-dev-4hn4"&gt;GitHub Actions Hackathon&lt;/a&gt; &lt;strong&gt;under DIY Deployments.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/Thiernope/gihub-workflows-netlify"&gt;My github Repository&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have you wondered how you can deploy your react app on netlify as quickly as possible? &lt;a href="https://github.com/features/actions"&gt;Github Actions&lt;/a&gt; makes it easy and facilitates quick deployments using github workflow. In this post, I am going to show you how to trigger automatic deployments to netlify using github workflow.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a simple react app using &lt;code&gt;npx create-react-app&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm run build&lt;/code&gt; in your terminal. This will create your build folder in the root directory. Netlify allows to drag and drop a build folder in the drop area as you can see it on the image below. Fill free to use this option.
Go login in to netlify &lt;strong&gt;netlify &amp;gt; sites&lt;/strong&gt; you will see where to drop this build folder. Once dropped, the site will go live in a few seconds. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yg627cGU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uhcbqfvlelavhkkg6qz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yg627cGU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uhcbqfvlelavhkkg6qz.png" alt="Dropping" width="880" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Netlify can also give access to deploy using netlify-cli via your terminal. You can &lt;br&gt;
 &lt;a href="https://www.netlify.com/blog/2016/07/22/deploy-react-apps-in-less-than-30-seconds/"&gt;Refer to this resource&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Connect your local repository to a github repostitory(remote), and &lt;a href="https://docs.cloudera.com/machine-learning/1.2/projects/topics/ml-linking-an-existing-project-to-a-git-remote.html"&gt;refer to this guide&lt;/a&gt;. Then you will have a remote repository and then be able to add actions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, it's time to set github workflow on your repository. To do it, go to &lt;strong&gt;github &amp;gt; actions&lt;/strong&gt; and add a github workflow. There are many templates they provide. But in this article, I am going to use Node.js.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WXkclPIu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ac4ltkud3hb7mr6gr7s0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WXkclPIu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ac4ltkud3hb7mr6gr7s0.PNG" alt="Actions" width="880" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have chosen NodeJs, you will be given the template below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fOGeZvRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msyu5i10n12rh14umst8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fOGeZvRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msyu5i10n12rh14umst8.PNG" alt="Template" width="871" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fill free to edit the template with the following edits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: CI/CD

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x, 14.x]

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}

    - name: Install dependencies
      run: npm install

    - name: Run the tests
      run: npm test 

    - name: Build
      run: npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, click to start a commit and commit the new file. Your gitworkflow will run successfully.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now it's time to deploy to netlify:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To deploy to netlify, we need 2 thigs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Our Netlify site_ID &lt;/li&gt;
&lt;li&gt;Netlify personal-Access token&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To find the site_ID, go to your already deployed app &amp;gt; &lt;strong&gt;Site overview &amp;gt; site settings &amp;gt; General&lt;/strong&gt; then, copy that site_ID&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xoiE-4i8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dw3kpb6fkfwkfmz8dnw1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xoiE-4i8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dw3kpb6fkfwkfmz8dnw1.png" alt="Site_ID" width="880" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To find Netlify pesonal access token, click your profile picture, go to *&lt;em&gt;user setting &amp;gt; application *&lt;/em&gt;. Generate a token and copy as you will need it later. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nfFfdfXp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1n06un8d0m3fj4e6y3v.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nfFfdfXp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1n06un8d0m3fj4e6y3v.PNG" alt="Personal access token" width="880" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you have copied both Site_ID, and netlify personal access token, It's time to go on github and put in the repository secrets. Go to &lt;strong&gt;github &amp;gt; settings &amp;gt; secrets&lt;/strong&gt; and click &lt;strong&gt;add new secret.&lt;/strong&gt; Then add netlfy site ID and Personal access token. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SHAEJs4O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1k7nv1cxe6u34r9eks7a.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SHAEJs4O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1k7nv1cxe6u34r9eks7a.PNG" alt="secrets" width="880" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After adding the secrets on github, Lets then add this step of deploying our site to netlify in our &lt;strong&gt;Node.js.yml&lt;/strong&gt; file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: Deploy Site
      env:
        NETLIFY_SITE_ID: ${{ secrets.NETLFY_APP_ID }}
        NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }}
      run: netlify deploy --prod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you replace &lt;code&gt;${{secrests.The name of the secret you put on your github}}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The final github workflow will look like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final YML file&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: CI/CD

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x, 14.x]

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}

    - name: Install dependencies
      run: npm install

    - name: Run the tests
      run: npm test 

    - name: Build
      run: npm run build
    - name: Deploy Site
      env:
        NETLIFY_SITE_ID: ${{ secrets.NETLFY_APP_ID }}
        NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }}
      run: netlify deploy --prod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After all your github workflow is set well, go in your root folder of your react app and add &lt;code&gt;netlify.toml&lt;/code&gt; file and add this code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[build]
command = "npm run build"
publish = "build"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may also put additional staffs like redirects rules in &lt;code&gt;netlify.toml&lt;/code&gt; especially when your react is built with react-router dom. Or Go to publish folder and create a new file &lt;code&gt;_redirects&lt;/code&gt; and write the code below: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/* /indext.html 200&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After setting the above workflow, and make sure you have the above &lt;code&gt;netlify.toml&lt;/code&gt; file, your application will automatically be deployed to netlify in such less amount of time as that time your workflow will take you to be complete. &lt;/p&gt;

&lt;p&gt;Happy Coding &lt;strong&gt;^_^&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>actionshackathon21</category>
      <category>netlify</category>
      <category>opensource</category>
      <category>github</category>
    </item>
  </channel>
</rss>
