feat: expand memory coverage tests #28
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: Test and Build | |
| on: | |
| pull_request: | |
| # 运行所有分支的PR单元测试 | |
| push: | |
| branches: [ main, develop, master, release* ] | |
| tags: [ 'v*' ] | |
| workflow_dispatch: | |
| inputs: | |
| registry: | |
| description: 'Docker Registry URL' | |
| required: false | |
| default: 'registry.cn-hangzhou.aliyuncs.com' | |
| type: string | |
| image_name: | |
| description: 'Docker Image Name' | |
| required: false | |
| default: 'vertexflow/vertex' | |
| type: string | |
| push_to_registry: | |
| description: 'Push to registry (false for PR builds)' | |
| required: false | |
| default: true | |
| type: boolean | |
| # 工作流级别权限配置 | |
| permissions: | |
| contents: read | |
| packages: write | |
| security-events: write | |
| actions: read | |
| env: | |
| REGISTRY: ${{ github.event.inputs.registry || vars.DOCKER_REGISTRY || 'registry.cn-hangzhou.aliyuncs.com' }} | |
| IMAGE_NAME: ${{ github.event.inputs.image_name || secrets.DOCKER_IMAGE_NAME || 'vertex' }} | |
| PUSH_TO_REGISTRY: ${{ github.event.inputs.push_to_registry != 'false' }} | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.9, 3.12] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| # 安装项目依赖 | |
| pip install -r requirements.txt | |
| pip install -e . | |
| # 安装测试依赖 | |
| pip install pytest pytest-cov pytest-asyncio | |
| - name: Run Unit Tests | |
| run: | | |
| echo "🧪 运行单元测试..." | |
| # 检查测试脚本是否存在 | |
| if [ -f "scripts/run_tests.sh" ]; then | |
| chmod +x scripts/run_tests.sh | |
| ./scripts/run_tests.sh | |
| else | |
| echo "⚠️ 测试脚本不存在,使用默认测试命令" | |
| if [ -d "vertex_flow/tests" ]; then | |
| python -m pytest vertex_flow/tests/ -v --tb=short --cov=vertex_flow --cov-report=term-missing | |
| else | |
| echo "💡 未找到测试目录,跳过单元测试" | |
| fi | |
| fi | |
| - name: Upload coverage reports | |
| if: matrix.python-version == '3.12' | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| fail_ci_if_error: false | |
| docker-build: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| # 只在release分支或tag时构建镜像 | |
| if: > | |
| (github.event_name == 'push' && | |
| (contains(github.ref, 'refs/heads/release') || | |
| contains(github.ref, 'refs/tags/'))) || | |
| github.event_name == 'workflow_dispatch' | |
| permissions: | |
| contents: read | |
| packages: write | |
| actions: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # 获取完整历史用于标签生成 | |
| - name: Debug environment variables | |
| run: | | |
| echo "=== Environment Variables Debug ===" | |
| echo "REGISTRY: ${{ env.REGISTRY }}" | |
| echo "IMAGE_NAME: ${{ env.IMAGE_NAME }}" | |
| echo "PUSH_TO_REGISTRY: ${{ env.PUSH_TO_REGISTRY }}" | |
| echo "" | |
| echo "=== GitHub Context ===" | |
| echo "Event name: ${{ github.event_name }}" | |
| echo "Ref: ${{ github.ref }}" | |
| echo "Base ref: ${{ github.base_ref }}" | |
| echo "Manual input registry: ${{ github.event.inputs.registry }}" | |
| echo "Manual input image_name: ${{ github.event.inputs.image_name }}" | |
| echo "Manual input push_to_registry: ${{ github.event.inputs.push_to_registry }}" | |
| echo "" | |
| echo "=== Repository Variables ===" | |
| echo "vars.DOCKER_REGISTRY: ${{ vars.DOCKER_REGISTRY }}" | |
| echo "" | |
| echo "=== Repository Secrets ===" | |
| echo "secrets.DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_IMAGE_NAME }}" | |
| echo "secrets.ACR_USERNAME: ${{ secrets.ACR_USERNAME }}" | |
| echo "secrets.ACR_PASSWORD: [HIDDEN]" | |
| echo "==================================" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Generate image tags | |
| id: tags | |
| run: | | |
| # 获取Git信息 | |
| BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
| COMMIT_ID=${GITHUB_SHA::7} | |
| TAG_NAME="" | |
| # 如果是标签推送,获取标签名 | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| TAG_NAME=${GITHUB_REF#refs/tags/} | |
| fi | |
| # 生成标签数组 | |
| declare -a TAGS_ARRAY=() | |
| # 如果有标签,使用tag名作为标签 | |
| if [ -n "$TAG_NAME" ]; then | |
| # 清理tag名称,确保符合Docker标签规范 | |
| CLEAN_TAG=$(echo "$TAG_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//') | |
| TAGS_ARRAY+=("$REGISTRY/$IMAGE_NAME:$CLEAN_TAG") | |
| TAGS_ARRAY+=("$REGISTRY/$IMAGE_NAME:latest") | |
| else | |
| # release分支使用分支名和commit id | |
| CLEAN_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//') | |
| TAGS_ARRAY+=("$REGISTRY/$IMAGE_NAME:$CLEAN_BRANCH") | |
| TAGS_ARRAY+=("$REGISTRY/$IMAGE_NAME:$COMMIT_ID") | |
| # 如果是主release分支,也标记为latest | |
| if [[ "$BRANCH_NAME" == "release" || "$BRANCH_NAME" =~ ^release/main$ ]]; then | |
| TAGS_ARRAY+=("$REGISTRY/$IMAGE_NAME:latest") | |
| fi | |
| fi | |
| # 将数组转换为逗号分隔的字符串(docker/build-push-action期望的格式) | |
| TAGS_STRING=$(IFS=','; echo "${TAGS_ARRAY[*]}") | |
| echo "tags=$TAGS_STRING" >> $GITHUB_OUTPUT | |
| echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| echo "commit=$COMMIT_ID" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT | |
| echo "Generated tags: $TAGS_STRING" | |
| echo "Branch: $BRANCH_NAME" | |
| echo "Commit: $COMMIT_ID" | |
| echo "Tag: $TAG_NAME" | |
| echo "Tags array: ${TAGS_ARRAY[@]}" | |
| - name: Login to Docker Registry | |
| if: github.event_name != 'pull_request' && env.PUSH_TO_REGISTRY == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.ACR_USERNAME }} | |
| password: ${{ secrets.ACR_PASSWORD }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=sha,prefix={{branch}}- | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./docker/Dockerfile | |
| push: ${{ env.PUSH_TO_REGISTRY == 'true' && github.event_name != 'pull_request' }} | |
| tags: ${{ steps.tags.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Build summary | |
| run: | | |
| echo "## Docker Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Image Name:** ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Branch:** ${{ steps.tags.outputs.branch }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit:** ${{ steps.tags.outputs.commit }}" >> $GITHUB_STEP_SUMMARY | |
| if [ -n "${{ steps.tags.outputs.tag }}" ]; then | |
| echo "- **Tag:** ${{ steps.tags.outputs.tag }}" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Generated Tags:**" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.tags.outputs.tags }}" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ env.PUSH_TO_REGISTRY }}" == "true" ] && [ "${{ github.event_name }}" != "pull_request" ]; then | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ Images pushed to ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "🔍 Build completed (no push)" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| test-summary: | |
| runs-on: ubuntu-latest | |
| needs: [test, docker-build] | |
| if: always() | |
| steps: | |
| - name: Test Results Summary | |
| run: | | |
| echo "## Test and Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.test.result }}" == "success" ]; then | |
| echo "✅ **Unit Tests:** Passed" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ **Unit Tests:** Failed" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [ "${{ needs.docker-build.result }}" == "success" ]; then | |
| echo "✅ **Docker Build:** Completed" >> $GITHUB_STEP_SUMMARY | |
| elif [ "${{ needs.docker-build.result }}" == "skipped" ]; then | |
| echo "⏭️ **Docker Build:** Skipped (not release branch/tag)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ **Docker Build:** Failed" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.test.result }}" == "success" ] && | |
| ([ "${{ needs.docker-build.result }}" == "success" ] || [ "${{ needs.docker-build.result }}" == "skipped" ]); then | |
| echo "🎉 **Overall Status:** Success" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "💥 **Overall Status:** Failed" >> $GITHUB_STEP_SUMMARY | |
| fi |