Update the Veracode CLI #107
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |