From 60059868d4d3fb498e968d2c10be1c59419231bb Mon Sep 17 00:00:00 2001 From: Thanayut T Date: Tue, 4 Feb 2025 15:48:32 +0700 Subject: [PATCH] feat: auto build --- .github/workflows/build.yaml | 36 +++++++++++++++++++------ .github/workflows/manual-build.yaml | 41 +++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/manual-build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 52d3251..caaefd9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,16 +1,36 @@ name: Build on: - workflow_dispatch: - inputs: - APP_DIR: - description: "Directory of the service to build" - required: true - type: string + push: + branches: + - main jobs: + changes: + runs-on: ubuntu-latest + outputs: + apps: ${{ steps.filter.outputs.changes }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Filter changed paths + uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + account/server: + - 'account/server/**' + auth/server: + - 'auth/server/**' + build: + needs: changes runs-on: ubuntu-latest + if: ${{ needs.changes.outputs.apps != '' && toJson(fromJson(needs.changes.outputs.apps)) != '[]' }} + strategy: + matrix: + APP_DIR: ${{ fromJSON(needs.changes.outputs.apps) }} permissions: contents: read packages: write @@ -34,8 +54,8 @@ jobs: context: . file: ./docker/Dockerfile push: true - tags: ghcr.io/noah-platform/noah/${{ github.event.inputs.APP_DIR }}:latest + tags: ghcr.io/noah-platform/noah/${{ matrix.APP_DIR }}:latest build-args: | - APP_DIR=${{ github.event.inputs.APP_DIR }} + APP_DIR=${{ matrix.APP_DIR }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/manual-build.yaml b/.github/workflows/manual-build.yaml new file mode 100644 index 0000000..fef5d8f --- /dev/null +++ b/.github/workflows/manual-build.yaml @@ -0,0 +1,41 @@ +name: Manual Build + +on: + workflow_dispatch: + inputs: + APP_DIR: + description: "Directory of the service to build" + required: true + type: string + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to the Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Docker Image + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/Dockerfile + push: true + tags: ghcr.io/noah-platform/noah/${{ github.event.inputs.APP_DIR }}:latest + build-args: | + APP_DIR=${{ github.event.inputs.APP_DIR }} + cache-from: type=gha + cache-to: type=gha,mode=max