|
| 1 | +# Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: Trigger MBridge Tests |
| 5 | +# Remote testing of MBridge from MCore |
| 6 | +# Triggers MBridge CI tests with current MCore commit to verify backward compatibility |
| 7 | + |
| 8 | +on: |
| 9 | + # Manual trigger only |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + mbridge_ref: |
| 13 | + description: 'MBridge branch/ref to trigger' |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + default: 'main' |
| 17 | + run_cicd_main: |
| 18 | + description: 'Run cicd-main.yml (full CI/CD)' |
| 19 | + required: false |
| 20 | + type: boolean |
| 21 | + default: true |
| 22 | + run_install_test: |
| 23 | + description: 'Run install-test.yml (quick install check)' |
| 24 | + required: false |
| 25 | + type: boolean |
| 26 | + default: true |
| 27 | + test_suite: |
| 28 | + description: 'Test suite to run (for cicd-main)' |
| 29 | + required: false |
| 30 | + type: choice |
| 31 | + options: |
| 32 | + - 'all' |
| 33 | + - 'unit-only' |
| 34 | + - 'functional-only' |
| 35 | + default: 'all' |
| 36 | + |
| 37 | +jobs: |
| 38 | + # First job: Get MCore commit info (shared by all matrix jobs) |
| 39 | + get-mcore-info: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + outputs: |
| 42 | + sha: ${{ steps.mcore_info.outputs.sha }} |
| 43 | + short_sha: ${{ steps.mcore_info.outputs.short_sha }} |
| 44 | + branch: ${{ steps.mcore_info.outputs.branch }} |
| 45 | + repo_url: ${{ steps.mcore_info.outputs.repo_url }} |
| 46 | + steps: |
| 47 | + - name: Checkout MCore |
| 48 | + uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + fetch-depth: 0 |
| 51 | + |
| 52 | + - name: Get MCore commit info |
| 53 | + id: mcore_info |
| 54 | + run: | |
| 55 | + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 56 | + echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 57 | + echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT |
| 58 | + |
| 59 | + # Get repo URL from origin remote, fallback to constructing from github context |
| 60 | + REPO_URL=$(git remote get-url origin 2>/dev/null || echo "${{ github.server_url }}/${{ github.repository }}.git") |
| 61 | + echo "repo_url=${REPO_URL}" >> $GITHUB_OUTPUT |
| 62 | +
|
| 63 | + echo "📦 MCore commit: $(git rev-parse --short HEAD)" |
| 64 | + echo "🌿 Branch: ${GITHUB_REF#refs/heads/}" |
| 65 | + echo "📍 Repo: ${REPO_URL}" |
| 66 | +
|
| 67 | + # Matrix job: Trigger and monitor MBridge workflows in parallel |
| 68 | + trigger-and-monitor: |
| 69 | + needs: [get-mcore-info] |
| 70 | + runs-on: ubuntu-latest |
| 71 | + continue-on-error: true # Don't fail workflow if monitoring times out |
| 72 | + strategy: |
| 73 | + fail-fast: false # Continue other matrix jobs even if one fails |
| 74 | + matrix: |
| 75 | + include: |
| 76 | + - workflow: install-test.yml |
| 77 | + name: Install Test |
| 78 | + - workflow: cicd-main.yml |
| 79 | + name: CI/CD Main |
| 80 | + |
| 81 | + name: ${{ matrix.name }} |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Check if workflow should run |
| 85 | + id: should_run |
| 86 | + run: | |
| 87 | + if [[ "${{ matrix.workflow }}" == "install-test.yml" && "${{ inputs.run_install_test }}" == "true" ]]; then |
| 88 | + echo "run=true" >> $GITHUB_OUTPUT |
| 89 | + elif [[ "${{ matrix.workflow }}" == "cicd-main.yml" && "${{ inputs.run_cicd_main }}" == "true" ]]; then |
| 90 | + echo "run=true" >> $GITHUB_OUTPUT |
| 91 | + else |
| 92 | + echo "run=false" >> $GITHUB_OUTPUT |
| 93 | + echo "⏭️ Skipping ${{ matrix.workflow }} (not enabled)" |
| 94 | + fi |
| 95 | + |
| 96 | + - name: Trigger ${{ matrix.workflow }} |
| 97 | + if: steps.should_run.outputs.run == 'true' |
| 98 | + id: trigger |
| 99 | + env: |
| 100 | + GH_TOKEN: ${{ secrets.PAT }} |
| 101 | + run: | |
| 102 | + echo "🚀 Triggering ${{ matrix.workflow }} | MCore: ${{ needs.get-mcore-info.outputs.short_sha }} | MBridge: ${{ inputs.mbridge_ref }}" |
| 103 | + |
| 104 | + gh workflow run ${{ matrix.workflow }} \ |
| 105 | + --repo NVIDIA-NeMo/Megatron-Bridge --ref ${{ inputs.mbridge_ref }} \ |
| 106 | + --field mcore_commit=${{ needs.get-mcore-info.outputs.sha }} \ |
| 107 | + --field mcore_branch=${{ needs.get-mcore-info.outputs.branch }} \ |
| 108 | + --field mcore_repo=${{ needs.get-mcore-info.outputs.repo_url }} \ |
| 109 | + --field test_suite=${{ inputs.test_suite }} \ |
| 110 | + --field triggered_by=mcore-ci |
| 111 | + |
| 112 | + - name: Get run ID |
| 113 | + if: steps.should_run.outputs.run == 'true' |
| 114 | + id: get_run_id |
| 115 | + env: |
| 116 | + GH_TOKEN: ${{ secrets.PAT }} |
| 117 | + run: | |
| 118 | + sleep 10 # Wait for run to appear |
| 119 | + RUN_ID=$(gh run list \ |
| 120 | + --repo NVIDIA-NeMo/Megatron-Bridge \ |
| 121 | + --workflow=${{ matrix.workflow }} \ |
| 122 | + --limit 5 \ |
| 123 | + --json databaseId,createdAt \ |
| 124 | + --jq "sort_by(.createdAt) | reverse | .[0] | .databaseId") |
| 125 | + |
| 126 | + echo "run_id=${RUN_ID}" >> $GITHUB_OUTPUT |
| 127 | + echo "📋 Run ID: ${RUN_ID}" |
| 128 | + |
| 129 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 130 | + ## 🔄 ${{ matrix.name }} Triggered |
| 131 | + |
| 132 | + **MCore:** \`${{ needs.get-mcore-info.outputs.short_sha }}\` | **MBridge:** \`${{ inputs.mbridge_ref }}\` | **Suite:** \`${{ inputs.test_suite }}\` |
| 133 | + |
| 134 | + - 🔄 [${{ matrix.workflow }}](https://github.com/NVIDIA-NeMo/Megatron-Bridge/actions/runs/${RUN_ID}) - Running... |
| 135 | + - ⏳ Monitoring every 5 minutes until completion |
| 136 | + |
| 137 | + > **Note:** Tests run without approval when triggered from MCore |
| 138 | + EOF |
| 139 | + |
| 140 | + - name: Monitor workflow |
| 141 | + if: steps.should_run.outputs.run == 'true' |
| 142 | + id: monitor |
| 143 | + continue-on-error: true |
| 144 | + env: |
| 145 | + GH_TOKEN: ${{ secrets.PAT }} |
| 146 | + run: | |
| 147 | + RUN_ID="${{ steps.get_run_id.outputs.run_id }}" |
| 148 | + echo "📊 Monitoring ${{ matrix.workflow }} (Run ID: ${RUN_ID})" |
| 149 | + |
| 150 | + gh run watch ${RUN_ID} --repo NVIDIA-NeMo/Megatron-Bridge --exit-status |
| 151 | + |
| 152 | + CONCLUSION=$(gh run view ${RUN_ID} --repo NVIDIA-NeMo/Megatron-Bridge --json conclusion --jq -r .conclusion) |
| 153 | + echo "workflow_status=${CONCLUSION}" >> $GITHUB_ENV |
| 154 | + echo "✅ Completed: ${CONCLUSION}" |
| 155 | + |
| 156 | + - name: Report results |
| 157 | + if: always() && steps.should_run.outputs.run == 'true' |
| 158 | + run: | |
| 159 | + CONCLUSION="${{ env.workflow_status || 'unknown' }}" |
| 160 | + RUN_ID="${{ steps.get_run_id.outputs.run_id }}" |
| 161 | + |
| 162 | + case "$CONCLUSION" in |
| 163 | + "success") ICON="✅"; MSG="passed" ;; |
| 164 | + "failure") ICON="❌"; MSG="failed"; EXIT_CODE=1 ;; |
| 165 | + "cancelled") ICON="🚫"; MSG="cancelled"; EXIT_CODE=0 ;; |
| 166 | + *) ICON="⏳"; MSG="still running or timed out"; EXIT_CODE=0 ;; |
| 167 | + esac |
| 168 | + |
| 169 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 170 | + ## 📊 ${{ matrix.name }} Results |
| 171 | + |
| 172 | + ### ${ICON} ${{ matrix.workflow }} |
| 173 | + **Status:** \`${CONCLUSION}\` |
| 174 | + |
| 175 | + [View full results →](https://github.com/NVIDIA-NeMo/Megatron-Bridge/actions/runs/${RUN_ID}) |
| 176 | + |
| 177 | + --- |
| 178 | + *Triggered from MCore \`${{ needs.get-mcore-info.outputs.short_sha }}\`* |
| 179 | + EOF |
| 180 | + |
| 181 | + echo "${ICON} ${{ matrix.name }} ${MSG}" |
| 182 | + exit ${EXIT_CODE:-0} |
| 183 | +
|
0 commit comments