fix: 发帖死循环 #18
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: App and API Images | |
| on: | |
| push: | |
| tags: ["v*"] | |
| env: | |
| HUAWEI_REGISTRY: swr.cn-east-3.myhuaweicloud.com | |
| HUAWEI_NAMESPACE: koala-qa | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| service: | |
| - name: api | |
| dockerfile: backend/Dockerfile | |
| context: backend | |
| - name: app | |
| dockerfile: ui/Dockerfile | |
| context: ui | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Extract tag name and build time | |
| id: extract_tag | |
| run: | | |
| echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| echo "build_time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Huawei Cloud Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.HUAWEI_REGISTRY }} | |
| username: ${{ secrets.HUAWEI_CLOUD_USERNAME }} | |
| password: ${{ secrets.HUAWEI_CLOUD_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ matrix.service.context }} | |
| file: ${{ matrix.service.dockerfile }} | |
| push: true | |
| tags: ${{ env.HUAWEI_REGISTRY }}/${{ env.HUAWEI_NAMESPACE }}/${{ matrix.service.name }}:${{ steps.extract_tag.outputs.tag }} | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false | |
| sbom: false | |
| build-args: | | |
| VERSION=${{ steps.extract_tag.outputs.tag }} | |
| COMMIT_HASH=${{ github.sha }} | |
| BUILD_TIME=${{ steps.extract_tag.outputs.build_time }} | |
| HTTP_PROXY=${{ secrets.HTTP_PROXY }} | |
| HTTPS_PROXY=${{ secrets.HTTPS_PROXY }} | |
| update-compose: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| if: needs.build-and-push.result == 'success' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Extract tag name | |
| id: extract_tag | |
| run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Setup git and checkout main branch | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git checkout main | |
| git pull origin main | |
| - name: Update docker-compose.yml | |
| run: | | |
| sed -i "s|image: swr.cn-east-3.myhuaweicloud.com/koala-qa/api:.*|image: swr.cn-east-3.myhuaweicloud.com/koala-qa/api:${{ steps.extract_tag.outputs.tag }}|g" docker-compose.yml | |
| sed -i "s|image: swr.cn-east-3.myhuaweicloud.com/koala-qa/app:.*|image: swr.cn-east-3.myhuaweicloud.com/koala-qa/app:${{ steps.extract_tag.outputs.tag }}|g" docker-compose.yml | |
| echo "📝 Updated docker-compose.yml:" | |
| git diff docker-compose.yml | |
| - name: Commit and push changes | |
| run: | | |
| if git diff --quiet docker-compose.yml; then | |
| echo "🔄 No changes needed in docker-compose.yml" | |
| else | |
| git add docker-compose.yml | |
| git commit -m "🚀 Auto-update docker-compose.yml with tag ${{ steps.extract_tag.outputs.tag }}" | |
| echo "🔄 Rebasing with latest main branch..." | |
| git fetch origin main | |
| git rebase origin/main | |
| echo "🚀 Pushing changes to main branch..." | |
| git push origin main | |
| echo "✅ Successfully updated docker-compose.yml with new image tags" | |
| fi | |
| notify: | |
| needs: [build-and-push, update-compose] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Extract tag name | |
| id: extract_tag | |
| run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Build result notification | |
| run: | | |
| if [ "${{ needs.build-and-push.result }}" == "success" ]; then | |
| echo "✅ App and UI images built successfully!" | |
| echo "🚀 Images pushed to Huawei Cloud: ${{ env.HUAWEI_REGISTRY }}/${{ env.HUAWEI_NAMESPACE }}" | |
| echo "📦 Tag: ${{ steps.extract_tag.outputs.tag }}" | |
| if [ "${{ needs.update-compose.result }}" == "success" ]; then | |
| echo "🔄 docker-compose.yml updated successfully" | |
| else | |
| echo "⚠️ docker-compose.yml update failed, but images were built successfully" | |
| fi | |
| else | |
| echo "❌ App and UI image build failed, please check logs" | |
| exit 1 | |
| fi |