1 minute read

The guideline is created for Nx monorepo workspace only to build and deploy affected apps to AWS S3 by github workflow.

Let’s consider the below monorepo structure . └── YourMonoRepo/ ├── apps/ │ ├── app1 │ └── app2 └── libs/ ├── lib1 └── lib2

The workflow will be triggered if there is any commit is made on branch develop.

1
2
3
4
5
6
name: CI-Deploy

on:
  push:
    branches:
      - develop

Setup build job

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      app1_exist: $
      app2_exist: $
    steps:
      - name: 🛎️ Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: 📥 Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 20  # Specify your Node.js version
          cache: 'npm'
      - name: 📦 Install dependencies
        run: npm ci
      - name: 🏗️ Build only affected apps
        run: npx nx affected -t build --base=develop~1 --head=develop
      - name: 🔍 Check if app1 build output folder exists
        id: check_build_output1
        if: $
        run: echo "app1_exist=true" >> "$GITHUB_OUTPUT"
      - name: 🔍 Check if app1 build output folder exists
        id: check_build_output2
        if: $
        run: echo "app2_exist=true" >> "$GITHUB_OUTPUT"
      - name: ⬆️ Upload app1 artifact
        if: steps.check_build_output.outputs.app1_exist == 'true'
        uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist/apps/app1
      - name: ⬆️ Upload app2 artifact
        if: steps.check_build_output.outputs.app2_exist == 'true'
        uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist/apps/app2

Steps

  1. Checkout the source code
  2. Setup node.js env
  3. Install dependencies
  4. Build affected apps
  5. Check if output folder of app1 is existed
  6. Check if output folder of app2 is existed
  7. Upload artifacts

Leave a comment