CI-UnitTest #528
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
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: CI-UnitTest | |
| on: | |
| # This workflow includes AWS credential to run jobs on AWS batch. | |
| # Thus, this workflow cannot checkout PRs and can only be triggered by CI-Lint. | |
| workflow_run: | |
| workflows: ["CI-Lint"] | |
| types: | |
| - completed | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| check_status: | |
| if: github.repository == 'awslabs/raf' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| cpu_image: "metaprojdev/raf:ci_cpu-v0.21" | |
| gpu_image: "metaprojdev/raf:ci_gpu-v0.23" | |
| skip_ci: ${{ steps.job_info.outputs.skip_ci }} | |
| ref: ${{ steps.job_info.outputs.ref }} | |
| repo: ${{ steps.job_info.outputs.repo }} | |
| pr: ${{ steps.pr_job_info.outputs.pr }} | |
| sha: ${{ steps.pr_job_info.outputs.sha }} | |
| job_tag: ${{ steps.gen_tag.outputs.tag }} | |
| steps: | |
| # The workflow triggered by workflow run will not show its status | |
| # in Github by default, so we have to use this action to enable it. | |
| # Note that when this action is used, "name" in job is unavailable: | |
| # https://github.com/haya14busa/action-workflow_run-status/issues/158 | |
| - uses: haya14busa/action-workflow_run-status@v1 | |
| - name: Download artifact | |
| uses: dawidd6/action-download-artifact@v6 | |
| with: | |
| workflow: ci_lint.yml | |
| run_id: ${{ github.event.workflow_run.id }} | |
| - name: Validate artifact content | |
| run: | | |
| # The artifact was generated by the CI-Lint workflow and contains the following files: | |
| # skip.txt, ref.txt, repo.txt, pr.txt, sha.txt | |
| # We will verify these exist and validate their contents. | |
| REQUIRED_FILES=("skip.txt" "ref.txt" "repo.txt" "pr.txt" "sha.txt") | |
| for filename in "${REQUIRED_FILES[@]}"; do | |
| if [[ ! -f "artifact/$filename" ]]; then | |
| echo "ERROR: Missing expected artifact file: artifact/$filename" | |
| exit 1 | |
| fi | |
| content=$(cat "artifact/$filename") | |
| # Use a case statement to perform file-specific checks. | |
| case "$filename" in | |
| # 1) skip.txt must be "0" or "1" | |
| "skip.txt") | |
| if [[ "$content" != "0" && "$content" != "1" ]]; then | |
| echo "ERROR: artifact/skip.txt must be '0' or '1', got '$content'" | |
| exit 1 | |
| fi | |
| ;; | |
| # 2) ref.txt must match e.g. refs/heads/* or refs/pull/* | |
| "ref.txt") | |
| # Adjust the regex if your branch names or refs differ. | |
| if ! [[ "$content" =~ ^refs/(heads|pull)/[A-Za-z0-9._/-]+$ ]]; then | |
| echo "ERROR: artifact/ref.txt must match 'refs/heads/...' or 'refs/pull/...', got '$content'" | |
| exit 1 | |
| fi | |
| ;; | |
| # 3) repo.txt must be "awslabs/raf" (replace with your actual expected name) | |
| "repo.txt") | |
| if [[ "$content" != "awslabs/raf" ]]; then | |
| echo "ERROR: artifact/repo.txt must be 'awslabs/raf', got '$content'" | |
| exit 1 | |
| fi | |
| ;; | |
| # 4) pr.txt must be an integer | |
| "pr.txt") | |
| if ! [[ "$content" =~ ^[0-9]+$ ]]; then | |
| echo "ERROR: artifact/pr.txt must be numeric (a PR ID), got '$content'" | |
| exit 1 | |
| fi | |
| ;; | |
| # 5) sha.txt must be a 40-character hex string (typical Git commit SHA) | |
| "sha.txt") | |
| if ! [[ "$content" =~ ^[0-9a-fA-F]{40}$ ]]; then | |
| echo "ERROR: artifact/sha.txt must be a valid 40-char hex commit SHA, got '$content'" | |
| exit 1 | |
| fi | |
| ;; | |
| esac | |
| echo "artifact/$filename passed checks with content: '$content'" | |
| done | |
| echo "All artifact files are valid." | |
| - name: Parse common job info | |
| id: job_info | |
| run: | | |
| skip_ci=$(head -n 1 artifact/skip.txt) | |
| echo "skip_ci=${skip_ci}" >> $GITHUB_OUTPUT | |
| ref=$(head -n 1 artifact/ref.txt) | |
| echo "ref=${ref}" >> $GITHUB_OUTPUT | |
| repo=$(head -n 1 artifact/repo.txt) | |
| echo "repo=${repo}" >> $GITHUB_OUTPUT | |
| lint=${{ github.event.workflow_run.conclusion }} | |
| echo "Linting result: ${lint}" | |
| - name: Parse PR job info | |
| id: pr_job_info | |
| continue-on-error: true | |
| # Note that pr and sha only available for pull request, and will be empty for push events. | |
| run: | | |
| pr=$(head -n 1 artifact/pr.txt) | |
| echo "pr=${pr}" >> $GITHUB_OUTPUT | |
| sha=$(head -n 1 artifact/sha.txt) | |
| echo "sha=${sha}" >> $GITHUB_OUTPUT | |
| - name: Generate tag | |
| id: gen_tag | |
| # This tag is PR-unique so it can be used to connect jobs for the same PR. | |
| # For example, we use it to share ccache caches and cancel previous runs. | |
| run: | | |
| tag=${{ steps.job_info.outputs.repo }}/${{ steps.pr_job_info.outputs.pr }} | |
| echo "tag=${tag}" >> $GITHUB_OUTPUT | |
| - name: Whether linting was failed | |
| if: ${{ github.event.workflow_run.conclusion != 'success' }} | |
| run: exit 1 | |
| test_on_cpu: | |
| needs: [check_status] | |
| if: github.repository == 'awslabs/raf' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: haya14busa/action-workflow_run-status@v1 | |
| - name: List environments | |
| run: | | |
| echo "Job tag: ${{ needs.check_status.outputs.job_tag }}" | |
| echo "Skip CI? ${{ needs.check_status.outputs.skip_ci }}" | |
| echo "REF: ${{ needs.check_status.outputs.ref }}" | |
| echo "REPO: ${{ needs.check_status.outputs.repo }}" | |
| echo "PR: ${{ needs.check_status.outputs.pr }}" | |
| echo "SHA: ${{ needs.check_status.outputs.sha }}" | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_BATCH_ACCESS_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_BATCH_SECRET_ACCESS_KEY }} | |
| aws-region: us-west-2 | |
| - name: Checkout repository | |
| # No need to checkout submodules because we only need the script. | |
| uses: actions/checkout@v4 | |
| - name: Test | |
| run: | | |
| # env vars are unavailable in job.if so we have to implement it here. | |
| if [ "${{ needs.check_status.outputs.skip_ci }}" == "1" ]; then | |
| echo "Skip CPU tests" | |
| exit 0 | |
| fi | |
| echo "Running tests on CPU" | |
| python3 -m pip install argparse boto3 | |
| python3 ./ci/batch/submit-job.py \ | |
| --platform CPU \ | |
| --image ${{ needs.check_status.outputs.cpu_image }} \ | |
| --name ci-cpu-${{ needs.check_status.outputs.job_tag }} \ | |
| --job-queue ci-cpu-queue \ | |
| --job-def-cfg ./ci/batch/job-def-cfg.json \ | |
| --entry-script /batch/entry.sh \ | |
| --source-ref ${{ needs.check_status.outputs.ref }} \ | |
| --repo ${{ needs.check_status.outputs.repo }} \ | |
| --wait \ | |
| --command "bash ./ci/batch/cli.sh config_cmake CPU && | |
| bash ./ci/batch/cli.sh compile build CPU ${{ needs.check_status.outputs.job_tag }} && | |
| bash ./ci/batch/cli.sh unit_test CPU" | |
| test_on_gpu: | |
| needs: [check_status] | |
| if: github.repository == 'awslabs/raf' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: haya14busa/action-workflow_run-status@v1 | |
| - name: List environments | |
| run: | | |
| echo "Job tag: ${{ needs.check_status.outputs.job_tag }}" | |
| echo "Skip CI? ${{ needs.check_status.outputs.skip_ci }}" | |
| echo "REF: ${{ needs.check_status.outputs.ref }}" | |
| echo "REPO: ${{ needs.check_status.outputs.repo }}" | |
| echo "PR: ${{ needs.check_status.outputs.pr }}" | |
| echo "SHA: ${{ needs.check_status.outputs.sha }}" | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_BATCH_ACCESS_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_BATCH_SECRET_ACCESS_KEY }} | |
| aws-region: us-west-2 | |
| - name: Checkout repository | |
| # No need to checkout submodules because we only need the script. | |
| uses: actions/checkout@v4 | |
| - name: Test | |
| run: | | |
| # env vars are unavailable in job.if so we have to implement it here. | |
| if [ "${{ needs.check_status.outputs.skip_ci }}" == "1" ]; then | |
| echo "Skip GPU tests" | |
| exit 0 | |
| fi | |
| echo "Running tests on GPU" | |
| python3 -m pip install argparse boto3 | |
| python3 ./ci/batch/submit-job.py \ | |
| --platform GPU \ | |
| --image ${{ needs.check_status.outputs.gpu_image }} \ | |
| --name ci-gpu-${{ needs.check_status.outputs.job_tag }} \ | |
| --job-queue ci-gpu-queue \ | |
| --job-def-cfg ./ci/batch/job-def-cfg.json \ | |
| --entry-script /batch/entry.sh \ | |
| --source-ref ${{ needs.check_status.outputs.ref }} \ | |
| --repo ${{ needs.check_status.outputs.repo }} \ | |
| --wait \ | |
| --command "bash ./ci/batch/cli.sh config_cmake GPU 75 && | |
| bash ./ci/batch/cli.sh compile build GPU ${{ needs.check_status.outputs.job_tag }} && | |
| bash ./ci/batch/cli.sh unit_test GPU" | |
| test_on_multi_gpu: | |
| needs: [check_status] | |
| if: github.repository == 'awslabs/raf' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: haya14busa/action-workflow_run-status@v1 | |
| - name: List environments | |
| run: | | |
| echo "Job tag: ${{ needs.check_status.outputs.job_tag }}" | |
| echo "Skip CI? ${{ needs.check_status.outputs.skip_ci }}" | |
| echo "REF: ${{ needs.check_status.outputs.ref }}" | |
| echo "REPO: ${{ needs.check_status.outputs.repo }}" | |
| echo "PR: ${{ needs.check_status.outputs.pr }}" | |
| echo "SHA: ${{ needs.check_status.outputs.sha }}" | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_BATCH_ACCESS_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_BATCH_SECRET_ACCESS_KEY }} | |
| aws-region: us-west-2 | |
| - name: Checkout repository | |
| # No need to checkout submodules because we only need the script. | |
| uses: actions/checkout@v4 | |
| - name: Test | |
| run: | | |
| # env vars are unavailable in job.if so we have to implement it here. | |
| if [ "${{ needs.check_status.outputs.skip_ci }}" == "1" ]; then | |
| echo "Skip multi-GPU tests" | |
| exit 0 | |
| fi | |
| echo "Running tests on Multiply GPUs" | |
| python3 -m pip install argparse boto3 | |
| python3 ./ci/batch/submit-job.py \ | |
| --platform multi-GPU \ | |
| --image ${{ needs.check_status.outputs.gpu_image }} \ | |
| --name ci-multi-gpu-${{ needs.check_status.outputs.job_tag }} \ | |
| --job-queue ci-gpu-queue \ | |
| --job-def-cfg ./ci/batch/job-def-cfg.json \ | |
| --entry-script /batch/entry.sh \ | |
| --source-ref ${{ needs.check_status.outputs.ref }} \ | |
| --repo ${{ needs.check_status.outputs.repo }} \ | |
| --wait \ | |
| --command "bash ./ci/batch/cli.sh config_cmake GPU 75 && | |
| bash ./ci/batch/cli.sh compile build multi-GPU ${{ needs.check_status.outputs.job_tag }} && | |
| bash ./ci/batch/cli.sh unit_test multi-GPU" | |
| update_ci_badge: | |
| needs: [test_on_cpu, test_on_gpu, test_on_multi_gpu] | |
| # Run this job whatever the unit tests were success or not. | |
| if: ${{ always() && github.repository == 'awslabs/raf' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: haya14busa/action-workflow_run-status@v1 | |
| - name: Checkout repository | |
| # No need to checkout submodules because we only need to get the HEAD commit hash. | |
| uses: actions/checkout@v4 | |
| - name: Download artifact | |
| uses: dawidd6/action-download-artifact@v6 | |
| with: | |
| workflow: ci_lint.yml | |
| run_id: ${{ github.event.workflow_run.id }} | |
| - name: Parse PR job info | |
| id: pr_job_info | |
| continue-on-error: true | |
| # Note that pr and sha only available for pull request, and will be empty for push events. | |
| run: | | |
| pr=$(head -n 1 artifact/pr.txt) | |
| echo "pr=${pr}" >> $GITHUB_OUTPUT | |
| - name: Generate CI badge | |
| id: badge | |
| run: | | |
| # env vars are unavailable in job.if so we have to implement it here. | |
| if [ "${{ steps.pr_job_info.outputs.pr }}" != "" ]; then | |
| echo "No need to update badge for PR CI. Skip." | |
| exit 0 | |
| fi | |
| echo "gist_id=a3f4a76704e40ddba1b73fb0ad072eb9" >> $GITHUB_OUTPUT | |
| head_commit=$(git rev-parse --short HEAD) | |
| if [[ "${{ needs.test_on_cpu.result }}" == "success" && | |
| "${{ needs.test_on_gpu.result }}" == "success" && | |
| "${{ needs.test_on_multi_gpu.result }}" == "success" ]]; then | |
| echo "message=passing (${head_commit})" >> $GITHUB_OUTPUT | |
| echo "color=success" >> $GITHUB_OUTPUT | |
| else | |
| echo "message=failing (${head_commit})" >> $GITHUB_OUTPUT | |
| echo "color=critical" >> $GITHUB_OUTPUT | |
| - name: Update CI badge | |
| # Intentionally fail this step with empty gist_id. | |
| uses: schneegans/[email protected] | |
| continue-on-error: true | |
| with: | |
| auth: ${{ secrets.BOT_TOKEN }} | |
| gistID: ${{ steps.badge.outputs.gist_id }} | |
| filename: awslabs-raf-ci-badge-last-pass.json | |
| label: CI-UnitTests | |
| message: ${{ steps.badge.outputs.message }} | |
| color: ${{ steps.badge.outputs.color }} |