forked from tazama-lf/event-director
-
Notifications
You must be signed in to change notification settings - Fork 0
248 lines (221 loc) · 9.91 KB
/
node.js.yml
File metadata and controls
248 lines (221 loc) · 9.91 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI
env:
NODE_ENV: 'dev'
STARTUP_TYPE: 'nats'
SERVER_URL: 'nats://localhost:4222'
ACK_POLICY: 'None'
PRODUCER_STREAM: 'temp-rule-sub'
CONSUMER_STREAM: 'CRSP'
STREAM_SUBJECT:
APM_ACTIVE: false
APM_LOGGING: false
FUNCTION_NAME: ${{ github.event.repository.name }}
REDIS_DB: 0
REDIS_AUTH:
REDIS_SERVERS: '[{"host":"127.0.0.1", "port":6379}]'
REDIS_IS_CLUSTER: false
DATABASE_URL: 'http://localhost:8529/'
DATABASE_USER: 'root'
DATABASE_PASSWORD:
DATABASE_NAME: 'networkmap'
REPO_NAME: 'performance-benchmark'
GH_TOKEN: '${{ secrets.GH_WRITE_TOKEN }}'
NPM_SCOPE: "@frmscoe"
NPM_REGISTRY: "https://npm.pkg.github.com/"
ENV_NEWMAN: https://raw.githubusercontent.com/frmscoe/postman/indexes/environments/Ekuta-LOCAL.postman_environment.json
THRESHOLD: 5
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
outputs:
responseAverage: ${{ steps.newman_test.outputs.responseAverage }}
responseMin: ${{ steps.newman_test.outputs.responseMin }}
responseMax: ${{ steps.newman_test.outputs.responseMax }}
responseSd: ${{ steps.newman_test.outputs.responseSd }}
numberOfTest: ${{ steps.newman_test.outputs.numberOfTest }}
name: integration test
permissions:
packages: write
contents: read
strategy:
matrix:
node-version: [20]
redis-version: [6]
steps:
- uses: actions/checkout@v4
- name: Start Arango
uses: xinova/arangodb-action@v1
with:
arangodb version: 'latest'
- name: Setup Arango
run: newman run https://raw.githubusercontent.com/frmscoe/postman/indexes/ArangoDB%20Setup.json -e ${{ env.ENV_NEWMAN }} --timeout-request 10200
- name: Startup Nats
uses: onichandame/nats-action@master
with:
port: 4222
- name: Startup Redis
uses: supercharge/redis-github-action@1.7.0
with:
redis-version: ${{ matrix.redis-version }}
- name: StartUp Nats-Rest Proxy
run: docker pull ghcr.io/frmscoe/nats-utilities:latest && docker run --network=host -e NODE_ENV='dev' ghcr.io/frmscoe/nats-utilities:latest &
- name: Setup Node.js (.npmrc)
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://npm.pkg.github.com/
scope: '@frmscoe'
- name: Install dependencies
run: npm ci
- name: Processor Build
run: npm run build
- name: Processor Start
run: npm run start &
- name: Test Processor
run: newman run https://raw.githubusercontent.com/frmscoe/postman/main/micro_processors/ChannelRouterSetupProcessor_Proxy_Test.postman_collection.json -e ${{ env.ENV_NEWMAN }} --timeout-request 10200 -r json --reporter-json-export fullReport.json
- name: Extract Specific Field
id: newman_test
run: |
echo "##[set-output name=numberOfTest]$(jq -r '.run.stats.tests.total' fullReport.json)"
echo "##[set-output name=responseSd]$(jq -r '.run.timings.responseSd' fullReport.json)"
echo "##[set-output name=responseMax]$(jq -r '.run.timings.responseMax' fullReport.json)"
echo "##[set-output name=responseMin]$(jq -r '.run.timings.responseMin' fullReport.json)"
echo "##[set-output name=responseAverage]$(jq -r '.run.timings.responseAverage' fullReport.json)"
- name: Upload Results
uses: actions/upload-artifact@v3
with:
name: Full_Report.json
path: fullReport.json
pastbench:
runs-on: ubuntu-latest
outputs:
responseMax: ${{ steps.pre_test.outputs.responseMax }}
responseAverage: ${{ steps.pre_test.outputs.responseAverage }}
responseMin: ${{ steps.pre_test.outputs.responseMin }}
numberOfTest: ${{ steps.pre_test.outputs.numberOfTest }}
author: ${{ steps.pre_test.outputs.author }}
updatedAt: ${{ steps.pre_test.outputs.updatedAt }}
prNumber: ${{ steps.pre_test.outputs.prNumber }}
steps:
- name: Clone repo
run: |
git clone https://user:$GH_TOKEN@github.com/${{ github.repository_owner }}/${{ env.REPO_NAME }}
- name: Extract data
id: pre_test
run: |
cd ${{ env.REPO_NAME }}
input=$(tail -n 1 "${{ github.event.repository.name }}".csv)
echo "##[set-output name=responseMax]$(echo "$input" | awk -F ';' '{print $1}')"
echo "##[set-output name=responseAverage]$(echo "$input" | awk -F ';' '{print $2}')"
echo "##[set-output name=responseMin]$(echo "$input" | awk -F ';' '{print $3}')"
echo "##[set-output name=numberOfTest]$(echo "$input" | awk -F ';' '{print $4}')"
echo "##[set-output name=author]$(echo "$input" | awk -F ';' '{print $5}')"
echo "##[set-output name=updatedAt]$(echo "$input" | awk -F ';' '{print $6}')"
echo "##[set-output name=prNumber]$(echo "$input" | awk -F ';' '{print $7}')"
output:
needs: [build, pastbench]
runs-on: ubuntu-latest
steps:
- name: Comment on PR
run: |
difference=$((${{ needs.pastbench.outputs.responseMax }} - ${{ needs.build.outputs.responseMax }}))
if [ $difference -gt $THRESHOLD ]; then
COMMENT="✅ Performance improved"
elif [ $difference -ge 0 ]; then
COMMENT="✔️ Performance might have improved"
elif [ $difference -gt -$THRESHOLD ]; then
COMMENT="⚠️ Performance might have declined"
else
COMMENT="❌ Performance declined"
fi
COMMENT_BODY="🧪 <b>Newman Test Results<b/> <br /> $COMMENT <br /><br />Current number of tests is ${{ needs.build.outputs.numberOfTest }} and previous was ${{ needs.pastbench.outputs.numberOfTest }} <br /><br />Response stats<blockquote> <li>Current response average is ${{ needs.build.outputs.responseAverage }}ms and previous was ${{ needs.pastbench.outputs.responseAverage }}ms <br /><li>Current response min is ${{ needs.build.outputs.responseMin }}ms and previous was ${{ needs.pastbench.outputs.responseMin }}ms <br /><li>Current response max is ${{ needs.build.outputs.responseMax }}ms and previous was ${{ needs.pastbench.outputs.responseMax }}ms <br /><li>Response standard deviation ${{ needs.build.outputs.responseSd }}ms <br /><br /> Previous PR was merged by ${{ needs.pastbench.outputs.author }} and Pull request number is #${{ needs.pastbench.outputs.prNumber }} at ${{ needs.pastbench.outputs.updatedAt }}"
API_URL="https://api.github.com/repos/${{github.repository}}/issues/${{github.event.number}}/comments"
curl -X POST \
-H "Authorization: Bearer ${{ env.GH_TOKEN }}" \
-H "Content-Type: application/json" \
--data-raw "{\"body\":\"$COMMENT_BODY\"}" \
$API_URL
store:
needs: build
runs-on: ubuntu-latest
steps:
- name: Store data
run: |
# GitHub repository details
repo_owner="${{ github.repository_owner }}"
repo_name="${{ env.REPO_NAME }}"
branch_name="temp-holder"
file_path="${{ env.FUNCTION_NAME }}".csv
# Personal access token with repo scope
access_token="${{ env.GH_TOKEN }}"
new_content="${{ needs.build.outputs.responseMax }};${{ needs.build.outputs.responseAverage }};${{ needs.build.outputs.responseMin }};${{ needs.build.outputs.numberOfTest }};${{ github.actor }};${{ github.event.pull_request.updated_at }};${{ github.event.number}}"
updated_content="$new_content"
updated_content_base64=$(echo -n "$updated_content" | base64)
# Get the current content SHA
current_content_sha=$(curl -s -H "Authorization: token $access_token" \
"https://api.github.com/repos/$repo_owner/$repo_name/contents/$file_path?ref=$branch_name" \
| jq -r '.sha')
request_payload=$(cat <<EOF
{
"message": "#${{ github.event.number}} Updated file via API",
"content": "$updated_content_base64",
"sha": "$current_content_sha",
"branch": "$branch_name"
}
EOF
)
curl -L -X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $access_token" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$repo_owner/$repo_name/contents/$file_path" \
-d "$request_payload"
test:
runs-on: ubuntu-latest
name: unit tests
strategy:
matrix:
node-version: [20]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
registry-url: ${{ env.NPM_REGISTRY }}
scope: ${{ env.NPM_SCOPE }}
- name: Install dependencies
run: npm ci
- name: Run test
run: npm run test
env:
NODE_ENV: 'test'
lint:
runs-on: ubuntu-latest
name: check style
strategy:
matrix:
node-version: [20]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
registry-url: ${{ env.NPM_REGISTRY }}
scope: ${{ env.NPM_SCOPE }}
- name: Install dependencies
run: npm ci
- name: Check linting
run: npm run lint