-
Notifications
You must be signed in to change notification settings - Fork 15
165 lines (161 loc) · 6.76 KB
/
ci_unit_test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 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/slapo'
runs-on: ubuntu-latest
outputs:
# FIXME: We have to make lots of changes on AWS batch to allow
# private docker hub images, so we currently use a private ECR image.
docker_image: "metaprojdev/slapo:ci-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: 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 "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
unit_test:
needs: [check_status]
if: github.repository == 'awslabs/slapo'
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@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 tests"
exit 0
fi
echo "Running tests on GPUs"
python3 -m pip install argparse boto3
python3 ./ci/submit_job.py \
--platform multi-GPU \
--image ${{ needs.check_status.outputs.docker_image }} \
--name ci-gpu-${{ needs.check_status.outputs.job_tag }} \
--job-queue ci-gpu-queue \
--job-def-cfg ./ci/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/install_test_pkgs.sh; bash ./ci/task_unit_test.sh"
update_ci_badge:
needs: [unit_test]
# Run this job whatever the unit tests were success or not.
if: ${{ always() && github.repository == 'awslabs/slapo' }}
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)
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=4b5f48daff54fb5d1a862c1649632648" >> $GITHUB_OUTPUT
head_commit=$(git rev-parse --short HEAD)
if [[ "${{ needs.unit_test.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
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-slapo-ci-badge-last-pass.json
label: CI-UnitTests
message: ${{ steps.badge.outputs.message }}
color: ${{ steps.badge.outputs.color }}