Files
lone-services/.gitea/workflows/ci.yml
T
2026-08-31 11:27:18 +08:00

116 lines
3.1 KiB
YAML

name: CI
on:
push:
branches:
- develop
paths:
- "bff/**"
- "services/**"
- "rpc/**"
- "pkg/**"
- ".gitea/workflows/ci.yml"
workflow_dispatch:
jobs:
changes:
runs-on: runner
outputs:
matrix: ${{ steps.filter.outputs.matrix }}
steps:
- name: Checkout
uses: https://git.ailuowan.com/deploy/checkout@v4
with:
fetch-depth: 0
- name: Detect changes
id: filter
run: |
SERVICES="bff product admin user ad chore express sale wecom"
dockerfile_for() {
case "$1" in
bff) echo "bff/Dockerfile" ;;
*) echo "services/$1/Dockerfile" ;;
esac
}
pattern_for() {
case "$1" in
bff) echo '^(bff|pkg|rpc)/|^\.gitea/workflows/ci\.yml$' ;;
*) echo "^(services/$1|rpc/$1|pkg)/|^\\.gitea/workflows/ci\\.yml$" ;;
esac
}
build_all=false
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
build_all=true
else
before="${{ github.event.before }}"
if [ -z "$before" ] || [ "$before" = "0000000000000000000000000000000000000000" ]; then
changed=$(git ls-files)
else
changed=$(git diff --name-only "$before" "${{ github.sha }}")
fi
echo "changed files:"
echo "$changed"
fi
matrix="["
first=true
for svc in $SERVICES; do
should_build=false
if [ "$build_all" = true ]; then
should_build=true
elif echo "$changed" | grep -qE "$(pattern_for "$svc")"; then
should_build=true
fi
if [ "$should_build" = true ]; then
df=$(dockerfile_for "$svc")
if [ "$first" = true ]; then
first=false
else
matrix="$matrix,"
fi
matrix="$matrix{\"name\":\"$svc\",\"dockerfile\":\"$df\"}"
echo "$svc=true"
else
echo "$svc=false"
fi
done
matrix="$matrix]"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
echo "matrix=$matrix"
docker:
needs: changes
if: needs.changes.outputs.matrix != '[]'
runs-on: runner
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.changes.outputs.matrix) }}
env:
NAME: lone/${{ matrix.name }}
steps:
- name: Checkout
uses: https://git.ailuowan.com/deploy/checkout@v4
- name: Login Registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ vars.REGISTRY }} -u "${{ vars.REGISTRY_USERNAME }}" --password-stdin
- name: Docker build
run: |
docker buildx use default
docker buildx build --builder default --load \
-f ${{ matrix.dockerfile }} \
-t ${{ vars.REGISTRY }}/$NAME:latest \
.
- name: Docker push
run: |
docker push ${{ vars.REGISTRY }}/$NAME:latest