Skip to content

Commit 9a3f7df

Browse files
committed
SCALRCORE-26072: Trigger go-scalr tests in fatmouse PRs
1 parent 5d0d321 commit 9a3f7df

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed

.github/workflows/pr.yml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
name: Run go-scalr tests on pr in any other repo
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
repo:
6+
description: The repository with pull request
7+
required: true
8+
pr_id:
9+
description: The number of the pull request
10+
required: true
11+
pr_head_sha:
12+
description: The head sha of the pull request
13+
required: true
14+
pr_branch:
15+
description: Pull request branch
16+
concurrency:
17+
group: ${{ github.ref }}-${{ github.workflow }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
tests:
22+
runs-on: ubuntu-latest
23+
name: tests
24+
env:
25+
SCALR_TOKEN: ${{ secrets.SCALR_TOKEN }}
26+
UPSTREAM_ID: ${{ github.run_number }}
27+
steps:
28+
- uses: actions/checkout@v3
29+
- name: Log pr link
30+
run: |
31+
echo ":taco: Pull request: https://github.com/Scalr/${{ inputs.repo }}/pull/${{ inputs.pr_id }} " >> $GITHUB_STEP_SUMMARY
32+
- name: Get current job log URL
33+
uses: Tiryoh/gha-jobid-action@v0
34+
id: get-job-id
35+
with:
36+
github_token: ${{ secrets.GITHUB_TOKEN }}
37+
job_name: ${{ github.job }}
38+
- name: Set pending status
39+
uses: actions/github-script@v3
40+
with:
41+
github-token: ${{ secrets.GH_PAT }}
42+
script: |
43+
github.repos.createCommitStatus({
44+
owner: 'Scalr',
45+
repo: '${{ inputs.repo }}',
46+
sha: '${{ inputs.pr_head_sha }}',
47+
state: 'pending',
48+
description: 'Starting go-scalr tests',
49+
context: 'go-scalr',
50+
target_url: '${{ steps.get-job-id.outputs.html_url }}',
51+
})
52+
- uses: actions/setup-go@v3
53+
with:
54+
go-version: "1.18"
55+
- name: Clone fatmouse repo
56+
uses: actions/checkout@v3
57+
with:
58+
repository: Scalr/fatmouse
59+
path: fatmouse
60+
token: ${{ secrets.GH_PAT }}
61+
- name: Set DB_BRANCH
62+
if: ${{ contains(github.event.head_commit.message, '[DB_BRANCH]') }}
63+
run: echo "DB_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
64+
- id: auth
65+
uses: google-github-actions/auth@v0
66+
with:
67+
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
68+
- name: Set up Cloud SDK
69+
uses: google-github-actions/setup-gcloud@v0
70+
- name: Copy secrets
71+
shell: bash
72+
run: |
73+
mkdir ~/.scalr-labs
74+
gsutil cp gs://drone_bucket/prod/private.d/.secrets.yaml fatmouse/tacobell/.secrets.yaml
75+
gsutil cp gs://drone_bucket/prod/private.d/github.json ~/.scalr-labs/github.json
76+
- name: Configure docker
77+
shell: bash
78+
run: gcloud auth configure-docker eu.gcr.io
79+
- name: Pull python builder
80+
shell: bash
81+
run: |
82+
echo "::group::Pull python builder image"
83+
docker pull eu.gcr.io/development-156220/fatmouse/python-builder:master
84+
docker tag eu.gcr.io/development-156220/fatmouse/python-builder:master fatmouse/python-builder:master
85+
echo "::endgroup::"
86+
- name: Get current job log URL
87+
uses: Tiryoh/gha-jobid-action@v0
88+
id: get-job-id
89+
with:
90+
github_token: ${{ secrets.GITHUB_TOKEN }}
91+
job_name: ${{ github.job }}
92+
- name: Generate run tag
93+
shell: bash
94+
run: |
95+
if [ ${{ github.run_attempt }} = 1 ]; then
96+
RERUN_SUFFIX=""
97+
else
98+
RERUN_SUFFIX=$(echo -${{ github.run_attempt }})
99+
fi
100+
echo "RUN_TAG=e2e-${{ github.workflow }}-${{ github.job }}-${{ github.run_number }}${RERUN_SUFFIX}" >> $GITHUB_ENV
101+
- name: Create container
102+
id: create
103+
shell: bash
104+
run: |
105+
FATMOUSE_BRANCH="--fatmouse-branch ${{ inputs.pr_branch }}"
106+
SCALR_BRANCH="--scalr-branch ${{ inputs.pr_branch }}"
107+
108+
if [ "${{ inputs.pr_branch }}" = "staging" ]; then
109+
IMAGE="--scalr-server-image-tag staging"
110+
else
111+
IMAGE=""
112+
fi
113+
114+
docker run --rm \
115+
-e GITHUB_WORKSPACE=true \
116+
-e GITHUB_OUTPUT=/fatmouse/output \
117+
-w /fatmouse \
118+
-v $PWD/fatmouse:/fatmouse \
119+
-v $GITHUB_OUTPUT:/fatmouse/output \
120+
-v ~/.scalr-labs:/etc/scalr-labs \
121+
fatmouse/python-builder:master python -u clickfile.py te up \
122+
${FATMOUSE_BRANCH} ${SCALR_BRANCH} ${IMAGE} \
123+
--run-url ${{ steps.get-job-id.outputs.html_url }} \
124+
--skip-ui-build \
125+
--cpu=1 \
126+
--ram=2G \
127+
${{ env.RUN_TAG }}
128+
- name: Run tests
129+
id: run-tests
130+
env:
131+
SCALR_ADDRESS: ${{ steps.create.outputs.host }}
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }}
134+
TEST_AWS_SECRET_KEY: ${{ secrets.TEST_AWS_SECRET_KEY }}
135+
TEST_AWS_ROLE_ARN: ${{ secrets.TEST_AWS_ROLE_ARN }}
136+
TEST_AWS_EXTERNAL_ID: ${{ secrets.TEST_AWS_EXTERNAL_ID }}
137+
TEST_ARM_CLIENT_ID: ${{ secrets.TEST_ARM_CLIENT_ID }}
138+
TEST_ARM_CLIENT_SECRET: ${{ secrets.TEST_ARM_CLIENT_SECRET }}
139+
TEST_ARM_TENANT_ID: ${{ secrets.TEST_ARM_TENANT_ID }}
140+
TEST_ARM_SUBSCRIPTION_ID: ${{ secrets.TEST_ARM_SUBSCRIPTION_ID }}
141+
run: make test
142+
- name: Set commit status after tests
143+
if: ${{ always() && (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') }}
144+
uses: actions/github-script@v3
145+
with:
146+
github-token: ${{ secrets.GH_PAT }}
147+
script: |
148+
github.repos.createCommitStatus({
149+
owner: 'Scalr',
150+
repo: '${{ inputs.repo }}',
151+
sha: '${{ inputs.pr_head_sha }}',
152+
state: '${{ steps.run-tests.outcome }}',
153+
description: 'go-scalr tests result: ${{ steps.run-tests.outcome }}',
154+
context: 'go-scalr',
155+
target_url: '${{ steps.get-job-id.outputs.html_url }}',
156+
})
157+
- name: Set commit status on interrupted workflow
158+
if: ${{ always() && steps.run-tests.outcome != 'failure' && steps.run-tests.outcome != 'success' }}
159+
uses: actions/github-script@v3
160+
with:
161+
github-token: ${{ secrets.GH_TOKEN }}
162+
script: |
163+
github.repos.createCommitStatus({
164+
owner: 'Scalr',
165+
repo: '${{ inputs.repo }}',
166+
sha: '${{ inputs.pr_head_sha }}',
167+
state: 'error',
168+
description: 'go-scalr workflow was interrupted',
169+
context: 'go-scalr',
170+
target_url: '${{ steps.get-job-id.outputs.html_url }}',
171+
})
172+
- name: Add comment on failed tests
173+
if: ${{ always() && steps.run-tests.outcome == 'failure' }}
174+
uses: actions/github-script@v5
175+
with:
176+
script: |
177+
const issue_number = ${{ inputs.pr_id }};
178+
const owner = 'Scalr';
179+
const repo = '${{ inputs.repo }}';
180+
const message = '**go-scalr tests failed**\nJob url ${{ steps.get-job-id.outputs.html_url }}';
181+
await github.rest.issues.createComment({owner, repo, issue_number, body: message});
182+
github-token: ${{ secrets.GH_PAT }}
183+
- name: Delete container
184+
id: delete
185+
if: ${{ always() }}
186+
shell: bash
187+
run: |
188+
docker run --rm \
189+
-w /fatmouse \
190+
-v $PWD/fatmouse:/fatmouse \
191+
-v ~/.scalr-labs:/etc/scalr-labs \
192+
fatmouse/python-builder:master \
193+
python -u clickfile.py te rm \
194+
--no-wait ${{ env.RUN_TAG }}

0 commit comments

Comments
 (0)