-
Notifications
You must be signed in to change notification settings - Fork 3
202 lines (173 loc) · 7.09 KB
/
pr_validate.yaml
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
202
name: Validate pull request
on:
pull_request:
types: [ opened, reopened, edited ]
jobs:
# BEWARE: GitHub uses Microsoft-style line endings (CRLF)
# instead of Unix-style (LF) interally for things like PR text.
#
# You MUST check for `\r\n` as the line separator instead of `\n`
# in this workflow.
lint-pr-body:
name: Lint pull request body
runs-on: ubuntu-20.04
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
outputs:
is-staging-na: ${{ steps.extract-staging.outputs.is-staging-na }}
sandbox: ${{ steps.extract-staging.outputs.sandbox }}
is-e2e-box-checked: ${{ steps.check-e2e-checkbox.outcome }}
steps:
- id: install
name: Install requirements
run: |-
sudo apt-get update -y
sudo apt-get install -y pcregrep
- id: extract-staging
name: Check staging URL
run: |-
REGEX="#### Link to staging deployment URL \(or set N\/A\)\s?\r\n(https:\/\/ui-(.+)\.scp-staging\.biomage\.net|https:\/\/ui-(.+)\.staging\.single-cell-platform\.net|N\/A)"
echo "REGEX to test against:"
echo $REGEX
echo "Now looking at regex result:"
URL=$(pcregrep -o1 -M "$REGEX" <<\EOF
${{ github.event.pull_request.body }}
EOF
)
IS_STAGING_NA='false'
if [ $URL = 'N/A' ]; then
IS_STAGING_NA='true'
fi
echo "Is staging N/A?"
echo $IS_STAGING_NA
echo "is-staging-na=$IS_STAGING_NA" >> $GITHUB_OUTPUT
echo "Full URL:"
echo $URL
echo "url=$URL" >> $GITHUB_OUTPUT
SANDBOX=$(pcregrep -o2 -M "$REGEX" <<\EOF
${{ github.event.pull_request.body }}
EOF
)
echo "Extracted sandbox:"
echo $SANDBOX
echo "sandbox=$SANDBOX" >> $GITHUB_OUTPUT
- id: reach-staging
if: steps.extract-staging.outputs.url != 'N/A'
name: Attempt to reach staging environments
uses: nick-fields/retry@v2
with:
timeout_seconds: 30
max_attempts: 5
retry_on: error
command: curl -f ${{ steps.extract-staging.outputs.url }}
# Add jitter to break up correlated events.
on_retry_command: sleep $[($RANDOM % 10) + 5]s
- id: check-e2e-checkbox
name: Check if E2E testing is checked
continue-on-error: true
run: |-
REGEX="\[[Xx]\] Started end-to-end tests on the latest commit\."
pcregrep -o1 -M "$REGEX" <<\EOF
${{ github.event.pull_request.body }}
EOF
run-integration-tests:
name: Run integration tests
runs-on: ubuntu-20.04
needs: lint-pr-body
concurrency:
group: ${{ github.sha }}
steps:
- id: check-e2e-run
name: Check if E2E should run
run: |-
SHOULD_RUN_E2E='true'
SHOULD_CANCEL_E2E='false'
echo "Should E2E cancel?"
if [ "${{ needs.lint-pr-body.outputs.is-staging-na}}" = "false" ] && [ "${{ needs.lint-pr-body.outputs.is-e2e-box-checked }}" != "success" ]; then
SHOULD_CANCEL_E2E='true'
fi
echo $SHOULD_CANCEL_E2E
echo "Should E2E be run?"
if [ "${{ needs.lint-pr-body.outputs.is-staging-na}}" = 'true' ]; then
SHOULD_RUN_E2E='false'
fi
echo $SHOULD_RUN_E2E
echo "should-e2e-cancel=$SHOULD_CANCEL_E2E" >> $GITHUB_OUTPUT
echo "should-e2e-run=$SHOULD_RUN_E2E" >> $GITHUB_OUTPUT
- id: cancel
name: Cancel if staging is not N/A and box is not checked
if: steps.check-e2e-run.outputs.should-e2e-cancel == 'true'
uses: andymckay/[email protected]
- id: install
if: steps.check-e2e-run.outputs.should-e2e-run == 'true'
name: Install requirements
run: |-
sudo apt-get update -y
sudo apt-get install -y pcregrep
- id: extract-commit-details
if: steps.check-e2e-run.outputs.should-e2e-run == 'true'
name: Get details of last commit
run: |-
echo "SHA of latest GitHub branch commit:"
echo ${{ github.event.pull_request.head.sha }}
echo "github_sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
REPO_NAME=$(echo $GITHUB_REPOSITORY | awk -F '/' '{print $2}')
echo "Repo name:"
echo $REPO_NAME
echo "repo_name=$REPO_NAME" >> $GITHUB_OUTPUT
- id: extract-integration-test-ref
if: steps.check-e2e-run.outputs.should-e2e-run == 'true'
name: Get integration test ref
run: |-
REGEX="#### Integration test branch\s?\r\n(.+)\s?\r\n"
echo "REGEX to test against:"
echo $REGEX
echo "Now looking at regex result:"
INTEGRATION_TEST_REF=$(pcregrep -o1 -M "$REGEX" <<\EOF
${{ github.event.pull_request.body }}
EOF
)
echo "Ref given is $INTEGRATION_TEST_REF, setting it as is."
echo "ref=$INTEGRATION_TEST_REF" >> $GITHUB_OUTPUT
- id: run-integration-test
if: steps.check-e2e-run.outputs.should-e2e-run == 'true'
name: Run integration tests
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: Run end-to-end tests
repo: ${{ github.repository_owner }}/testing
token: ${{ secrets.API_TOKEN_GITHUB }}
ref: ${{ steps.extract-integration-test-ref.outputs.ref }}
inputs: '{ "environment": "staging", "ref": "${{ steps.extract-integration-test-ref.outputs.ref }}", "sandboxId": "${{needs.lint-pr-body.outputs.sandbox}}", "image_sha" : "${{ steps.extract-commit-details.outputs.github_sha }}", "namespace": "${{steps.extract-commit-details.outputs.repo_name}}-${{needs.lint-pr-body.outputs.sandbox}}" }'
- id: get-pr-body
if: failure()
name: Get the current PR body
uses: jwalton/gh-find-current-pr@v1
with:
state: open
- id: create-unchecked-pr-body
if: failure()
name: Create unchecked PR body
run: |-
UNCHECKED_BODY=$(sed 's/- \[[Xx]\] Started end-to-end tests on the latest commit\./- \[ \] Started end-to-end tests on the latest commit\./' <<\EOF
${{ steps.get-pr-body.outputs.body }}
EOF
)
echo "Unchecked PR body"
echo $UNCHECKED_BODY
# This sets multiline strings into the output variable
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
echo "body<<EOF" >> "$GITHUB_OUTPUT"
echo "$UNCHECKED_BODY" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- id: uncheck-integration-checkbox
if: failure()
name: Uncheck the integration checkbox
uses: tzkhan/pr-update-action@v2
with:
repo-token: "${{ secrets.API_TOKEN_GITHUB }}"
head-branch-regex: '${{ github.head_ref }}'
lowercase-branch: false
body-template: "${{ steps.create-unchecked-pr-body.outputs.body }}"
body-update-action: 'replace'