Refine gitleaks download and extraction process in code analysis workflow by implementing dynamic asset URL retrieval, enhanced error handling for invalid downloads, and improved extraction methods.
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 3m16s

This commit is contained in:
Torsten Schulz (local)
2025-12-20 15:22:30 +01:00
parent dd21174f1d
commit 9e5ccbe8a3

View File

@@ -43,12 +43,31 @@ jobs:
- name: gitleaks (Secrets Scanning) - name: gitleaks (Secrets Scanning)
run: | run: |
curl -sSL -L https://github.com/gitleaks/gitleaks/releases/latest/download/gitleaks_linux_x64.tar.gz -o gitleaks.tar.gz # Try to get the latest release asset URL
if [ ! -s gitleaks.tar.gz ] || file gitleaks.tar.gz | grep -q "HTML"; then ASSET_URL=$(curl -s https://api.github.com/repos/gitleaks/gitleaks/releases/latest | grep -o '"browser_download_url": "[^"]*linux_x64[^"]*"' | head -1 | cut -d'"' -f4)
echo "Error: Downloaded file is not a valid archive" if [ -z "$ASSET_URL" ]; then
# Fallback: construct URL manually
VERSION=$(curl -s https://api.github.com/repos/gitleaks/gitleaks/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
ASSET_URL="https://github.com/gitleaks/gitleaks/releases/download/${VERSION}/gitleaks_${VERSION}_linux_x64.tar.gz"
fi
echo "Downloading from: $ASSET_URL"
curl -sSL -L "$ASSET_URL" -o gitleaks.tar.gz
# Check if download was successful and file is not HTML
if [ ! -s gitleaks.tar.gz ] || head -1 gitleaks.tar.gz | grep -q "<!DOCTYPE html"; then
echo "Error: Downloaded file is not a valid archive (might be HTML page)"
head -5 gitleaks.tar.gz
exit 1
fi
# Try different extraction methods
if tar -tzf gitleaks.tar.gz >/dev/null 2>&1; then
tar -xzf gitleaks.tar.gz
elif tar -tf gitleaks.tar.gz >/dev/null 2>&1; then
tar -xf gitleaks.tar.gz
else
echo "Error: Cannot extract archive. File type:"
file gitleaks.tar.gz
exit 1 exit 1
fi fi
tar -xzf gitleaks.tar.gz 2>/dev/null || tar -xf gitleaks.tar.gz || (echo "Failed to extract archive" && exit 1)
chmod +x gitleaks chmod +x gitleaks
./gitleaks detect --source . --no-git --redact --exit-code 1 ./gitleaks detect --source . --no-git --redact --exit-code 1
rm -f gitleaks.tar.gz rm -f gitleaks.tar.gz