Skip to content

Commit

Permalink
feat: auto build
Browse files Browse the repository at this point in the history
  • Loading branch information
tithanayut committed Feb 4, 2025
1 parent fb0aa96 commit 3509a29
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
45 changes: 37 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
name: Build

on:
workflow_dispatch:
inputs:
APP_DIR:
description: "Directory of the service to build"
required: true
type: string
push:
branches:
- main

jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Filter changed paths
id: filter
uses: dorny/paths-filter@v3
with:
list-files: json
filters: |
account: "account/server/**"
auth: "auth/server/**"
- name: Generate matrix dynamically
id: set-matrix
run: |
matrix=()
for service in $(jq -r 'keys[]' <<< '${{ toJson(steps.filter.outputs) }}'); do
if [[ "${{ steps.filter.outputs[service] }}" == "true" ]]; then
matrix+=("\"$service\"")
fi
done
echo "matrix={\"APP_DIR\":[$(IFS=,; echo "${matrix[*]}")]}" >> $GITHUB_ENV
build:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.matrix != '{}' }}
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
permissions:
contents: read
packages: write
Expand All @@ -34,8 +63,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
41 changes: 41 additions & 0 deletions .github/workflows/manual-build.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3509a29

Please sign in to comment.