Skip to content

Notify JSCore chat when smoke tests complete #5557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: E2E Smoke Tests

on: workflow_dispatch
# Allows REST trigger. Currently triggered by release-cli script during a staging run.
on:
workflow_dispatch:
inputs:
versionOrTag:
description: 'release version or tag'
required: true
default: 'next'

jobs:
test:
Expand Down Expand Up @@ -32,7 +39,8 @@ jobs:
echo "export const config = $PROJECT_CONFIG; export const testAccount = $TEST_ACCOUNT" > firebase-config.js
- name: Yarn install
run: |
yarn add firebase
echo "Installing firebase@${{ github.event.inputs.versionOrTag }}"
yarn add firebase@${{ github.event.inputs.versionOrTag }}
yarn
- name: Deploy "callTest" cloud function
run: |
Expand All @@ -51,3 +59,17 @@ jobs:
env:
APP_CHECK_DEBUG_TOKEN: ${{ secrets.APP_CHECK_DEBUG_TOKEN }}
run: xvfb-run yarn test:compat
- name: Tests succeeded
if: success()
run: node scripts/ci/notify-test-result.js success
env:
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
# run in root
working-directory: '.'
- name: Tests failed
if: failure()
run: node scripts/ci/notify-test-result.js fail
env:
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
# run in root
working-directory: '.'
83 changes: 83 additions & 0 deletions scripts/ci/notify-test-result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const https = require('https');

/**
* Sends result of E2E staging test to JSCore chat.
*/
async function notifyTestResults() {
// JSCore chat webhook URL.
if (!process.env.WEBHOOK_URL) {
console.log(`Couldn't find WEBHOOK_URL env variable.`);
return;
}

// URL of this workflow run.
const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
let status = 'did not log a status correctly';
if (process.argv.includes('fail')) {
status = 'failed';
}
if (process.argv.includes('success')) {
status = 'succeeded';
}

let message = `E2E Tests ${status}`;

// Add version if it can find it in the workflow_dispatch event data.
if (process.env.GITHUB_EVENT_PATH) {
const wrPayload = require(process.env.GITHUB_EVENT_PATH);
if (wrPayload.inputs && wrPayload.inputs.versionOrTag) {
message += ` for release ${wrPayload.inputs.versionOrTag}.`;
} else {
console.log(`Couldn't find versionOrTag in event payload.`);
}
} else {
console.log(`Couldn't find event payload.`);
}

message += ` ${workflowUrl}`;

const data = JSON.stringify({
text: message
});

const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};

return new Promise((resolve, reject) => {
console.log(`Sending message to chat: ${message}`);
const req = https.request(process.env.WEBHOOK_URL, options, res => {
res.on('data', d => {
process.stdout.write(d);
});
res.on('end', resolve);
});

req.on('error', error => reject(error));

req.write(data);
req.end();
});
}

notifyTestResults();