🔨 Update gha

This commit is contained in:
2025-12-14 01:24:24 +08:00
parent 24c756a9a8
commit ef219c336c

View File

@@ -1,103 +1,103 @@
name: Build and Push Microservices name: Build and Push Microservices
on: on:
push: push:
branches: branches:
- master - master
workflow_dispatch: workflow_dispatch:
jobs: jobs:
determine-changes: determine-changes:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
matrix: ${{ steps.changes.outputs.matrix }} matrix: ${{ steps.changes.outputs.matrix }}
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Get changed files - name: Get changed files
id: changed-files id: changed-files
run: | run: |
echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT
- name: Determine changed services - name: Determine changed services
id: changes id: changes
run: | run: |
files="${{ steps.changed-files.outputs.files }}" files="${{ steps.changed-files.outputs.files }}"
matrix="{\"include\":[]}" matrix="{\"include\":[]}"
services=("Sphere" "Pass" "Ring" "Drive" "Develop" "Gateway" "Insight" "Zone") services=("Sphere" "Pass" "Ring" "Drive" "Develop" "Insight" "Zone")
images=("sphere" "pass" "ring" "drive" "develop" "gateway" "insight" "zone") images=("sphere" "pass" "ring" "drive" "develop" "insight" "zone")
changed_services=() changed_services=()
for file in $files; do for file in $files; do
if [[ "$file" == DysonNetwork.Shared/* ]]; then if [[ "$file" == DysonNetwork.Shared/* ]]; then
changed_services=("${services[@]}") changed_services=("${services[@]}")
break break
fi fi
for i in "${!services[@]}"; do for i in "${!services[@]}"; do
if [[ "$file" == DysonNetwork.${services[$i]}/* ]]; then if [[ "$file" == DysonNetwork.${services[$i]}/* ]]; then
# check if service is already in changed_services # check if service is already in changed_services
if [[ ! " ${changed_services[@]} " =~ " ${services[$i]} " ]]; then if [[ ! " ${changed_services[@]} " =~ " ${services[$i]} " ]]; then
changed_services+=("${services[$i]}") changed_services+=("${services[$i]}")
fi fi
fi fi
done done
done done
if [ ${#changed_services[@]} -gt 0 ]; then if [ ${#changed_services[@]} -gt 0 ]; then
json_objects="" json_objects=""
for service in "${changed_services[@]}"; do for service in "${changed_services[@]}"; do
for i in "${!services[@]}"; do for i in "${!services[@]}"; do
if [[ "${services[$i]}" == "$service" ]]; then if [[ "${services[$i]}" == "$service" ]]; then
image="${images[$i]}" image="${images[$i]}"
break break
fi fi
done done
json_objects+="{\"service\":\"$service\",\"image\":\"$image\"}," json_objects+="{\"service\":\"$service\",\"image\":\"$image\"},"
done done
matrix="{\"include\":[${json_objects%,}]}" matrix="{\"include\":[${json_objects%,}]}"
fi fi
echo "matrix=$matrix" >> $GITHUB_OUTPUT echo "matrix=$matrix" >> $GITHUB_OUTPUT
build-and-push: build-and-push:
needs: determine-changes needs: determine-changes
if: ${{ needs.determine-changes.outputs.matrix != '{"include":[]}' }} if: ${{ needs.determine-changes.outputs.matrix != '{"include":[]}' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
packages: write packages: write
strategy: strategy:
matrix: ${{ fromJson(needs.determine-changes.outputs.matrix) }} matrix: ${{ fromJson(needs.determine-changes.outputs.matrix) }}
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Setup NBGV - name: Setup NBGV
uses: dotnet/nbgv@master uses: dotnet/nbgv@master
id: nbgv id: nbgv
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry - name: Log in to GitHub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image for ${{ matrix.service }} - name: Build and push Docker image for ${{ matrix.service }}
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
file: DysonNetwork.${{ matrix.service }}/Dockerfile file: DysonNetwork.${{ matrix.service }}/Dockerfile
push: true push: true
tags: | tags: |
ghcr.io/${{ vars.PACKAGE_OWNER }}/dyson-${{ matrix.image }}:${{ steps.nbgv.outputs.SimpleVersion }} ghcr.io/${{ vars.PACKAGE_OWNER }}/dyson-${{ matrix.image }}:${{ steps.nbgv.outputs.SimpleVersion }}
ghcr.io/${{ vars.PACKAGE_OWNER }}/dyson-${{ matrix.image }}:latest ghcr.io/${{ vars.PACKAGE_OWNER }}/dyson-${{ matrix.image }}:latest
platforms: linux/amd64 platforms: linux/amd64