-
Notifications
You must be signed in to change notification settings - Fork 3
201 lines (200 loc) · 7.87 KB
/
pr.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Run go-scalr tests on pr in any other repo
on:
workflow_dispatch:
inputs:
repo:
description: The repository with pull request
required: true
pr_id:
description: The number of the pull request
required: true
pr_head_sha:
description: The head sha of the pull request
required: true
pr_branch:
description: Pull request branch
base_branch:
description: Base branch of pull request
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
tests:
runs-on: ubuntu-latest
name: tests
env:
SCALR_TOKEN: ${{ secrets.SCALR_TOKEN }}
UPSTREAM_ID: ${{ github.run_number }}
steps:
- name: Sudo GitHub Token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{vars.SUDO_GHA_APP_ID}}
installation_id: ${{vars.SUDO_GHA_APP_INSTALLATION_ID}}
private_key: ${{secrets.SUDO_GHA_APP_PRIVATE_KEY}}
- uses: actions/checkout@v3
- name: Log pr link
run: |
echo ":taco: Pull request: https://github.com/Scalr/${{ inputs.repo }}/pull/${{ inputs.pr_id }} " >> $GITHUB_STEP_SUMMARY
- name: Get current job log URL
uses: Tiryoh/gha-jobid-action@v0
id: get-job-id
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
job_name: ${{ github.job }}
- name: Set pending status
uses: actions/github-script@v3
with:
github-token: ${{steps.generate_token.outputs.token}}
script: |
github.repos.createCommitStatus({
owner: 'Scalr',
repo: '${{ inputs.repo }}',
sha: '${{ inputs.pr_head_sha }}',
state: 'pending',
description: 'Starting go-scalr tests',
context: 'go-scalr',
target_url: '${{ steps.get-job-id.outputs.html_url }}',
})
- uses: actions/setup-go@v3
with:
go-version: "1.18"
- name: Clone fatmouse repo
uses: actions/checkout@v3
with:
repository: Scalr/fatmouse
path: fatmouse
ref: ${{ inputs.pr_branch }}
token: ${{steps.generate_token.outputs.token}}
- name: Get pr labels
id: pr-labels
uses: ./fatmouse/.github/actions/pr-labels
with:
github_token: ${{steps.generate_token.outputs.token}}
owner: Scalr
repo: fatmouse
pr_id: ${{ inputs.pr_id }}
- name: Set DB_BRANCH
if: ${{ contains(github.event.head_commit.message, '[DB_BRANCH]') }}
run: echo "DB_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- id: auth
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- name: Copy secrets
shell: bash
run: |
mkdir ~/.scalr-labs
gsutil cp gs://tacobell_development-156220/.secrets.yaml fatmouse/tacobell/.secrets.yaml
gsutil cp gs://tacobell_development-156220/github.json ~/.scalr-labs/github.json
- name: Configure docker
shell: bash
run: gcloud auth configure-docker eu.gcr.io
- name: Pull python builder
shell: bash
run: |
echo "::group::Pull python builder image"
docker pull eu.gcr.io/development-156220/fatmouse/python-builder:master
docker tag eu.gcr.io/development-156220/fatmouse/python-builder:master fatmouse/python-builder:master
echo "::endgroup::"
- name: Generate run tag
shell: bash
run: |
if [ ${{ github.run_attempt }} = 1 ]; then
RERUN_SUFFIX=""
else
RERUN_SUFFIX=$(echo -${{ github.run_attempt }})
fi
echo "RUN_TAG=e2e-go-scalr-external-pr-${{ github.run_number }}${RERUN_SUFFIX}" >> $GITHUB_ENV
- name: Create container
id: create
shell: bash
run: |
docker run --rm \
-e GITHUB_WORKSPACE=true \
-e GITHUB_OUTPUT=/fatmouse/output \
-w /fatmouse \
-v $PWD/fatmouse:/fatmouse \
-v $GITHUB_OUTPUT:/fatmouse/output \
-v ~/.scalr-labs:/etc/scalr-labs \
fatmouse/python-builder:master python -u clickfile.py te up \
--branch ${{ inputs.pr_branch }} \
--run-url ${{ steps.get-job-id.outputs.html_url }} \
--skip-ui-build \
--agent-pool-id="${{ !contains(steps.pr-labels.outputs.labels, ' e2e:tev2_on_server ') && vars.TACO_APOOL_ID || '' }}" \
${{ env.RUN_TAG }}
- name: Get Scalr hostname
shell: bash
run: |
SCALR_HOST=${{ steps.create.outputs.host }}
echo "SCALR_ADDRESS=https://mainiacp.${SCALR_HOST/https:\/\//}" >> $GITHUB_ENV
- name: Run tests
id: run-tests
env:
SCALR_ADDRESS: ${{ env.SCALR_ADDRESS }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }}
TEST_AWS_SECRET_KEY: ${{ secrets.TEST_AWS_SECRET_KEY }}
TEST_AWS_ROLE_ARN: ${{ secrets.TEST_AWS_ROLE_ARN }}
TEST_AWS_EXTERNAL_ID: ${{ secrets.TEST_AWS_EXTERNAL_ID }}
TEST_ARM_CLIENT_ID: ${{ secrets.TEST_ARM_CLIENT_ID }}
TEST_ARM_CLIENT_SECRET: ${{ secrets.TEST_ARM_CLIENT_SECRET }}
TEST_ARM_TENANT_ID: ${{ secrets.TEST_ARM_TENANT_ID }}
TEST_ARM_SUBSCRIPTION_ID: ${{ secrets.TEST_ARM_SUBSCRIPTION_ID }}
run: make test
- name: Set commit status after tests
if: ${{ always() && (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') }}
uses: actions/github-script@v3
with:
github-token: ${{steps.generate_token.outputs.token}}
script: |
github.repos.createCommitStatus({
owner: 'Scalr',
repo: '${{ inputs.repo }}',
sha: '${{ inputs.pr_head_sha }}',
state: '${{ steps.run-tests.outcome }}',
description: 'go-scalr tests result: ${{ steps.run-tests.outcome }}',
context: 'go-scalr',
target_url: '${{ steps.get-job-id.outputs.html_url }}',
})
- name: Set commit status on interrupted workflow
if: ${{ always() && steps.run-tests.outcome != 'failure' && steps.run-tests.outcome != 'success' }}
uses: actions/github-script@v3
with:
github-token: ${{steps.generate_token.outputs.token}}
script: |
github.repos.createCommitStatus({
owner: 'Scalr',
repo: '${{ inputs.repo }}',
sha: '${{ inputs.pr_head_sha }}',
state: 'error',
description: 'go-scalr workflow was interrupted',
context: 'go-scalr',
target_url: '${{ steps.get-job-id.outputs.html_url }}',
})
- name: Add comment on failed tests
if: ${{ always() && steps.run-tests.outcome == 'failure' }}
uses: actions/github-script@v5
with:
script: |
const issue_number = ${{ inputs.pr_id }};
const owner = 'Scalr';
const repo = '${{ inputs.repo }}';
const message = '**go-scalr tests failed**\nJob url ${{ steps.get-job-id.outputs.html_url }}';
await github.rest.issues.createComment({owner, repo, issue_number, body: message});
github-token: ${{steps.generate_token.outputs.token}}
- name: Delete container
id: delete
if: ${{ always() }}
shell: bash
run: |
docker run --rm \
-w /fatmouse \
-v $PWD/fatmouse:/fatmouse \
-v ~/.scalr-labs:/etc/scalr-labs \
fatmouse/python-builder:master \
python -u clickfile.py te rm \
--no-wait ${{ env.RUN_TAG }}