forked from veracode/github-actions-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (83 loc) · 3.79 KB
/
update-cli.yml
File metadata and controls
89 lines (83 loc) · 3.79 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
name: Update the Veracode CLI
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
jobs:
update-veracode-cli:
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Update Veracode CLI to latest version
run: |
cd helper/cli
# Check if any CLI files exist to determine local version
if ls veracode-cli_*_linux_x86.tar.gz 1> /dev/null 2>&1; then
cliFile=$(ls -1vr veracode-cli_*_linux_x86.tar.gz | head -n 1)
echo "Filename: $cliFile"
local_version="${cliFile#*_}"
local_version="${local_version%%_*}"
echo "Local version: $local_version"
else
local_version=""
echo "No local CLI files found - will download the latest version"
fi
curl -sSO https://tools.veracode.com/veracode-cli/LATEST_VERSION
latest_version=$(<"LATEST_VERSION")
echo "Latest version: $latest_version"
# Always clean up old versions (keep only the latest version)
echo "Cleaning up old CLI versions (keeping only $latest_version)..."
# Single loop to remove all files except the latest Linux and Windows versions
for file in veracode-cli_*; do
if [[ -f "$file" && "$file" != "veracode-cli_${latest_version}_linux_x86.tar.gz" && "$file" != "veracode-cli_${latest_version}_windows_x86.zip" && "$file" != "veracode-cli_${latest_version}_windows.ps1" ]]; then
# Additional check: if this is a PS1 file, only remove it if the corresponding ZIP exists
if [[ "$file" == *"_windows.ps1" ]]; then
expected_zip="veracode-cli_${latest_version}_windows_x86.zip"
if [[ -f "$expected_zip" ]]; then
echo "Removing old PS1 file: $file (ZIP version exists)"
git rm -f "$file" 2>/dev/null || rm -f "$file"
else
echo "Keeping PS1 file: $file (no ZIP version available yet)"
fi
else
echo "Removing old CLI file: $file"
git rm -f "$file" 2>/dev/null || rm -f "$file"
fi
fi
done
if [[ -n "$local_version" && "$local_version" == "$latest_version" ]]; then
echo "We already have the latest version ($local_version) - nothing to download"
rm -rf LATEST_VERSION
else
if [[ -n "$local_version" ]]; then
echo "There is a new version available (local: $local_version, latest: $latest_version)"
else
echo "No local version exists - downloading latest version ($latest_version)"
fi
# Download the new version (both Linux and Windows binaries)
linuxUrl="https://tools.veracode.com/veracode-cli/veracode-cli_${latest_version}_linux_x86.tar.gz"
windowsUrl="https://tools.veracode.com/veracode-cli/veracode-cli_${latest_version}_windows_x86.zip"
echo "Downloading Linux CLI: $linuxUrl"
curl -sSO $linuxUrl
echo "Downloading Windows CLI: $windowsUrl"
curl -sSO $windowsUrl
# Clean up temporary files
rm -rf LATEST_VERSION
fi
ls -la
- name: commit back to repo
run: |
git config --global user.name 'veracode'
git config --global user.email 'cli@veracode.com'
# Check if there are any changes
if [[ -n "$(git status --porcelain)" ]]; then
echo "Changes detected — committing and pushing latest CLI."
git add -A
git commit -m "New CLI Version"
git push --verbose
else
echo "No changes to commit."
fi