|
| 1 | +name: Helpers |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Pull Request Tests"] |
| 5 | + types: |
| 6 | + - requested |
| 7 | +env: |
| 8 | + app: Accept:application/vnd.github.v3+json |
| 9 | + base_url: $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs |
| 10 | + AUTH: ${{ secrets.GITHUB_TOKEN }} |
| 11 | + aws_instance_id: ${{ secrets.AWS_INSTANCE_ID }} |
| 12 | + no_instances: 6 |
| 13 | + |
| 14 | + |
| 15 | +jobs: |
| 16 | + pre: |
| 17 | + name: Preprocess |
| 18 | + runs-on: ubuntu-20.04 |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Share helper id |
| 22 | + run: echo -n ${{ github.run_id }} >~/id_file |
| 23 | + |
| 24 | + - uses: actions/cache@v2 |
| 25 | + with: |
| 26 | + path: ~/id_file |
| 27 | + key: helperid-${{ github.event.workflow_run.id }} |
| 28 | + |
| 29 | + |
| 30 | + repocheck: |
| 31 | + name: Repo check |
| 32 | + runs-on: ubuntu-20.04 |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Check up-to-dateness and post comment |
| 36 | + run: | |
| 37 | + if [[ ${{ github.event.workflow_run.event }} == push ]]; then |
| 38 | + echo "This is a push event. No need to check." |
| 39 | + comment='' |
| 40 | + elif [[ ${{ github.event.workflow_run.event }} == pull_request ]]; then |
| 41 | + echo "This is a pull_request event. Check." |
| 42 | + head_sha=${{ github.event.workflow_run.head_sha }} |
| 43 | + echo "head_sha is $head_sha" |
| 44 | +
|
| 45 | + git clone -q ${{ github.event.workflow_run.head_repository.html_url }} . |
| 46 | + git checkout -q $head_sha |
| 47 | + git submodule -q update --init --recursive |
| 48 | +
|
| 49 | + cd ${{ github.workspace }}/tests/ci |
| 50 | + url=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY |
| 51 | + pr_number=$(curl -sS -H $app $url/pulls \ |
| 52 | + | jq -r '.[] | select(.head.sha == "'"$head_sha"'") | .number') |
| 53 | + echo "pr_number is $pr_number" |
| 54 | + pr_uid=${{ github.event.workflow_run.head_repository.owner.login }} |
| 55 | + echo "pr_uid is $pr_uid" |
| 56 | + comment="$(./repo_check.sh $pr_uid 2>/dev/null)" |
| 57 | + echo "comment is $comment" |
| 58 | + fi |
| 59 | +
|
| 60 | + if [[ -n $comment ]]; then |
| 61 | + curl -sS -X POST -H $app -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 62 | + $url/issues/$pr_number/comments -d '{"body": "'"${comment}"'"}' |
| 63 | + echo -n "failure" >~/repocheck_file |
| 64 | + else |
| 65 | + echo -n "success" >~/repocheck_file |
| 66 | + fi |
| 67 | +
|
| 68 | + - uses: actions/cache@v2 |
| 69 | + with: |
| 70 | + path: ~/repocheck_file |
| 71 | + key: repocheck-${{ github.event.workflow_run.id }} |
| 72 | + |
| 73 | + |
| 74 | + startrunner: |
| 75 | + name: Start runners |
| 76 | + needs: repocheck |
| 77 | + runs-on: ubuntu-20.04 |
| 78 | + outputs: |
| 79 | + started: ${{ steps.ec2.outputs.started }} |
| 80 | + |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v2 |
| 83 | + |
| 84 | + - name: Check all builds are complete and successful |
| 85 | + id: current |
| 86 | + run: | |
| 87 | + cd ${{ github.workspace }}/tests/ci |
| 88 | + eval url=$base_url/${{ github.event.workflow_run.id }}/jobs |
| 89 | + b_r=$(echo -n $url | ./check_status.py build $(./setup.py no_builds)) |
| 90 | + if [ $b_r == 'success' ]; then |
| 91 | + echo "::set-output name=check::pass" |
| 92 | + elif [ $b_r == 'failure' ]; then |
| 93 | + echo "::set-output name=check::fail" |
| 94 | + fi |
| 95 | +
|
| 96 | + - name: Check all previous runs finish using ec2 |
| 97 | + id: previous |
| 98 | + if: steps.current.outputs.check == 'pass' |
| 99 | + run: | |
| 100 | + cd ${{ github.workspace }}/tests/ci |
| 101 | + eval url=$base_url |
| 102 | + echo -n $url | ./check_status.py ec2 ${{ github.run_id }} |
| 103 | +
|
| 104 | + - uses: aws-actions/configure-aws-credentials@v1 |
| 105 | + if: steps.current.outputs.check == 'pass' |
| 106 | + with: |
| 107 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 108 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 109 | + aws-region: us-east-1 |
| 110 | + |
| 111 | + - name: Start ec2 instances |
| 112 | + id: ec2 |
| 113 | + if: steps.current.outputs.check == 'pass' |
| 114 | + run: | |
| 115 | + no_stopped=0 |
| 116 | + while [ $no_stopped -lt $no_instances ]; do |
| 117 | + sleep 20 |
| 118 | + no_stopped=$(aws ec2 describe-instances --instance-ids $aws_instance_id \ |
| 119 | + | jq -r '.Reservations[].Instances[].State.Name' | grep stopped | wc -l) |
| 120 | + echo "no_stopped: $no_stopped" |
| 121 | + done |
| 122 | + aws ec2 start-instances --instance-ids $aws_instance_id |
| 123 | + echo "::set-output name=started::yes" |
| 124 | +
|
| 125 | +
|
| 126 | + stoprunner: |
| 127 | + name: Stop runners |
| 128 | + needs: startrunner |
| 129 | + runs-on: ubuntu-20.04 |
| 130 | + if: needs.startrunner.outputs.started == 'yes' |
| 131 | + |
| 132 | + steps: |
| 133 | + - uses: actions/checkout@v2 |
| 134 | + |
| 135 | + - name: Check all tests are complete |
| 136 | + run: | |
| 137 | + cd ${{ github.workspace }}/tests/ci |
| 138 | + eval url=$base_url/${{ github.event.workflow_run.id }} |
| 139 | + echo $url | ./check_status.py test |
| 140 | +
|
| 141 | + - uses: aws-actions/configure-aws-credentials@v1 |
| 142 | + with: |
| 143 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 144 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 145 | + aws-region: us-east-1 |
| 146 | + |
| 147 | + - name: Stop ec2 instances |
| 148 | + run: aws ec2 stop-instances --instance-ids $aws_instance_id |
0 commit comments