diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 22bc6b5..f982997 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: changes: runs-on: runner outputs: - matrix: ${{ steps.filter.outputs.matrix }} + build_list: ${{ steps.filter.outputs.build_list }} steps: - name: Checkout uses: https://git.ailuowan.com/deploy/checkout@v4 @@ -28,13 +28,6 @@ jobs: 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$' ;; @@ -56,67 +49,85 @@ jobs: echo "$changed" fi - matrix="[" - first=true + build_list="" for svc in $SERVICES; do - build=false + should_build=false if [ "$build_all" = true ]; then - build=true + should_build=true elif echo "$changed" | grep -qE "$(pattern_for "$svc")"; then - build=true + should_build=true fi - df=$(dockerfile_for "$svc") - if [ "$first" = true ]; then - first=false + if [ "$should_build" = true ]; then + if [ -n "$build_list" ]; then + build_list="$build_list,$svc" + else + build_list="$svc" + fi + echo "$svc=yes" else - matrix="$matrix," + echo "$svc=no" fi - # use yes/no to avoid true/false being coerced to boolean in matrix if - if [ "$build" = true ]; then - flag=yes - else - flag=no - fi - matrix="$matrix{\"name\":\"$svc\",\"dockerfile\":\"$df\",\"build\":\"$flag\"}" - echo "$svc=$flag" done - matrix="$matrix]" - echo "matrix=$matrix" >> "$GITHUB_OUTPUT" - echo "matrix=$matrix" + echo "build_list=$build_list" >> "$GITHUB_OUTPUT" + echo "build_list=$build_list" docker: needs: changes runs-on: runner - name: ${{ matrix.name }} strategy: fail-fast: false matrix: - include: ${{ fromJSON(needs.changes.outputs.matrix) }} + include: + - name: bff + dockerfile: bff/Dockerfile + - name: product + dockerfile: services/product/Dockerfile + - name: admin + dockerfile: services/admin/Dockerfile + - name: user + dockerfile: services/user/Dockerfile + - name: ad + dockerfile: services/ad/Dockerfile + - name: chore + dockerfile: services/chore/Dockerfile + - name: express + dockerfile: services/express/Dockerfile + - name: sale + dockerfile: services/sale/Dockerfile + - name: wecom + dockerfile: services/wecom/Dockerfile env: + BUILD_LIST: ${{ needs.changes.outputs.build_list }} NAME: lone/${{ matrix.name }} steps: - - name: Skip - if: matrix.build != 'yes' - run: echo "skip ${{ matrix.name }} (no changes)" + - name: Check changes + id: check + run: | + if echo ",$BUILD_LIST," | grep -q ",${{ matrix.name }},"; then + echo "build=yes" >> "$GITHUB_OUTPUT" + else + echo "build=no" >> "$GITHUB_OUTPUT" + echo "skip ${{ matrix.name }} (no changes)" + fi - name: Checkout - if: matrix.build == 'yes' + if: steps.check.outputs.build == 'yes' uses: https://git.ailuowan.com/deploy/checkout@v4 - name: Login Registry - if: matrix.build == 'yes' + if: steps.check.outputs.build == 'yes' run: | echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ vars.REGISTRY }} -u "${{ vars.REGISTRY_USERNAME }}" --password-stdin - name: Docker build - if: matrix.build == 'yes' + if: steps.check.outputs.build == 'yes' run: | docker buildx use default docker buildx build --builder default --load -f "${{ matrix.dockerfile }}" -t "${{ vars.REGISTRY }}/$NAME:latest" . - name: Docker push - if: matrix.build == 'yes' + if: steps.check.outputs.build == 'yes' run: | docker push ${{ vars.REGISTRY }}/$NAME:latest diff --git a/services/wecom/internal/logic/helper.go b/services/wecom/internal/logic/helper.go index 1a2fbc9..b64d07a 100644 --- a/services/wecom/internal/logic/helper.go +++ b/services/wecom/internal/logic/helper.go @@ -20,7 +20,6 @@ func statusEnable(status uint8) int { return utils.NumberOne } -// build func typeText(t uint8) string { switch t { case dao.UserTypeAdmin: