Skip to content

GHA version pinning (#23) #52

GHA version pinning (#23)

GHA version pinning (#23) #52

# This workflow checks out code, performs a Codacy security scan
# and integrates the results with the
# GitHub Advanced Security code scanning feature. For more information on
# the Codacy security scan action usage and parameters, see
# https://github.com/codacy/codacy-analysis-cli-action.
# For more information on Codacy Analysis CLI in general, see
# https://github.com/codacy/codacy-analysis-cli.
name: Codacy Security Scan
on:
push:
branches: [ "master", "main" ]
pull_request:
branches: [ "master", "main" ]
workflow_dispatch:
jobs:
codacy-security-scan:
name: Codacy Security Scan
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}
# Generate temporary self-signed TLS certificates required by the service
- name: Generate temporary TLS certificates
run: |
openssl req -x509 -newkey rsa:4096 -keyout sss-key.pem -out sss-cert.pem \
-sha256 -days 1 -nodes \
-subj "/C=US/ST=CI/L=CI/O=CI/CN=localhost"
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@9e45d0be1fc80fd2d86048032610422fdbcc6068 # pinned from codacy/codacy-analysis-cli-action@v4
with:
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
# You can also omit the token and run the tools that support default configurations
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647
# Split the multi-run SARIF into individual per-tool files to satisfy the
# requirement that each category upload contains only a single run.
# See: https://github.blog/changelog/2025-07-21-code-scanning-will-stop-combining-multiple-sarif-runs-uploaded-in-the-same-sarif-file/
- name: Split SARIF results into individual tool files
run: |
mkdir -p sarif-runs
count=$(jq '.runs | length' results.sarif)
for i in $(seq 0 $((count - 1))); do
tool=$(jq -r ".runs[$i].tool.driver.name" results.sarif \
| tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g')
jq --argjson i "$i" \
'{"version": .version, "$schema": .["$schema"], "runs": [.runs[$i]]}' \
results.sarif > "sarif-runs/${tool}.sarif"
done
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@5c8a8a642e79153f5d047b10ec1cba1d1cc65699 # pinned to github/codeql-action/upload-sarif v3.35.1 (intentionally using v3.x instead of v4.x)
with:
sarif_file: sarif-runs/
category: codacy