Skip to content

Commit 6282ddd

Browse files
feat(release_create): add virustotal scanning (#13)
1 parent 58a32e0 commit 6282ddd

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ jobs:
9191
-e 's|\${ secrets.GH_BOT_NAME }|${{ secrets.GH_BOT_NAME }}|g' \
9292
-e 's|\${ secrets.GH_BOT_TOKEN }|${{ secrets.GH_BOT_TOKEN }}|g' \
9393
-e 's|\${ secrets.GITHUB_TOKEN }|${{ secrets.GITHUB_TOKEN }}|g' \
94+
-e 's|\${ secrets.VIRUSTOTAL_API_KEY }|${{ secrets.VIRUSTOTAL_API_KEY }}|g' \
9495
"with_params.json"
9596
9697
# Output the processed parameters

actions/release_create/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ steps:
3838
| sleepDuration | The duration to sleep in seconds before deleting tags. | `15` | `false` |
3939
| tag | The tag to create. | | `true` |
4040
| token | GitHub Token. | | `true` |
41+
| virustotal_api_key | The VirusTotal API key to use for scanning artifacts. | | `false` |
4142

4243
## See Also
4344

actions/release_create/action.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,53 @@ inputs:
5757
token:
5858
description: 'Github Token.'
5959
required: true
60+
virustotal_api_key:
61+
description: 'The VirusTotal API key to use for scanning the artifacts.'
62+
required: false
6063

6164
runs:
6265
using: "composite"
6366
steps:
67+
- name: VirusTotal
68+
if: inputs.virustotal_api_key != ''
69+
id: vt
70+
uses: cssnr/virustotal-action@v1.3.1
71+
with:
72+
file_globs: ${{ inputs.artifacts }}
73+
summary: true
74+
update_release: false
75+
vt_api_key: ${{ inputs.virustotal_api_key }}
76+
77+
- name: Format VirusTotal Results
78+
if: inputs.virustotal_api_key != ''
79+
id: format-vt
80+
shell: bash
81+
run: |
82+
# Create body file with original content
83+
cat > release_body.md << 'BODY_EOF'
84+
${{ inputs.body }}
85+
BODY_EOF
86+
87+
# If we have VT results, append them
88+
if [ -n '${{ steps.vt.outputs.json }}' ]; then
89+
# Add separator if body exists and isn't empty
90+
if [ -s release_body.md ] && [ "$(cat release_body.md | tr -d '[:space:]')" != "" ]; then
91+
echo "" >> release_body.md
92+
fi
93+
94+
# Append VirusTotal results
95+
echo "---" >> release_body.md
96+
echo "🛡️ **VirusTotal Results:**" >> release_body.md
97+
printf '%s\n' '${{ steps.vt.outputs.json }}' | jq -r '.[] | "- [\(.name)](\(.link))"' >> release_body.md
98+
fi
99+
100+
# Set output
101+
{
102+
echo "body<<EOF"
103+
cat release_body.md
104+
echo "EOF"
105+
} >> $GITHUB_OUTPUT
106+
64107
- name: Create/Update GitHub Release
65108
if: >-
66109
github.repository == 'LizardByte/actions' ||
@@ -70,7 +113,7 @@ runs:
70113
allowUpdates: ${{ inputs.allowUpdates }}
71114
artifactErrorsFailBuild: ${{ inputs.artifactErrorsFailBuild }}
72115
artifacts: ${{ inputs.artifacts }}
73-
body: ${{ inputs.body }}
116+
body: ${{ steps.format-vt.outputs.body || inputs.body }}
74117
commit: ${{ github.sha }}
75118
generateReleaseNotes: ${{ inputs.generateReleaseNotes }}
76119
name: ${{ inputs.name }}

actions/release_create/ci-matrix.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"runs-on": "ubuntu-latest",
55
"with": {
66
"allowUpdates": false,
7-
"artifacts": "",
7+
"artifacts": "dist/*",
88
"body": "Test from PR-${ github.event.pull_request.number }",
99
"generateReleaseNotes": false,
1010
"name": "pr-${ github.event.pull_request.number }-${ github.run_id }",
1111
"prerelease": true,
1212
"tag": "pr-${ github.event.pull_request.number }-${ github.run_id }",
13-
"token": "${ secrets.GH_BOT_TOKEN }"
13+
"token": "${ secrets.GH_BOT_TOKEN }",
14+
"virustotal_api_key": "${ secrets.VIRUSTOTAL_API_KEY }"
1415
}
1516
}
1617
]

actions/release_create/pre-ci.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Create a dummy binary file to simulate with virustotal scan
4+
5+
# Create output directory if it doesn't exist
6+
mkdir -p dist
7+
8+
# Create a simple dummy executable
9+
cat > dist/dummy-binary << 'EOF'
10+
#!/bin/bash
11+
echo "This is a dummy binary for VirusTotal testing"
12+
exit 0
13+
EOF
14+
15+
# Make it executable
16+
chmod +x dist/dummy-binary
17+
18+
# Validate the binary file was created successfully
19+
if [[ -f "dist/dummy-binary" && -x "dist/dummy-binary" ]]; then
20+
echo "Valid dummy binary created at dist/dummy-binary"
21+
echo "File size: $(stat -c%s dist/dummy-binary) bytes"
22+
echo "File type: $(file dist/dummy-binary)"
23+
else
24+
echo "Error: Failed to create valid dummy binary"
25+
exit 1
26+
fi

0 commit comments

Comments
 (0)