Skip to content

Commit 9d69875

Browse files
rishabh6788kaushalmahi12
authored andcommitted
add length check on comment body for benchmark workflow (opensearch-project#14834)
Signed-off-by: Rishabh Singh <[email protected]> Signed-off-by: Kaushal Kumar <[email protected]>
1 parent 2e31c78 commit 9d69875

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

.github/workflows/add-performance-comment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Performance Label Action
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [labeled]
66

77
jobs:

.github/workflows/benchmark-pull-request.yml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,41 @@ jobs:
2525
echo "USER_TAGS=pull_request_number:${{ github.event.issue.number }},repository:OpenSearch" >> $GITHUB_ENV
2626
- name: Check comment format
2727
id: check_comment
28-
run: |
29-
comment='${{ github.event.comment.body }}'
30-
if echo "$comment" | jq -e 'has("run-benchmark-test")'; then
31-
echo "Valid comment format detected, check if valid config id is provided"
32-
config_id=$(echo $comment | jq -r '.["run-benchmark-test"]')
33-
benchmark_configs=$(cat .github/benchmark-configs.json)
34-
if echo $benchmark_configs | jq -e --arg id "$config_id" 'has($id)' && echo "$benchmark_configs" | jq -e --arg version "$OPENSEARCH_MAJOR_VERSION" --arg id "$config_id" '.[$id].supported_major_versions | index($version) != null' > /dev/null; then
35-
echo $benchmark_configs | jq -r --arg id "$config_id" '.[$id]."cluster-benchmark-configs" | to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_ENV
36-
else
37-
echo "invalid=true" >> $GITHUB_OUTPUT
38-
fi
39-
else
40-
echo "invalid=true" >> $GITHUB_OUTPUT
41-
fi
28+
uses: actions/github-script@v6
29+
with:
30+
script: |
31+
const fs = require('fs');
32+
const comment = context.payload.comment.body;
33+
let commentJson;
34+
try {
35+
commentJson = JSON.parse(comment);
36+
} catch (error) {
37+
core.setOutput('invalid', 'true');
38+
return;
39+
}
40+
if (!commentJson.hasOwnProperty('run-benchmark-test')) {
41+
core.setOutput('invalid', 'true');
42+
return;
43+
}
44+
const configId = commentJson['run-benchmark-test'];
45+
let benchmarkConfigs;
46+
try {
47+
benchmarkConfigs = JSON.parse(fs.readFileSync('.github/benchmark-configs.json', 'utf8'));
48+
} catch (error) {
49+
core.setFailed('Failed to read benchmark-configs.json');
50+
return;
51+
}
52+
const openSearchMajorVersion = process.env.OPENSEARCH_MAJOR_VERSION;
53+
console.log('MAJOR_VERSION', openSearchMajorVersion)
54+
if (!benchmarkConfigs.hasOwnProperty(configId) ||
55+
!benchmarkConfigs[configId].supported_major_versions.includes(openSearchMajorVersion)) {
56+
core.setOutput('invalid', 'true');
57+
return;
58+
}
59+
const clusterBenchmarkConfigs = benchmarkConfigs[configId]['cluster-benchmark-configs'];
60+
for (const [key, value] of Object.entries(clusterBenchmarkConfigs)) {
61+
core.exportVariable(key, value);
62+
}
4263
- name: Post invalid format comment
4364
if: steps.check_comment.outputs.invalid == 'true'
4465
uses: actions/github-script@v6

0 commit comments

Comments
 (0)