Emilio Schepis
Emilio Schepis's Blog

Emilio Schepis's Blog

Developing Geonotes — Automated build system with GitHub Actions — Ep. 6

Developing Geonotes — Automated build system with GitHub Actions — Ep. 6

Implementing an automated build system for Geonotes using GitHub actions to update the Hasura and Firebase instances.

An automated testing system is essential for ensuring that the code is always up to quality standards and consistently builds successfully.

I have implemented this system for Geonotes using GitHub actions.

🤖 Automated build system

To create an automated build system, I decided to use GitHub Actions. There are quite a few reasons why it is a good choice for my use case:

  • It is directly integrated into the Version Control System, without needing additional platforms
  • It is completely free for public repositories
  • It has a nice YAML syntax to define the various jobs

My Continuous Integration pipeline is composed of two main stages: Hasura and Firebase.

The first job essentially synchronizes the schema, metadata and migrations between my local environment and my remote Heroku environment. Source

steps:
  - uses: actions/checkout@v2
  - name: Download Hasura CLI
    run: |
      curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash
      sudo hasura update-cli --version ${HASURA_CLI_VERSION}
  - name: Apply migrations and metadata
    working-directory: hasura
    run: |
      hasura metadata apply
      hasura migrate apply --all-databases
      hasura metadata reload

The second job runs only after the first one is complete, and is responsible of linting and building the code, and ultimately updating all cloud functions in the remote Firebase project. Source

steps:
  # ...
  - name: Download Firebase CLI
    run: |
      curl -sL https://firebase.tools | bash
  - name: Update environment configuration
    run: |
      firebase use ${FIREBASE_PROJECT_ID}
      firebase functions:config:get > .runtimeconfig.json
  - name: Install dependencies
    run: npm ci
  - name: Lint
    run: npm run lint
  - name: Deploy
    run: firebase deploy --only functions

The whole pipeline is invoked each time a push is made to the develop branch, ensuring that the remote environments for both Hasura and Firebase always stay in sync.

🛑 A small roadblock

While writing the pipeline definition, I run into a weird problem in the interaction between the Firebase CLI and the GitHub action runner image.

Even though the deployment worked flawlessly from my machine using firebase deploy --only functions, running the same command in the GitHub runner resulted in a syntax error on optional chaining (?.).

Technically, optional chaining is available in ES2020 and should be fully supported by Node.js 14 (which both my system and the action are running). I have opened an issue on the Firebase tools repository, but for now the easiest workaround has been to target ES2019 during the TypeScript build.

⭐️ The final result

I am now much more confident that my backend is always in a working state and synchronized between my local environment and my deployment target. This should ensure more peace of mind when finally releasing to production.

Screen Shot 2021-08-13 at 23.04.24.jpg

🚧 Next steps

The first workflow is in progress but it still does not cover the frontend part. Ideally I'll want to also deploy the Expo artifacts on push.

I want to also focus on building more base functionalities into the app, like the ability to create a custom note in the current location, and a list of all the notes the user has created.

🎙 How to follow the project

I'll be posting updates throughout the development process and as I learn new thing regarding development, design, and marketing.

If you'd like to have even more real-time updates you can

 
Share this