forked from ufs-community/ufs-weather-model
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (126 loc) · 4.64 KB
/
aux.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
name: Helpers
on:
workflow_run:
workflows: ["Pull Request Tests"]
types:
- requested
env:
app: Accept:application/vnd.github.v3+json
base_url: $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs
AUTH: ${{ secrets.GITHUB_TOKEN }}
aws_instance_id: ${{ secrets.AWS_INSTANCE_ID }}
no_instances: 10
jobs:
pre:
name: Preprocess
runs-on: ubuntu-20.04
steps:
- name: Share helper id
run: echo -n ${{ github.run_id }} >~/id_file
- uses: actions/cache@v2
with:
path: ~/id_file
key: helperid-${{ github.event.workflow_run.id }}
- name: Delete run-ci label
run: |
head_sha=${{ github.event.workflow_run.head_sha }}
url=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY
pr_number=$(curl -sS -H $app $url/pulls \
| jq -r '.[] | select(.head.sha == "'"$head_sha"'") | .number')
echo "pr_number is $pr_number"
curl -sS -X DELETE -H $app -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
$url/issues/$pr_number/labels/run-ci
repocheck:
name: Repo check
runs-on: ubuntu-20.04
steps:
- name: Check up-to-dateness and post comment
run: |
head_sha=${{ github.event.workflow_run.head_sha }}
git clone -q ${{ github.event.workflow_run.head_repository.html_url }} .
git checkout -q $head_sha
git submodule -q update --init --recursive
cd ${{ github.workspace }}/tests/ci
url=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY
pr_number=$(curl -sS -H $app $url/pulls \
| jq -r '.[] | select(.head.sha == "'"$head_sha"'") | .number')
echo "pr_number is $pr_number"
pr_uid=${{ github.event.workflow_run.head_repository.owner.login }}
echo "pr_uid is $pr_uid"
comment="$(./repo_check.sh $pr_uid 2>/dev/null)"
echo "comment is $comment"
if [[ -n $comment ]]; then
curl -sS -X POST -H $app -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
$url/issues/$pr_number/comments -d '{"body": "'"${comment}"'"}'
echo -n "failure" >~/repocheck_file
else
echo -n "success" >~/repocheck_file
fi
- uses: actions/cache@v2
with:
path: ~/repocheck_file
key: repocheck-${{ github.event.workflow_run.id }}
startrunner:
name: Start runners
needs: repocheck
runs-on: ubuntu-20.04
outputs:
started: ${{ steps.ec2.outputs.started }}
steps:
- uses: actions/checkout@v2
- name: Check all builds are complete and successful
id: current
run: |
cd ${{ github.workspace }}/tests/ci
eval url=$base_url/${{ github.event.workflow_run.id }}/jobs
b_r=$(echo -n $url | ./check_status.py build)
if [ $b_r == 'success' ]; then
echo "::set-output name=check::pass"
elif [ $b_r == 'failure' ]; then
echo "::set-output name=check::fail"
fi
- name: Check all previous runs finish using ec2
id: previous
if: steps.current.outputs.check == 'pass'
run: |
cd ${{ github.workspace }}/tests/ci
eval url=$base_url
echo -n $url | ./check_status.py ec2 ${{ github.run_id }}
- uses: aws-actions/configure-aws-credentials@v1
if: steps.current.outputs.check == 'pass'
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Start ec2 instances
id: ec2
if: steps.current.outputs.check == 'pass'
run: |
no_stopped=0
while [ $no_stopped -lt $no_instances ]; do
sleep 20
no_stopped=$(aws ec2 describe-instances --instance-ids $aws_instance_id \
| jq -r '.Reservations[].Instances[].State.Name' | grep stopped | wc -l)
echo "no_stopped: $no_stopped"
done
aws ec2 start-instances --instance-ids $aws_instance_id
echo "::set-output name=started::yes"
stoprunner:
name: Stop runners
needs: startrunner
runs-on: ubuntu-20.04
if: needs.startrunner.outputs.started == 'yes'
steps:
- uses: actions/checkout@v2
- name: Check all tests are complete
run: |
cd ${{ github.workspace }}/tests/ci
eval url=$base_url/${{ github.event.workflow_run.id }}
echo $url | ./check_status.py test
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Stop ec2 instances
run: aws ec2 stop-instances --instance-ids $aws_instance_id