<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Đinh Quân on Medium]]></title>
        <description><![CDATA[Stories by Đinh Quân on Medium]]></description>
        <link>https://medium.com/@quandnl?source=rss-92c31015cbad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H9Efbtrguj-gMUkwTc4A6w@2x.jpeg</url>
            <title>Stories by Đinh Quân on Medium</title>
            <link>https://medium.com/@quandnl?source=rss-92c31015cbad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 01:41:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@quandnl/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Upload Files in repository to Firebase Storage in Github Action]]></title>
            <link>https://quandnl.medium.com/upload-files-in-repository-to-firebase-storage-in-github-action-f467c1309a54?source=rss-92c31015cbad------2</link>
            <guid isPermaLink="false">https://medium.com/p/f467c1309a54</guid>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[uploading]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Đinh Quân]]></dc:creator>
            <pubDate>Sat, 09 Jan 2021 12:42:29 GMT</pubDate>
            <atom:updated>2021-01-09T18:51:06.685Z</atom:updated>
            <content:encoded><![CDATA[<h3>Upload a file in the repository to Firebase Storage in Github Action</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*npT9DbLKJz691bfA" /><figcaption>Photo by <a href="https://unsplash.com/@richygreat?utm_source=medium&amp;utm_medium=referral">Richy Great</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>With the power of Github Action, we can implement the CI/CD process with various tasks quickly and directly. I recently have a CD task in my current project, which needs to upload some files in the repository to Firebase Storage after the CI is completed. I would like to share how I handled the task using Github Action.</p><p>The solution uses <strong>python 3.7.6 </strong>on a macOS runner machine.</p><p><strong>Prerequisite</strong>: a Github repository, a Google Firebase/Cloud account, and a cup of coffee ☕️ 😊.</p><h3>1. Set up Firebase project</h3><p>In your <a href="https://console.firebase.google.com/">Firebase console</a> project, let’s get started with the Storage setup if you haven’t done it yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UhvGF4HAbBGwTxy1aD8Qtw.png" /><figcaption>Set up Firebase storage with the default rule</figcaption></figure><p>Notice the bucket name in the File section; we will need it later. In this article, the default bucket will be used. Check out the <a href="https://firebase.google.com/docs/storage">Firebase document</a> for more detail about the bucket and custom bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCtm2pwyhhLdv_W-D25kPA.png" /><figcaption>The bucket name reference will have a format <strong>gs://&lt;BUCKET_NAME&gt;.appspot.com</strong></figcaption></figure><h3>2. Set up Google cloud’s Service account and get the Credential key</h3><p>From the <a href="https://console.cloud.google.com/">Google cloud console</a>, navigate to the associated project in the <strong>All</strong> tab and open it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jmp7bzrnGEq2aV9aHL7-UQ.png" /><figcaption>Check the project Id to make sure it fits with the one on Firebase.</figcaption></figure><p>In the <strong>IDENTITY &amp; SECURITY</strong> section on the menu, select <strong>Identity</strong> &gt; <strong>Service Accounts</strong>. Two default service accounts existed in the section already without the credential key. Choose the <strong>Create key</strong> action to generate and download the JSON certificate for the credential. Securely store the JSON file because the key it contains cannot be recovered if lost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ay1kC_ImzB_ZLB017xleJQ.png" /><figcaption>Create the credential key for a Service account. The key will be downloaded right after created.</figcaption></figure><h3>3. Store the secret key file on Github’s secret</h3><p>The upload process, which needs to import the certificate key JSON file, will be executed on Github Action. However, storing sensitive information directly on the repository is not a good idea, even a private repository. There are some great approaches to protecting private data; one is to use <strong>Github’s encrypted secrets</strong>.</p><p>The idea is to encode the key file to a base64 string and store it on Github Secret, then decode it later in the workflow to retrieve a file that the upload script can uses. The script below could encode a file in the same directory to a base64 string and print it out.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3173949984e3a1f07cb7f26a87dc276a/href">https://medium.com/media/3173949984e3a1f07cb7f26a87dc276a/href</a></iframe><p>Next step, create a secret on Github and use the base64 string as the content. Notice that there is some limitation like the secret name format or number of secret on each organization. Further information could be found <a href="https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3zdQFc8yJl0sT88Ah30fA.png" /><figcaption>In this article, we will store the key in a repository secret.</figcaption></figure><h3>4. The upload script</h3><p>We now have all the necessary elements (the Google cloud key file, the Google storage bucket name) for the upload script. Notice that the bucket name that we use is the part without <strong>gs:// </strong>as from <a href="https://firebase.google.com/docs/storage/admin/start">google firebase document</a>:</p><blockquote>You can specify a default bucket name when initializing the Admin SDK. Then you can retrieve an authenticated reference to this bucket. The bucket name must not contain gs:// or any other protocol prefixes. For example, if the bucket URL displayed in the <a href="https://console.firebase.google.com/project/_/storage">Firebase Console</a> is gs://bucket-name.appspot.com, pass the string bucket-name.appspot.com to the Admin SDK.</blockquote><p>Now, we use this python script to run the upload task whenever it is triggered. Remember to put this script file in the repository’s directory that matches the path we declared in the workflows <strong>.yml</strong> file, which we will create in the next part.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e501a30a2f2b01ef2faac2c342f7987/href">https://medium.com/media/5e501a30a2f2b01ef2faac2c342f7987/href</a></iframe><h3>5. Github Action workflow</h3><p>To create a workflow, in the repository site, select the <strong>Action</strong> tab and select a template for our workflows or skip to make a new one. Use the .<strong>yml</strong> script below and replace the corresponding file name and file path in the project.</p><p>In the workflow, we use another 3rd party action name <a href="https://github.com/marketplace/actions/base64-to-file"><strong>base64-to-file</strong></a>, which will export the base64 string from the secret that we added to a file and save it in <strong>/Users/runner/work/_temp </strong>on the runner machine. This file will be used as an input for Google’s credential object in the upload script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19224d4d7bad61f0c30bc6a9db18055b/href">https://medium.com/media/19224d4d7bad61f0c30bc6a9db18055b/href</a></iframe><p>The workflow file will be pushed to the repository after finish and be located in <strong>.github/workflows</strong>.</p><h3>Viola<strong>! 🤟🏻</strong></h3><p>From now, whenever the workflow’s conditions are triggered, the get credential and upload process will run and upload a specific file to Firebase Storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9LA4lLnbLhIrFDB5kl0tdg.png" /><figcaption>The public link of the uploaded file is written on the console.</figcaption></figure><p>Thank you for reading! 🙏🏻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f467c1309a54" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>