Skip to content

Commit

Permalink
feat: updated qa automated workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Homoakin619 committed Aug 24, 2024
1 parent 5a725e3 commit b0318a3
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/scheduled-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Scheduled Test

on:
schedule:
- cron: '* * * * *'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run a script
run: |
cd qa
chmod +x test.sh
./test.sh
16 changes: 0 additions & 16 deletions .github/workflows/test-cron.yaml

This file was deleted.

80 changes: 80 additions & 0 deletions qa/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
require('dotenv').config();

const resultFilePath = path.resolve(__dirname, 'result.json');

const postmanApiKey = process.env.POSTMAN_API_KEY;

const runTasks = async () => {
try {
console.log('Generating test reports...');

// Spawn a new process for running Newman tests
const newmanProcess = spawn('npx', [
'newman',
'run',
`https://api.getpostman.com/collections/37678338-b29374aa-a7b1-43e9-bdc8-fc3bcf39871b?apikey=${postmanApiKey}`,
'-e',
`https://api.getpostman.com/environments/37678787-5f6cbeff-c9d9-44c3-b670-7887cf48fc12?apikey=${postmanApiKey}`,
'--reporters',
'cli,json',
'--reporter-json-export',
resultFilePath,
]);

// Handle stdout
newmanProcess.stdout.on('data', data => {
console.log(`stdout: ${data}`);
});

// Handle stderr
newmanProcess.stderr.on('data', data => {
console.error(`stderr: ${data}`);
});

// Handle process close
newmanProcess.on('close', code => {
if (code !== 0) {
console.warn(`Newman process exited with code ${code}. There may be test failures.`);
}
console.log('Finished running tests and generating reports');

// Spawn a new process for compressing the report and making API requests
console.log('Running test result compression and API request...');

const compressProcess = spawn('node', ['compress_send.js']);

compressProcess.stdout.on('data', data => {
console.log(`stdout: ${data}`);
});

compressProcess.stderr.on('data', data => {
console.error(`stderr: ${data}`);
});

compressProcess.on('close', code => {
if (code !== 0) {
console.error(`Compression process exited with code ${code}`);
return;
}
console.log('Finished compressing test results and making API requests');

// Remove the result.json file after successful compression
fs.unlink(resultFilePath, err => {
if (err) {
console.error(`Error removing result.json: ${err.message}`);
return;
}
console.log('Successfully removed result.json');
});
});
});
} catch (error) {
console.error(`Error executing commands: ${error.message}`);
console.log(error.stack);
}
};

runTasks();
3 changes: 3 additions & 0 deletions qa/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm install dot-env
npm install newman
node ./index.js

0 comments on commit b0318a3

Please sign in to comment.