Skip to content

CI-UnitTest

CI-UnitTest #217

Workflow file for this run

# 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 other workflows.
workflow_run:
workflows: ["CI-Entry", "CI-Entry-Nightly"]
types:
- completed
defaults:
run:
shell: bash
jobs:
check_status:
if: github.repository == 'awslabs/ratex'
runs-on: ubuntu-latest
outputs:
trigger: ${{ steps.job_info.outputs.trigger }}
ci_image: "metaprojdev/ratex:ci_gpu-latest"
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: Whether linting was failed
if: ${{ github.event.workflow_run.conclusion != 'success' }}
run: |
conclusion=${{ github.event.workflow_run.conclusion }}
echo "Linting wasn't successed: ${conclusion}"
exit 1
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: ci_lint.yml
run_id: ${{ github.event.workflow_run.id }}
- name: Parse common job info
id: job_info
run: |
skip_ci=$(head -n 1 artifact/skip.txt)
echo "::set-output name=skip_ci::${skip_ci}"
ref=$(head -n 1 artifact/ref.txt)
echo "::set-output name=ref::${ref}"
repo=$(head -n 1 artifact/repo.txt)
echo "::set-output name=repo::${repo}"
trigger=$(head -n 1 artifact/trigger.txt)
echo "::set-output name=trigger::${trigger}"
- 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 "::set-output name=pr::${pr}"
sha=$(head -n 1 artifact/sha.txt)
echo "::set-output name=sha::${sha}"
- 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 "::set-output name=tag::${tag}"
test_on_gpu:
# Run full tests with the latest docker image on GPU.
needs: [check_status]
if: github.repository == 'awslabs/ratex'
runs-on: ubuntu-latest
steps:
- uses: haya14busa/action-workflow_run-status@v1
- name: List environments
run: |
echo "Trigger: ${{ needs.check_status.outputs.trigger }}"
echo "Docker Image: ${{ needs.check_status.outputs.ci_image }}"
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@v2
- name: Lint-Build-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 unit tests"
exit 0
fi
echo "Running tests on CPU and GPU"
python3 -m pip install argparse boto3
python3 ./ci/batch/submit-job.py \
--job-type GPU \
--image ${{ needs.check_status.outputs.ci_image }} \
--name ci-ratex-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 set_pytorch ${{ needs.check_status.outputs.trigger }} &&
bash ./ci/batch/cli.sh compile ${{ needs.check_status.outputs.job_tag }} &&
bash ./ci/batch/cli.sh lint && bash ./ci/batch/cli.sh unit_test GPU"
test_on_multi_gpu:
needs: [check_status]
if: github.repository == 'awslabs/ratex'
runs-on: ubuntu-latest
steps:
- uses: haya14busa/action-workflow_run-status@v1
- name: List environments
run: |
echo "Trigger: ${{ needs.check_status.outputs.trigger }}"
echo "Docker Image: ${{ needs.check_status.outputs.ci_image }}"
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@v2
- 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 \
--job-type multi-GPU \
--image ${{ needs.check_status.outputs.ci_image }} \
--name ci-ratex-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 set_pytorch ${{ needs.check_status.outputs.trigger }} &&
bash ./ci/batch/cli.sh compile multi-GPU-${{ needs.check_status.outputs.job_tag }} &&
bash ./ci/batch/cli.sh unit_test multi-GPU"
update_ci_badge:
# Run this job whatever the unit tests were success or not.
needs: [test_on_gpu, test_on_multi_gpu]
if: ${{ always() && github.repository == 'awslabs/ratex' }}
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@v2
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
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)
trigger=$(head -n 1 artifact/trigger.txt)
echo "::set-output name=pr::${pr}"
echo "::set-output name=trigger::${trigger}"
- name: Generate CI badge
id: badge
run: |
# env vars are unavailable in job.if so we have to implement it here.
echo "Trigger: ${{ steps.pr_job_info.outputs.trigger }}"
echo "PR: ${{ steps.pr_job_info.outputs.pr }}"
if [ "${{ steps.pr_job_info.outputs.pr }}" != "" ]; then
echo "No need to update badge for PR CI. Skip."
exit 0
fi
if [ "${{ steps.pr_job_info.outputs.trigger }}" == "nightly" ]; then
echo "No need to update badge for nightly PR CI. Skip."
exit 0
fi
echo "::set-output name=gist_id::aeb41ce3096bc1aaeb671f2c58836a3f"
head_commit=$(git rev-parse --short HEAD)
if [[ "${{ needs.test_on_gpu.result }}" == "success" &&
"${{ needs.test_on_multi_gpu.result }}" == "success" ]]; then
echo "::set-output name=message::passing (${head_commit})"
echo "::set-output name=color::success"
else
echo "::set-output name=message::failing (${head_commit})"
echo "::set-output name=color::critical"
fi
- 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-ratex-ci-badge-last-pass.json
label: CI-UnitTests
message: ${{ steps.badge.outputs.message }}
color: ${{ steps.badge.outputs.color }}