Skip to content

Commit fc1d364

Browse files
authored
Notify JSCore chat when smoke tests complete (#5557)
1 parent 53a9263 commit fc1d364

File tree

2 files changed

+107
-2
lines changed

2 files changed

+107
-2
lines changed

.github/workflows/e2e-test.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: E2E Smoke Tests
22

3-
on: workflow_dispatch
3+
# Allows REST trigger. Currently triggered by release-cli script during a staging run.
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
versionOrTag:
8+
description: 'release version or tag'
9+
required: true
10+
default: 'next'
411

512
jobs:
613
test:
@@ -32,7 +39,8 @@ jobs:
3239
echo "export const config = $PROJECT_CONFIG; export const testAccount = $TEST_ACCOUNT" > firebase-config.js
3340
- name: Yarn install
3441
run: |
35-
yarn add firebase
42+
echo "Installing firebase@${{ github.event.inputs.versionOrTag }}"
43+
yarn add firebase@${{ github.event.inputs.versionOrTag }}
3644
yarn
3745
- name: Deploy "callTest" cloud function
3846
run: |
@@ -51,3 +59,17 @@ jobs:
5159
env:
5260
APP_CHECK_DEBUG_TOKEN: ${{ secrets.APP_CHECK_DEBUG_TOKEN }}
5361
run: xvfb-run yarn test:compat
62+
- name: Tests succeeded
63+
if: success()
64+
run: node scripts/ci/notify-test-result.js success
65+
env:
66+
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
67+
# run in root
68+
working-directory: '.'
69+
- name: Tests failed
70+
if: failure()
71+
run: node scripts/ci/notify-test-result.js fail
72+
env:
73+
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
74+
# run in root
75+
working-directory: '.'

scripts/ci/notify-test-result.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const https = require('https');
19+
20+
/**
21+
* Sends result of E2E staging test to JSCore chat.
22+
*/
23+
async function notifyTestResults() {
24+
// JSCore chat webhook URL.
25+
if (!process.env.WEBHOOK_URL) {
26+
console.log(`Couldn't find WEBHOOK_URL env variable.`);
27+
return;
28+
}
29+
30+
// URL of this workflow run.
31+
const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
32+
let status = 'did not log a status correctly';
33+
if (process.argv.includes('fail')) {
34+
status = 'failed';
35+
}
36+
if (process.argv.includes('success')) {
37+
status = 'succeeded';
38+
}
39+
40+
let message = `E2E Tests ${status}`;
41+
42+
// Add version if it can find it in the workflow_dispatch event data.
43+
if (process.env.GITHUB_EVENT_PATH) {
44+
const wrPayload = require(process.env.GITHUB_EVENT_PATH);
45+
if (wrPayload.inputs && wrPayload.inputs.versionOrTag) {
46+
message += ` for release ${wrPayload.inputs.versionOrTag}.`;
47+
} else {
48+
console.log(`Couldn't find versionOrTag in event payload.`);
49+
}
50+
} else {
51+
console.log(`Couldn't find event payload.`);
52+
}
53+
54+
message += ` ${workflowUrl}`;
55+
56+
const data = JSON.stringify({
57+
text: message
58+
});
59+
60+
const options = {
61+
method: 'POST',
62+
headers: {
63+
'Content-Type': 'application/json'
64+
}
65+
};
66+
67+
return new Promise((resolve, reject) => {
68+
console.log(`Sending message to chat: ${message}`);
69+
const req = https.request(process.env.WEBHOOK_URL, options, res => {
70+
res.on('data', d => {
71+
process.stdout.write(d);
72+
});
73+
res.on('end', resolve);
74+
});
75+
76+
req.on('error', error => reject(error));
77+
78+
req.write(data);
79+
req.end();
80+
});
81+
}
82+
83+
notifyTestResults();

0 commit comments

Comments
 (0)