Skip to content

Update security-checks.yml #6

Update security-checks.yml

Update security-checks.yml #6

name: "Security Checks Workflows"
on:
pull_request:
branches: [main]
push:
branches: [main]
permissions:
contents: read
security-events: write
jobs:
codeql-analysis:
name: "CodeQL Analysis"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: 'javascript'
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
output: "./codeql-results.sarif" # Save the SARIF report to the workspace
- name: Generate Markdown from SARIF
run: |
echo "# CodeQL Analysis Report" > codeql-report.md
echo "## Detected Vulnerabilities" >> codeql-report.md
vulnerabilities=$(jq -r '.runs[].results[] | "\n### \(.ruleId)\n**File:** \(.locations[].physicalLocation.artifactLocation.uri)\n**Line:** \(.locations[].physicalLocation.region.startLine)\n**Message:** \(.message.text)"' codeql-results.sarif)
echo "$vulnerabilities" >> codeql-report.md
gitleaks-scan:
name: "Gitleaks Secrets Scan"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Gitleaks scan
uses: gitleaks/gitleaks-action@v2
with:
args: '--report-format=json --report-path=gitleaks-report.json'
- name: Convert Gitleaks JSON Report to Markdown
run: |
echo "# Gitleaks Secrets Report" > gitleaks-report.md
echo "## Detected Secrets" >> gitleaks-report.md
secrets=$(jq -r '.[] | "\n### \(.Description)\n**File:** \(.File)\n**Line:** \(.StartLine)\n**Secret:** \(.Secret)"' gitleaks-report.json)
echo "$secrets" >> gitleaks-report.md
create-issue-on-failure:
if: ${{ failure() }}
name: "Create GitHub Issue if Security Check Fails"
runs-on: ubuntu-latest
steps:
- name: Create failure log file
run: |
echo "# Security Check Failure" > failure_log.txt
echo "One or more security checks failed. Please review the following reports for more details:" >> failure_log.txt
cat codeql-report.md >> failure_log.txt || true
cat gitleaks-report.md >> failure_log.txt || true
- name: Create GitHub issue on failure
uses: peter-evans/create-issue-from-file@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Security Check Failure: ${{ github.workflow }}"
content-filepath: failure_log.txt