Skip to content

Commit 6b92c16

Browse files
committed
Initial workflow
1 parent 9f29853 commit 6b92c16

File tree

4 files changed

+626
-0
lines changed

4 files changed

+626
-0
lines changed

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "API Timer"
2+
description: "Ensure your API endpoints respond within a certain timeframe."
3+
inputs:
4+
time-limit:
5+
description: "The amount of ms before the workflow fails."
6+
required: true;
7+
default: 750
8+
base:
9+
description: "The base URL of your requests."
10+
required: true
11+
default: "https://example.com"
12+
endpoints:
13+
description: "The endpoints to test the response time of."
14+
required: true
15+
default: [
16+
"/test"
17+
]
18+

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
4+
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
5+
6+
(async () => {
7+
try {
8+
const timeLimit = core.getInput("time-limit");
9+
const base = core.getInput("base");
10+
const endpoints = core.getInput("endpoints");
11+
12+
for (endpoint of endpoints){
13+
const time = Date.now();
14+
await fetch(`${base}${endpoint}`).then(data => data.text());
15+
const timeTaken = Date.now() - time;
16+
if (timeTaken >= timeLimit){
17+
core.setFailed(`The endpoint ${endpoint} took ${timeTaken}ms to respond when limit was set to ${timeLimit}ms.`);
18+
}
19+
}
20+
} catch(err){
21+
core.setFailed(err.message);
22+
}
23+
})();

0 commit comments

Comments
 (0)