Skip to content

Commit cc12e25

Browse files
Merge pull request #2107 from RedisInsight/build/feature/RI-4462_Add_virus_check_for_releases
#RI-4462 - [CircleCI] Add Virus check to release branch builds
2 parents ded43a6 + 01e39b2 commit cc12e25

File tree

2 files changed

+157
-16
lines changed

2 files changed

+157
-16
lines changed

.circleci/config.yml

Lines changed: 115 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,29 @@ aliases:
2828
$filePathWithQuotes = '"{0}"' -f $filePath
2929
& "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86\signtool.exe" sign /a /sm /n "Redis Labs Inc." /fd sha256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /v $FilePathWithQuotes
3030
shell: powershell.exe
31-
scan: &scan
31+
fileScan: &fileScan
3232
run:
33-
name: Virustotal scan
34-
command: &virusscan |
33+
name: Virustotal file scan
34+
command: &virusfilescan |
3535
uploadUrl=$(curl -sq -XGET https://www.virustotal.com/api/v3/files/upload_url -H "x-apikey: $VIRUSTOTAL_API_KEY" | jq -r '.data')
3636
uploadFile=$("/usr/bin/find" /tmp/release -name ${FILE_NAME})
3737
echo "File to upload: ${uploadFile}"
3838
analysedId=$(curl -sq -XPOST "${uploadUrl}" -H "x-apikey: $VIRUSTOTAL_API_KEY" --form file=@"${uploadFile}" | jq -r '.data.id')
39+
if [ $analysedId == "null" ]; then
40+
echo 'Status is null, something went wrong'; exit 1;
41+
fi
42+
echo "export ANALYZED_ID=${analysedId}" >> $BASH_ENV
43+
echo "Virustotal Analyzed id: ${analysedId}"
44+
sleep 10
45+
shell: /bin/bash
46+
urlScan: &urlScan
47+
run:
48+
name: Virustotal url scan
49+
command: &virusurlscan |
50+
echo "Url to check: ${URL}"
51+
52+
analysedId=$(curl -sq -XPOST https://www.virustotal.com/api/v3/urls -H "x-apikey: $VIRUSTOTAL_API_KEY" --form url=${URL} | jq -r '.data.id')
53+
3954
if [ $analysedId == "null" ]; then
4055
echo 'Status is null, something went wrong'; exit 1;
4156
fi
@@ -76,13 +91,32 @@ aliases:
7691
echo "Results:"
7792
echo "analazedHarmless: ${analazedHarmless}, analazedMalicious: ${analazedMalicious}, analazedSuspicious: ${analazedSuspicious}"
7893

79-
if [ "$analazedHarmless" != "0" ] || [ "$analazedMalicious" != "0" ] || [ "$analazedSuspicious" != "0" ]; then
80-
echo 'Found dangers'; exit 1;
94+
if [ "$analazedMalicious" != "0" ] || [ "$analazedSuspicious" != "0" ]; then
95+
echo "export VIRUS_CHECK_FAILED=true" >> $BASH_ENV
96+
echo 'Found dangers'; exit 0;
8197
fi
8298

99+
echo "export VIRUS_CHECK_FAILED=false" >> $BASH_ENV
100+
echo "export SKIP_VIRUSTOTAL_REPORT=true" >> $BASH_ENV
83101
echo 'Passed';
84102
shell: /bin/bash
85103
no_output_timeout: 15m
104+
virustotalReport: &virustotalReport
105+
run:
106+
name: Virustotal slack report
107+
command: &virusreport |
108+
if [ "$SKIP_VIRUSTOTAL_REPORT" == "true" ]; then
109+
exit 0;
110+
fi
111+
112+
FILE_NAME=virustotal.report.json
113+
BUILD_NAME=$BUILD_NAME FILE_NAME=$FILE_NAME VIRUS_CHECK_FAILED=$VIRUS_CHECK_FAILED node .circleci/virustotal-report.js &&
114+
curl -H "Content-type: application/json" --data @$FILE_NAME -H "Authorization: Bearer ${SLACK_TEST_REPORT_KEY}" -X POST https://slack.com/api/chat.postMessage
115+
116+
if [ "$VIRUS_CHECK_FAILED" == "true" ]; then
117+
echo 'Found dangers'; exit 1;
118+
fi
119+
shell: /bin/bash
86120
iTestsNames: &iTestsNames
87121
- oss-st-5 # OSS Standalone v5
88122
- oss-st-5-pass # OSS Standalone v5 with admin pass required
@@ -612,6 +646,7 @@ jobs:
612646
613647
UPGRADES_LINK='' SEGMENT_WRITE_KEY='' yarn package:stage && yarn package:mas
614648
rm -rf release/mac
649+
mv release/mas-universal/RedisInsight-mac-universal-mas.pkg release/RedisInsight-mac-universal-mas.pkg
615650
no_output_timeout: 60m
616651

617652
- run:
@@ -625,7 +660,7 @@ jobs:
625660
- release/RedisInsight*.zip
626661
- release/RedisInsight*.dmg
627662
- release/RedisInsight*.dmg.blockmap
628-
- release/**/*.pkg
663+
- release/RedisInsight*.pkg
629664
- release/*-mac.yml
630665
- release/redisstack
631666
windows:
@@ -674,7 +709,7 @@ jobs:
674709
- release/RedisInsight*.exe
675710
- release/RedisInsight*.exe.blockmap
676711
- release/*.yml
677-
virustotal:
712+
virustotal-file:
678713
executor: linux-executor
679714
parameters:
680715
ext:
@@ -688,8 +723,35 @@ jobs:
688723
name: export FILE_NAME environment variable
689724
command: |
690725
echo 'export FILE_NAME="RedisInsight*<< parameters.ext >>"' >> $BASH_ENV
691-
- <<: *scan
726+
- <<: *fileScan
692727
- <<: *validate
728+
virustotal-url:
729+
executor: linux-executor
730+
parameters:
731+
fileName:
732+
description: File name
733+
type: string
734+
steps:
735+
- checkout
736+
- run:
737+
name: export URL environment variable
738+
command: |
739+
echo 'export URL="https://download.redisinsight.redis.com/latest/<< parameters.fileName >>"' >> $BASH_ENV
740+
echo 'export BUILD_NAME="<< parameters.fileName >>"' >> $BASH_ENV
741+
- <<: *urlScan
742+
- <<: *validate
743+
- <<: *virustotalReport
744+
745+
virustotal-report:
746+
executor: linux-executor
747+
steps:
748+
- checkout
749+
- run:
750+
name: Send virustotal passed report
751+
command: |
752+
echo 'export VIRUS_CHECK_FAILED=0' >> $BASH_ENV
753+
echo 'export SKIP_VIRUSTOTAL_REPORT=false' >> $BASH_ENV
754+
- <<: *virustotalReport
693755
docker:
694756
executor: linux-executor
695757
parameters:
@@ -1159,42 +1221,42 @@ workflows:
11591221
env: prod
11601222
requires: *prodElectronBuildRequires
11611223
# virus check all electron apps (prod)
1162-
- virustotal:
1224+
- virustotal-file:
11631225
name: Virus check - AppImage (prod)
11641226
ext: .AppImage
11651227
requires:
11661228
- Build app - Linux (prod)
1167-
- virustotal:
1229+
- virustotal-file:
11681230
name: Virus check - deb (prod)
11691231
ext: .deb
11701232
requires:
11711233
- Build app - Linux (prod)
1172-
- virustotal:
1234+
- virustotal-file:
11731235
name: Virus check - rpm (prod)
11741236
ext: .rpm
11751237
requires:
11761238
- Build app - Linux (prod)
1177-
- virustotal:
1239+
- virustotal-file:
11781240
name: Virus check - snap (prod)
11791241
ext: .snap
11801242
requires:
11811243
- Build app - Linux (prod)
1182-
- virustotal:
1244+
- virustotal-file:
11831245
name: Virus check x64 - dmg (prod)
11841246
ext: -x64.dmg
11851247
requires:
11861248
- Build app - MacOS (prod)
1187-
- virustotal:
1249+
- virustotal-file:
11881250
name: Virus check arm64 - dmg (prod)
11891251
ext: -arm64.dmg
11901252
requires:
11911253
- Build app - MacOS (prod)
1192-
- virustotal:
1254+
- virustotal-file:
11931255
name: Virus check MAS - pkg (prod)
11941256
ext: -mas.pkg
11951257
requires:
11961258
- Build app - MacOS (prod)
1197-
- virustotal:
1259+
- virustotal-file:
11981260
name: Virus check - exe (prod)
11991261
ext: .exe
12001262
requires:
@@ -1278,6 +1340,43 @@ workflows:
12781340
report: true
12791341
requires:
12801342
- Build app - Linux (stage)
1343+
1344+
- virustotal-url:
1345+
name: Virus check - AppImage (nightly)
1346+
fileName: RedisInsight-v2-linux-x86_64.AppImage
1347+
- virustotal-url:
1348+
name: Virus check - deb (nightly)
1349+
fileName: RedisInsight-v2-linux-amd64.deb
1350+
- virustotal-url:
1351+
name: Virus check - rpm (nightly)
1352+
fileName: RedisInsight-v2-linux-x86_64.rpm
1353+
- virustotal-url:
1354+
name: Virus check - snap (nightly)
1355+
fileName: RedisInsight-v2-linux-amd64.snap
1356+
- virustotal-url:
1357+
name: Virus check x64 - dmg (nightly)
1358+
fileName: RedisInsight-v2-mac-x64.dmg
1359+
- virustotal-url:
1360+
name: Virus check arm64 - dmg (nightly)
1361+
fileName: RedisInsight-v2-mac-arm64.dmg
1362+
- virustotal-url:
1363+
name: Virus check MAS - pkg (nightly)
1364+
fileName: RedisInsight-mac-universal-mas.pkg
1365+
- virustotal-url:
1366+
name: Virus check - exe (nightly)
1367+
fileName: RedisInsight-v2-win-installer.exe
1368+
- virustotal-report:
1369+
name: Virus check report (prod)
1370+
requires:
1371+
- Virus check - AppImage (nightly)
1372+
- Virus check - deb (nightly)
1373+
- Virus check - rpm (nightly)
1374+
- Virus check - snap (nightly)
1375+
- Virus check x64 - dmg (nightly)
1376+
- Virus check arm64 - dmg (nightly)
1377+
- Virus check MAS - pkg (nightly)
1378+
- Virus check - exe (nightly)
1379+
12811380
# # e2e desktop tests on exe build
12821381
# - e2e-exe:
12831382
# name: E2ETest (exe) - Nightly

.circleci/virustotal-report.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const fs = require('fs');
2+
3+
const fileName = process.env.FILE_NAME;
4+
const buildName = process.env.BUILD_NAME;
5+
const failed = process.env.VIRUS_CHECK_FAILED === 'true';
6+
7+
const results = {
8+
message: {
9+
text: `*Virustotal checks* (Branch: *${process.env.CIRCLE_BRANCH}*)` +
10+
`\n<https://app.circleci.com/pipelines/workflows/${process.env.CIRCLE_WORKFLOW_ID}|View on CircleCI>`,
11+
attachments: [],
12+
},
13+
};
14+
15+
const result = {
16+
color: '#36a64f',
17+
title: `Finished at: ${new Date().toISOString()}`,
18+
text: `All builds were passed via virustotal checks`,
19+
fields: [],
20+
};
21+
22+
if (failed) {
23+
results.passed = false;
24+
result.color = '#cc0000';
25+
result.text = 'Build had failed virustotal checks';
26+
result.fields.push({
27+
title: 'Failed build',
28+
value: buildName,
29+
short: true,
30+
});
31+
}
32+
33+
results.message.attachments.push(result);
34+
35+
if (failed === true) {
36+
results.message.text = '<!here> ' + results.message.text;
37+
}
38+
39+
fs.writeFileSync(fileName, JSON.stringify({
40+
channel: process.env.SLACK_VIRUSTOTAL_REPORT_CHANNEL,
41+
...results.message,
42+
}));

0 commit comments

Comments
 (0)