|
| 1 | +# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +name: ~test template |
| 15 | + |
| 16 | +on: |
| 17 | + workflow_call: |
| 18 | + inputs: |
| 19 | + RUNNER: |
| 20 | + type: string |
| 21 | + description: Runner to use for test |
| 22 | + required: true |
| 23 | + TIMEOUT: |
| 24 | + type: number |
| 25 | + description: Max runtime of test in minutes |
| 26 | + required: false |
| 27 | + default: 10 |
| 28 | + SCRIPT: |
| 29 | + type: string |
| 30 | + description: Test script to execute |
| 31 | + required: true |
| 32 | + AFTER_SCRIPT: |
| 33 | + type: string |
| 34 | + description: Script to run after main test |
| 35 | + required: false |
| 36 | + default: ":" |
| 37 | + IS_OPTIONAL: |
| 38 | + type: boolean |
| 39 | + description: Failure will cancel all other tests if set to true |
| 40 | + required: false |
| 41 | + default: false |
| 42 | + outputs: |
| 43 | + conclusion: |
| 44 | + description: Conclusion of main test step |
| 45 | + value: ${{ jobs.main.outputs.conclusion }} |
| 46 | + log: |
| 47 | + description: Last 2000 characters of the test step's log |
| 48 | + value: ${{ jobs.main.outputs.log }} |
| 49 | +jobs: |
| 50 | + |
| 51 | + main: |
| 52 | + runs-on: ${{ inputs.RUNNER }} |
| 53 | + outputs: |
| 54 | + conclusion: ${{ steps.main.conclusion }} |
| 55 | + log: ${{ steps.main.outputs.log }} |
| 56 | + steps: |
| 57 | + - name: Docker system cleanup |
| 58 | + run: | |
| 59 | + docker system prune -a --filter "until=48h" --force || true |
| 60 | +
|
| 61 | + - name: Docker pull image |
| 62 | + run: | |
| 63 | + docker pull nemoci.azurecr.io/nemo__placeholder_container:${{ github.run_id }} |
| 64 | +
|
| 65 | + - name: Start container |
| 66 | + run: | |
| 67 | + docker run --rm -d --name nemo_container_${{ github.run_id }} --runtime=nvidia --gpus all --shm-size=64g \ |
| 68 | + --env TRANSFORMERS_OFFLINE=0 \ |
| 69 | + --env HYDRA_FULL_ERROR=1 \ |
| 70 | + --env HF_HOME=/home/TestData/_placeholder/hf_home \ |
| 71 | + --env _PLACEHOLDER_CI_DIR=/home/TestData/_placeholder \ |
| 72 | + --env _PLACEHOLDER_REPO_DIR=/opt/NeMo-_Placeholder \ |
| 73 | + --volume /mnt/datadrive/TestData/_placeholder/checkpoints:/home/TestData/_placeholder/checkpoints:ro \ |
| 74 | + --volume /mnt/datadrive/TestData/_placeholder/hf_home/hub:/home/TestData/_placeholder/hf_home/hub:ro \ |
| 75 | + nemoci.azurecr.io/nemo__placeholder_container:${{ github.run_id }} \ |
| 76 | + bash -c "sleep $(( ${{ inputs.TIMEOUT }} * 60 + 60 ))" |
| 77 | + |
| 78 | + - id: main |
| 79 | + name: Run main script |
| 80 | + timeout-minutes: ${{ inputs.TIMEOUT }} |
| 81 | + run: | |
| 82 | + # Print the host driver for debugging |
| 83 | + nvidia-smi |
| 84 | + mkdir -p ${{ github.run_id }} |
| 85 | + cd ${{ github.run_id }}/ |
| 86 | +
|
| 87 | + set +e |
| 88 | + ( |
| 89 | + set -e |
| 90 | +
|
| 91 | + cmd=$(cat <<"RUN_TEST_EOF" |
| 92 | + nvidia-smi |
| 93 | + # Sanity check the driver/cuda combo |
| 94 | + cudaCheck |
| 95 | + # In case git commands need to be run inside _Placeholder |
| 96 | + git config --global --add safe.directory $_PLACHOLDER_REPO_DIR |
| 97 | + ${{ inputs.SCRIPT }} |
| 98 | + RUN_TEST_EOF |
| 99 | + ) |
| 100 | + docker exec nemo_container_${{ github.run_id }} bash -eux -o pipefail -c "$cmd" |
| 101 | + ) 2> >(tee err.log) |
| 102 | +
|
| 103 | + EXIT_CODE=$? |
| 104 | +
|
| 105 | + echo "log=$(tail -c 2000 err.log | base64 -w 0)" >> "$GITHUB_OUTPUT" |
| 106 | + |
| 107 | + exit $EXIT_CODE |
| 108 | +
|
| 109 | + - uses: "NVIDIA/NeMo/.github/actions/cancel-workflow@main" |
| 110 | + if: failure() && inputs.IS_OPTIONAL == false |
| 111 | + |
| 112 | + - name: after_script |
| 113 | + if: always() && inputs.AFTER_SCRIPT != ':' |
| 114 | + run: | |
| 115 | + cmd=$(cat <<"RUN_TEST_EOF" |
| 116 | + ${{ inputs.AFTER_SCRIPT }} |
| 117 | + RUN_TEST_EOF |
| 118 | + ) |
| 119 | + docker exec nemo_container_${{ github.run_id }} bash -eux -o pipefail -c "$cmd" |
| 120 | +
|
| 121 | + - name: Container shutdown |
| 122 | + if: always() |
| 123 | + run: | |
| 124 | + docker container stop nemo_container_${{ github.run_id }} || true |
| 125 | + docker container rm nemo_container_${{ github.run_id }} || true |
0 commit comments