'Deploy individual services from a monorepo using github actions

I have around 10 individual micro-services which are mostly cloud functions for various data processing jobs, which all live in a single github repository.

The goal is to trigger the selective deployment of these service to Google Cloud Functions, on push to a branch - when an individual function has been updated.

I must avoid the situation in which update of a single service causes the deployment of all the cloud functions.

My current repository structure:

/repo
--/service_A
----/function
----/notebook
--/service_B
----/function
----/notebook

On a side note, what are the pros/cons of using Github Actions VS Google Cloud Build for such automation?



Solution 1:[1]

GitHub Actions supports monorepos with path filtering for workflows. You can create a workflow to selectively trigger when files on a specific path change.

https://help.github.com/en/articles/workflow-syntax-for-github-actions#onpushpull_requestpaths

For example, this workflow will trigger on a push when any files under the path service_A/ have changed (note the ** glob to match files in nested directories).

on:
  push:
    paths:
      - 'service_A/**'

Solution 2:[2]

You could also run some script to discover which services were changed based on git diff and trigger corresponding job via GitHub REST API.

There could be two workflows main.yml and services.yml.

Main workflow will be configured to be started always on push and it will only start script to find out which services were changed. For each changed service repository dispatch event will be triggered with service name in payload.

Services workflow will be configured to be started on repository_dispatch and it will contain one job for each service. Jobs would have additional condition based on event payload.

See showcase with similar setup: https://github.com/zladovan/monorepo

Solution 3:[3]

The answer is that you switch to using NX.dev and just let it work it out for you with its nx affected deploy command

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Envek
Solution 2 Ján ?abala
Solution 3 airtonix