|
| 1 | +name: "BioNeMo Recipes CI" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "pull-request/[0-9]+" |
| 7 | + - "dependabot/**" |
| 8 | + merge_group: |
| 9 | + types: [checks_requested] |
| 10 | + schedule: |
| 11 | + - cron: "0 9 * * *" # Runs at 9 AM UTC daily (2 AM MST) |
| 12 | + |
| 13 | +defaults: |
| 14 | + run: |
| 15 | + shell: bash -x -e -u -o pipefail {0} |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + changed-dirs: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + any_changed: ${{ steps.changed-files.outputs.any_changed }} |
| 26 | + all_changed_files: ${{ steps.changed-files.outputs.all_changed_files }} |
| 27 | + dirs: ${{ steps.set-dirs.outputs.dirs }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - id: get-pr-info |
| 31 | + if: ${{ startsWith(github.ref_name, 'pull-request/') }} |
| 32 | + uses: nv-gha-runners/get-pr-info@main |
| 33 | + |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - name: Get changed files |
| 39 | + id: changed-files |
| 40 | + uses: step-security/changed-files@v46 |
| 41 | + with: |
| 42 | + json: true |
| 43 | + matrix: true |
| 44 | + base_sha: main |
| 45 | + dir_names: true |
| 46 | + dir_names_max_depth: 2 |
| 47 | + files: | |
| 48 | + models/** |
| 49 | + recipes/** |
| 50 | +
|
| 51 | + - id: set-dirs |
| 52 | + name: Determine which directories to run |
| 53 | + env: |
| 54 | + EVENT_NAME: ${{ github.event_name }} |
| 55 | + PR_INFO: ${{ steps.get-pr-info.outputs.pr-info }} |
| 56 | + CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 57 | + run: | |
| 58 | + # Get all recipe and model directories |
| 59 | + ALL_DIRS=$(ls -d recipes/*/ models/*/ 2>/dev/null | jq -R -s -c 'split("\n")[:-1] | map(rtrimstr("/"))') |
| 60 | +
|
| 61 | + # Determine which directories to run: all for schedule, filtered for other events |
| 62 | + if [[ "$EVENT_NAME" == "schedule" ]]; then |
| 63 | + DIRS=$(echo "$ALL_DIRS") |
| 64 | + else |
| 65 | + # Check if INCLUDE_ALL_RECIPES label is present |
| 66 | + HAS_INCLUDE_ALL_LABEL=false |
| 67 | + if [[ "$PR_INFO" != "null" && "$PR_INFO" != "" ]]; then |
| 68 | + if echo "$PR_INFO" | jq -e '.labels[]? | select(.name == "INCLUDE_ALL_RECIPES")' > /dev/null 2>&1; then |
| 69 | + HAS_INCLUDE_ALL_LABEL=true |
| 70 | + echo "Found INCLUDE_ALL_RECIPES label - running all directories" |
| 71 | + fi |
| 72 | + fi |
| 73 | +
|
| 74 | + if [[ "$HAS_INCLUDE_ALL_LABEL" == "true" ]]; then |
| 75 | + DIRS=$(echo "$ALL_DIRS") |
| 76 | + else |
| 77 | + # Filter directories to only those that have changed files |
| 78 | + DIRS=$(echo "$ALL_DIRS" | jq -c --argjson changed "$CHANGED_FILES" ' |
| 79 | + map(select(. as $dir | $changed | index($dir) != null)) |
| 80 | + ') |
| 81 | + fi |
| 82 | + fi |
| 83 | +
|
| 84 | + # Assign Docker images to the selected directories |
| 85 | + # Currently, AMPLIFY is the only folder that needs a custom base image, since we have to support both TE and |
| 86 | + # xformers-based models for golden value testing. The rest of the models use the default pytorch image. |
| 87 | + DIRS_WITH_IMAGES=$(echo "$DIRS" | jq -c ' |
| 88 | + map({ |
| 89 | + dir: ., |
| 90 | + image: ( |
| 91 | + if . == "models/amplify" then |
| 92 | + "svcbionemo023/bionemo-framework:amplify-model-devcontainer-082025" |
| 93 | + else |
| 94 | + "nvcr.io/nvidia/pytorch:25.06-py3" |
| 95 | + end |
| 96 | + ) |
| 97 | + }) |
| 98 | + ') |
| 99 | + echo "dirs=$DIRS_WITH_IMAGES" >> $GITHUB_OUTPUT |
| 100 | + - name: Show output |
| 101 | + run: | |
| 102 | + echo '${{ toJSON(steps.changed-files.outputs) }}' |
| 103 | + echo '${{ toJSON(steps.set-dirs.outputs) }}' |
| 104 | + shell: bash |
| 105 | + |
| 106 | + unit-tests: |
| 107 | + needs: changed-dirs |
| 108 | + runs-on: linux-amd64-gpu-l4-latest-1 |
| 109 | + if: ${{ needs.changed-dirs.outputs.dirs != '[]' }} |
| 110 | + container: |
| 111 | + image: ${{ matrix.recipe.image }} |
| 112 | + strategy: |
| 113 | + matrix: |
| 114 | + recipe: ${{ fromJson(needs.changed-dirs.outputs.dirs) }} |
| 115 | + fail-fast: false |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Setup proxy cache |
| 119 | + uses: nv-gha-runners/setup-proxy-cache@main |
| 120 | + - name: Checkout repository |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + sparse-checkout: "${{ matrix.recipe.dir }}" |
| 124 | + sparse-checkout-cone-mode: false |
| 125 | + |
| 126 | + - name: Install dependencies |
| 127 | + working-directory: ${{ matrix.recipe.dir }} |
| 128 | + # |
| 129 | + run: | |
| 130 | + if [ -f pyproject.toml ] || [ -f setup.py ]; then |
| 131 | + PIP_CONSTRAINT= pip install -e . |
| 132 | + echo "Installed ${{ matrix.recipe.dir }} as editable package" |
| 133 | + elif [ -f requirements.txt ]; then |
| 134 | + PIP_CONSTRAINT= pip install -r requirements.txt |
| 135 | + echo "Installed ${{ matrix.recipe.dir }} from requirements.txt" |
| 136 | + else |
| 137 | + echo "No pyproject.toml, setup.py, or requirements.txt found in ${{ matrix.recipe.dir }}" |
| 138 | + exit 1 |
| 139 | + fi |
| 140 | +
|
| 141 | + - name: Run tests |
| 142 | + working-directory: ${{ matrix.recipe.dir }} |
| 143 | + run: pytest -v . |
| 144 | + |
| 145 | + verify-recipe-tests: |
| 146 | + # This job checks the status of the unit-tests matrix and fails if any matrix job failed or was cancelled. |
| 147 | + # Use this job as the required check for PRs. |
| 148 | + needs: unit-tests |
| 149 | + runs-on: ubuntu-latest |
| 150 | + if: always() |
| 151 | + steps: |
| 152 | + - name: Check unit-tests matrix status |
| 153 | + run: | |
| 154 | + if [[ "${{ needs.unit-tests.result }}" == "failure" || "${{ needs.unit-tests.result }}" == "cancelled" ]]; then |
| 155 | + echo "Some unit-tests matrix jobs have failed or been cancelled!" |
| 156 | + exit 1 |
| 157 | + else |
| 158 | + echo "All unit-tests matrix jobs have completed successfully or were skipped!" |
| 159 | + exit 0 |
| 160 | + fi |
0 commit comments