From e5e23e3c751e4397f7bae1353af8bd1af6d027d5 Mon Sep 17 00:00:00 2001 From: Ghian Date: Sat, 18 Jan 2025 22:45:51 +0800 Subject: [PATCH] ci: refactor build workflows (#108) - Combined the separate build workflows for the Go server and Node client into a unified file. - Refactored steps for better readability and maintainability. - Improved efficiency by consolidating tasks and avoiding duplication. --- .github/workflows/build.yaml | 68 +++++++++++++++++++++++++++++ .github/workflows/client-build.yaml | 37 ---------------- .github/workflows/go-build.yaml | 50 --------------------- 3 files changed, 68 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/build.yaml delete mode 100644 .github/workflows/client-build.yaml delete mode 100644 .github/workflows/go-build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..8dc4fd6 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,68 @@ +name: Go React Auth | Build + +on: + pull_request: + branches: + - develop + workflow_dispatch: + +jobs: + build: + name: Build Application + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ">=1.23" + + - name: Cache Go Modules + uses: actions/cache@v4 + with: + path: ~/.cache/go-build + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-build- + + - name: Check Go Version + run: go version + + - name: Run Server Build + run: go build -tags netgo -ldflags '-s -w' -o app + + - name: Upload Server Build Artifact + uses: actions/upload-artifact@v4 + with: + name: server + path: app + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Cache Node Modules + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-modules-${{ hashFiles('client/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node-modules- + + - name: Install Client Dependencies + run: npm ci --cache .npm --prefer-offline + working-directory: client + + - name: Run Build + run: npm run build + working-directory: client + + - name: Upload Client Build Artifact + uses: actions/upload-artifact@v4 + with: + name: client + path: app diff --git a/.github/workflows/client-build.yaml b/.github/workflows/client-build.yaml deleted file mode 100644 index de7cb61..0000000 --- a/.github/workflows/client-build.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name: Client - Build - -on: - pull_request: - branches: - - develop - workflow_dispatch: - -jobs: - build: - name: Build Application - runs-on: ubuntu-latest - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Install Dependencies - run: | - cd client - npm ci --cache .npm --prefer-offline - - - name: Run Build - run: | - cd client - npm run build - - - name: Upload Build Artifact - uses: actions/upload-artifact@v4 - with: - name: client-app - path: app diff --git a/.github/workflows/go-build.yaml b/.github/workflows/go-build.yaml deleted file mode 100644 index cdc4d3d..0000000 --- a/.github/workflows/go-build.yaml +++ /dev/null @@ -1,50 +0,0 @@ -name: Backend - Build - -on: - pull_request: - branches: - - develop - workflow_dispatch: - -jobs: - build: - name: Build Application - runs-on: ubuntu-latest - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: ">=1.23" - - - name: Cache Go Modules - uses: actions/cache@v4 - with: - path: ~/.cache/go-build - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-build- - - - name: Check Go Version - run: go version - - - name: Run Build - env: - PORT: ${{ vars.PORT }} - SUPABASE_URI: ${{ secrets.SUPABASE_URI }} - RUN_MIGRATIONS: ${{ vars.RUN_MIGRATIONS }} - SECRET_KEY: ${{ secrets.SECRET_KEY }} - run: | - if ! go build -tags netgo -ldflags '-s -w' -o app; then - echo "Build failed. Please check the logs." - exit 1 - fi - - - name: Upload Build Artifact - uses: actions/upload-artifact@v4 - with: - name: backend-app - path: app