<?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: Prachit Suhas Patil</title>
    <description>The latest articles on DEV Community by Prachit Suhas Patil (@pprachit09).</description>
    <link>https://dev.to/pprachit09</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%2F497725%2Fadd99315-2277-4e71-872b-62371f6f8831.jpeg</url>
      <title>DEV Community: Prachit Suhas Patil</title>
      <link>https://dev.to/pprachit09</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pprachit09"/>
    <language>en</language>
    <item>
      <title>Firebase Hosting with GitHub Actions</title>
      <dc:creator>Prachit Suhas Patil</dc:creator>
      <pubDate>Sat, 24 Oct 2020 02:16:20 +0000</pubDate>
      <link>https://dev.to/pprachit09/firebase-hosting-with-github-actions-55ka</link>
      <guid>https://dev.to/pprachit09/firebase-hosting-with-github-actions-55ka</guid>
      <description>&lt;p&gt;Recently Firebase has launched a brand-new GitHub &lt;a href="https://github.com/marketplace/actions/deploy-to-firebase-hosting" rel="noopener noreferrer"&gt;Action&lt;/a&gt;. With this you can preview your site on every Pull Request. This Preview channel will be updated once PR is created or updated. Every PR will get its own preview channel, so you can focus on each PR's changes. Also we can configure Github Action to deploy the site to live version once PR is merged.&lt;/p&gt;

&lt;p&gt;I have configured this for one of my GitHub &lt;a href="https://github.com/pprachit09/coderlust-resume" rel="noopener noreferrer"&gt;repository&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to your GitHub repository and click on "Actions" tab.&lt;/li&gt;
&lt;li&gt;Click on "set up a workflow yourself" &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%2Fi%2F8vcvmjdbi8xzesrpdduz.JPG" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Give name to your file. Here I am naming my file as "deploy-preview.yml"&lt;/li&gt;
&lt;li&gt;Add below code in the yml file
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Deploy to preview channel

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
  pull_request:

jobs:
  build_and_preview:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      # Add any build steps here.
      - run: npm i &amp;amp;&amp;amp; npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"
          expires: 7d
          projectId: your-project-id
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok. So let's take a step back and understand what we have done here. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First we have added &lt;em&gt;on&lt;/em&gt; condition &lt;em&gt;pull_request&lt;/em&gt; so that this action will trigger on every Pull Request&lt;/li&gt;
&lt;li&gt;We have added &lt;code&gt;- run: npm i &amp;amp;&amp;amp; npm run build&lt;/code&gt; to download all the npm packages and create a build to deploy on production.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;repoToken&lt;/em&gt; You don't need to set this secret yourself - GitHub sets it automatically.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;projectId&lt;/em&gt; The Firebase project that contains the Hosting site to which you want to deploy. If left blank, you need to check in a .firebaserc file so that the Firebase CLI knows which Firebase project to use.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;firebaseServiceAccount&lt;/em&gt; Now this is required and you can find the same in your project settings. Go to &lt;em&gt;&lt;a href="https://console.firebase.google.com/u/1/project/%7Bproject-name%7D/settings/serviceaccounts/adminsdk" rel="noopener noreferrer"&gt;https://console.firebase.google.com/u/1/project/{project-name}/settings/serviceaccounts/adminsdk&lt;/a&gt;&lt;/em&gt; and click on &lt;em&gt;Generate new private key&lt;/em&gt;. Save the json file and add it in GitHub secrets.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;For that, go to settings tab of your repository and select secrets from the left menu.&lt;br&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%2Fi%2Fplpaksk9uzh8hf15u0s0.JPG" 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%2Fi%2Fplpaksk9uzh8hf15u0s0.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;em&gt;New Secret&lt;/em&gt;. Give the Name as &lt;em&gt;FIREBASE_SERVICE_ACCOUNT&lt;/em&gt; and in value field, paste the JSON copied in the Firebase project. Click on save.&lt;br&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%2Fi%2Fxg2k8nnt19z13ovf74i5.JPG" 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%2Fi%2Fxg2k8nnt19z13ovf74i5.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now you are ready to commit your new GitHub action file to your repository. From the right hand side, Click on "Start commit" and give commit message. Also, select option of create a new branch for this commit and start a pull request.&lt;br&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%2Fi%2Fx7s3cql2du4ir21dh2hw.JPG" 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%2Fi%2Fx7s3cql2du4ir21dh2hw.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you raise a Pull Request, you can see the GitHub action in Action. Once the Action is completed, you will see the preview URL present on your PR. Super Cool...!!!! You can also decide the expiry of this Preview Channel by specifying it in your .yml file you created earlier. &lt;em&gt;expires&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;If you want to deploy your site to the live version on successful merge. You can add one more GitHub Action, For example let's call it as "deploy_live.yml". Add below content in your file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Deploy to Live Channel

on:
  push:
    branches:
      - main

jobs:
  build_and_preview:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      # Add any build steps here. For example:
      - run: npm i &amp;amp;&amp;amp; npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"
          projectId: your-project-id
          channelId: live
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are specifying,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;on:
  push:
    branches:
      - main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that this action will only trigger when PR is merged in main branch.&lt;/p&gt;

&lt;p&gt;And Here we go....!!! We have completely automated deployment of our site.&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://github.com/marketplace/actions/deploy-to-firebase-hosting" rel="noopener noreferrer"&gt;https://github.com/marketplace/actions/deploy-to-firebase-hosting&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/pprachit09/coderlust-resume/tree/main/.github/workflows" rel="noopener noreferrer"&gt;https://github.com/pprachit09/coderlust-resume/tree/main/.github/workflows&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to share your thoughts...!!! Happy Learning.&lt;/p&gt;

</description>
      <category>react</category>
      <category>github</category>
      <category>firebase</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
