-
Notifications
You must be signed in to change notification settings - Fork 154
ci: Enable initial unit tests and remove auto-formatting in PRs #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+519
−245
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
20938df
Remove autoformatting
chtruong814 2ba6249
Test isort lint checking
chtruong814 c9f98fa
Test fixing isort
chtruong814 998b429
Install lint dependencies from requirements_test.txt
chtruong814 ba1be08
Add pylint to requirements_test.txt
chtruong814 72b8d1f
Add flake8 to requirements_test.txt
chtruong814 1243760
Test black formatting failure
chtruong814 20806ef
Test black format failiure
chtruong814 e0904b4
Remove example.py
chtruong814 18e53b2
Remove directories from being excluded for formatting checks
chtruong814 8773662
Add initial test
chtruong814 fba817c
Add initial test placeholder
chtruong814 1ca3a12
Always require test comment to run CI tests
chtruong814 ca3a609
Fix lint errors
chtruong814 44d1e88
Fix workflow
chtruong814 3e14733
Fix workflow
chtruong814 33d6cd7
Fix test template
chtruong814 b3ee2e7
Use test template
chtruong814 9a58ddf
Fix test path
chtruong814 10c27ec
Fix path ref
chtruong814 ee2d459
Fix test
chtruong814 66d51c3
Fix test template ref
chtruong814 103be9e
Do not require test comment for trusted devs
chtruong814 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,73 +11,241 @@ | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| name: ~Build container template | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| image-name: | ||
| required: true | ||
| type: string | ||
| description: "The name of the image to build" | ||
| dockerfile: | ||
| required: true | ||
| type: string | ||
| runner: | ||
| required: false | ||
| default: linux-amd64-gpu-rtxa6000-latest-2-nemo | ||
| type: string | ||
| description: "The runner to use for the build" | ||
| secrets: | ||
| AZURE_CLIENT_ID: | ||
| required: true | ||
| AZURE_TENANT_ID: | ||
| required: true | ||
| AZURE_SUBSCRIPTION_ID: | ||
| required: true | ||
|
|
||
| jobs: | ||
| pre-flight: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| cache-from: ${{ steps.cache-from.outputs.LAST_PRS }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Get last merged PR | ||
| id: cache-from | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| LAST_PRS=$(gh api graphql -f query=' | ||
| query { | ||
| repository(owner: "NVIDIA", name: "NeMo-LM") { | ||
| pullRequests(states: MERGED, first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) { | ||
| nodes { | ||
| number | ||
| } | ||
| } | ||
| } | ||
| }' | jq -r '.data.repository.pullRequests.nodes[].number' | while read -r number; do | ||
| echo "nemoci.azurecr.io/${{ inputs.image-name }}-buildcache:$number" | ||
| done) | ||
|
|
||
| echo "LAST_PRS<<EOF" >> $GITHUB_OUTPUT | ||
| echo "$LAST_PRS" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
|
|
||
| build: | ||
| uses: NVIDIA/NeMo-FW-CI-templates/.github/workflows/[email protected] | ||
| needs: [pre-flight] | ||
| with: | ||
| image-name: ${{ inputs.image-name }} | ||
| dockerfile: ${{ inputs.dockerfile }} | ||
| image-label: nemo-core | ||
| prune-filter-timerange: 24h | ||
| use-inline-cache: false | ||
| runner: ${{ inputs.runner }} | ||
| has-azure-credentials: true | ||
| secrets: | ||
| AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | ||
| AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | ||
| AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
| name: "Test Template" | ||
| description: "Template for running NeMo tests in a containerized environment" | ||
|
|
||
| inputs: | ||
| runner: | ||
| description: "Runner to use for test" | ||
| required: true | ||
| timeout: | ||
| description: "Max runtime of test in minutes" | ||
| required: false | ||
| default: "10" | ||
| script: | ||
| description: "Test script to execute" | ||
| required: true | ||
| is_optional: | ||
| description: "Failure will cancel all other tests if set to true" | ||
| required: false | ||
| default: "false" | ||
| is_unit_test: | ||
| description: "Upload coverage as unit test" | ||
| required: false | ||
| default: "false" | ||
| image: | ||
| description: "Image to use for test" | ||
| required: false | ||
| default: "nemo_lm" | ||
| cpu-only: | ||
| description: "Run tests on CPU only" | ||
| required: false | ||
| default: "false" | ||
| azure-client-id: | ||
| description: "Azure Client ID" | ||
| required: true | ||
| azure-tenant-id: | ||
| description: "Azure Tenant ID" | ||
| required: true | ||
| azure-subscription-id: | ||
| description: "Azure Subscription ID" | ||
| required: true | ||
| has-azure-credentials: | ||
| description: "Has Azure credentials" | ||
| required: false | ||
| default: "false" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Install Azure CLI | ||
| if: ${{ inputs.has-azure-credentials == 'true' }} | ||
| shell: bash | ||
| run: | | ||
| curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash | ||
|
|
||
| - name: Azure Login | ||
| if: ${{ inputs.has-azure-credentials == 'true' }} | ||
| uses: azure/login@v2 | ||
| with: | ||
| client-id: ${{ inputs.azure-client-id }} | ||
| tenant-id: ${{ inputs.azure-tenant-id }} | ||
| subscription-id: ${{ inputs.azure-subscription-id }} | ||
|
|
||
| - name: Azure ACR Login | ||
| if: ${{ inputs.has-azure-credentials == 'true' }} | ||
| shell: bash | ||
| run: | | ||
| az acr login --name nemoci | ||
|
|
||
| - name: Azure Fileshare | ||
| if: ${{ inputs.has-azure-credentials == 'true' && inputs.is_unit_test == 'false' }} | ||
| shell: bash | ||
| id: azure-fileshare | ||
| run: | | ||
| sudo apt update | ||
| sudo apt install -y cifs-utils | ||
|
|
||
| RESOURCE_GROUP_NAME="azure-gpu-vm-runner_group" | ||
| STORAGE_ACCOUNT_NAME="nemocistorageaccount2" | ||
| FILE_SHARE_NAME="fileshare" | ||
|
|
||
| MNT_ROOT="/media" | ||
| MNT_PATH="$MNT_ROOT/$STORAGE_ACCOUNT_NAME/$FILE_SHARE_NAME" | ||
|
|
||
| echo "MNT_PATH=$MNT_PATH" | tee -a "$GITHUB_OUTPUT" | ||
|
|
||
| sudo mkdir -p $MNT_PATH | ||
|
|
||
| # Create a folder to store the credentials for this storage account and | ||
| # any other that you might set up. | ||
| CREDENTIAL_ROOT="/etc/smbcredentials" | ||
| sudo mkdir -p "/etc/smbcredentials" | ||
|
|
||
| # Get the storage account key for the indicated storage account. | ||
| # You must be logged in with az login and your user identity must have | ||
| # permissions to list the storage account keys for this command to work. | ||
| STORAGE_ACCOUNT_KEY=$(az storage account keys list \ | ||
| --resource-group $RESOURCE_GROUP_NAME \ | ||
| --account-name $STORAGE_ACCOUNT_NAME \ | ||
| --query "[0].value" --output tsv | tr -d '"') | ||
|
|
||
| # Create the credential file for this individual storage account | ||
| SMB_CREDENTIAL_FILE="$CREDENTIAL_ROOT/$STORAGE_ACCOUNT_NAME.cred" | ||
| if [ ! -f $SMB_CREDENTIAL_FILE ]; then | ||
| echo "username=$STORAGE_ACCOUNT_NAME" | sudo tee $SMB_CREDENTIAL_FILE > /dev/null | ||
| echo "password=$STORAGE_ACCOUNT_KEY" | sudo tee -a $SMB_CREDENTIAL_FILE > /dev/null | ||
| else | ||
| echo "The credential file $SMB_CREDENTIAL_FILE already exists, and was not modified." | ||
| fi | ||
|
|
||
| # Change permissions on the credential file so only root can read or modify the password file. | ||
| sudo chmod 600 $SMB_CREDENTIAL_FILE | ||
|
|
||
| # This command assumes you have logged in with az login | ||
| HTTP_ENDPOINT=$(az storage account show --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME --query "primaryEndpoints.file" --output tsv | tr -d '"') | ||
| SMB_PATH=$(echo $HTTP_ENDPOINT | cut -c7-${#HTTP_ENDPOINT})$FILE_SHARE_NAME | ||
|
|
||
| STORAGE_ACCOUNT_KEY=$(az storage account keys list --resource-group $RESOURCE_GROUP_NAME --account-name $STORAGE_ACCOUNT_NAME --query "[0].value" --output tsv | tr -d '"') | ||
|
|
||
| sudo mount -t cifs $SMB_PATH $MNT_PATH -o credentials=$SMB_CREDENTIAL_FILE,serverino,nosharesock,actimeo=30,mfsymlinks | ||
|
|
||
| ls -al $MNT_PATH/TestData | ||
|
|
||
| - name: Docker pull image | ||
| shell: bash | ||
| run: | | ||
| docker pull nemoci.azurecr.io/${{ inputs.image }}:${{ github.run_id }} | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| path: NeMo-LM | ||
|
|
||
| - name: Start container | ||
| shell: bash | ||
| run: | | ||
| MNT_PATH=${{ steps.azure-fileshare.outputs.mnt_path }} | ||
|
|
||
| ARG=("") | ||
| if [[ "${{ inputs.cpu-only }}" == "false" ]]; then | ||
| ARG=("--runtime=nvidia --gpus all") | ||
| fi | ||
|
|
||
| cmd=$(cat <<RUN_TEST_EOF | ||
| #!/bin/bash | ||
| docker container rm -f nemo_container_${{ github.run_id }} || true | ||
| docker run \ | ||
| --rm \ | ||
| -d \ | ||
| --name nemo_container_${{ github.run_id }} ${ARG[@]} \ | ||
| --shm-size=64g \ | ||
| --env TRANSFORMERS_OFFLINE=0 \ | ||
| --env HYDRA_FULL_ERROR=1 \ | ||
| --env HF_HOME=/home/TestData/HF_HOME \ | ||
| --env RUN_ID=${{ github.run_id }} \ | ||
| --volume $(pwd)/NeMo-LM:/workspace \ | ||
| --volume $MNT_PATH/TestData:/home/TestData \ | ||
| nemoci.azurecr.io/${{ inputs.image }}:${{ github.run_id }} \ | ||
| bash -c "sleep $(( ${{ inputs.timeout }} * 60 + 60 ))" | ||
| RUN_TEST_EOF | ||
| ) | ||
|
|
||
| echo "$cmd" | tee "retry_job.sh" | ||
| bash retry_job.sh | ||
| docker exec -t nemo_container_${{ github.run_id }} bash -c 'pip install -e .' | ||
|
|
||
| - name: Create run-script | ||
| id: create | ||
| shell: bash | ||
| run: | | ||
| COVERAGE_PREFIX=$([[ "${{ inputs.is_unit_test }}" == "true" ]] && echo "unit-test" || echo "e2e") | ||
| echo "coverage-prefix=$COVERAGE_PREFIX" | tee -a "$GITHUB_OUTPUT" | ||
|
|
||
| cmd=$(cat <<RUN_TEST_EOF | ||
| #!/bin/bash | ||
|
|
||
| ( | ||
| set -e | ||
|
|
||
| docker exec -t nemo_container_${{ github.run_id }} bash -c '\ | ||
| bash tests/${{ inputs.is_unit_test == 'true' && 'unit_tests' || 'functional_tests' }}/${{ inputs.script }}.sh && \ | ||
| echo "Finished successfully." || echo "Did not finish."' | ||
| ) 2>&1 | tee err.log | ||
|
|
||
| RUN_TEST_EOF | ||
| ) | ||
|
|
||
| echo "timeout_in_seconds=$(( ${{ inputs.timeout }} * 60 ))" | tee -a "$GITHUB_OUTPUT" | ||
| echo "$cmd" | tee "job.sh" | ||
|
|
||
| - name: Run main script | ||
| uses: nick-fields/retry@v3 | ||
| with: | ||
| timeout_seconds: ${{ steps.create.outputs.timeout_in_seconds }} | ||
| max_attempts: 3 | ||
| shell: bash | ||
| retry_on: timeout | ||
| command: /bin/bash job.sh | ||
| on_retry_command: /bin/bash retry_job.sh | ||
|
|
||
| - name: Check result | ||
| id: check | ||
| shell: bash | ||
| run: | | ||
| docker exec nemo_container_${{ github.run_id }} coverage combine || true | ||
| docker exec nemo_container_${{ github.run_id }} coverage xml | ||
| docker cp nemo_container_${{ github.run_id }}:/workspace/.coverage .coverage | ||
| docker cp nemo_container_${{ github.run_id }}:/workspace/coverage.xml coverage.xml | ||
|
|
||
| coverage_report=coverage-${{ steps.create.outputs.coverage-prefix }}-${{ github.run_id }}-$(uuidgen) | ||
| echo "coverage_report=$coverage_report" >> "$GITHUB_OUTPUT" | ||
|
|
||
| IS_SUCCESS=$(tail -n 1 err.log | grep -q "Finished successfully." && echo "true" || echo "false") | ||
|
|
||
| if [[ "$IS_SUCCESS" == "false" && "${{ inputs.is_optional }}" == "true" ]]; then | ||
| echo "::warning:: Test failed, but displayed as successful because it is marked as optional." | ||
| IS_SUCCESS=true | ||
| fi | ||
|
|
||
| if [[ "$IS_SUCCESS" == "false" ]]; then | ||
| echo Test did not finish successfully. | ||
| exit 1 | ||
| fi | ||
|
|
||
| exit $EXIT_CODE | ||
|
|
||
| - name: Test coverage | ||
| shell: bash -x -e -u -o pipefail {0} | ||
| run: | | ||
| docker exec -t nemo_container_${{ github.run_id }} coverage report -i | ||
|
|
||
| - name: Upload artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| if: ${{ steps.check.outputs.coverage_report != 'none' }} | ||
| with: | ||
| name: ${{ steps.check.outputs.coverage_report }} | ||
| path: | | ||
| coverage.xml | ||
| .coverage | ||
| include-hidden-files: true | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I removed the
Run CICDlabel need for now and I thought we were thinking better to use/ok to test? Or do you think we should just let any commit start running the CI? Open to either tbh. Early enough that we can wait to see if it's a pain without it.