Update security-gates.yml #19
This file contains 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: security-gates | |
# Controls when the workflow will run | |
on: | |
workflow_call: | |
push: | |
branches: [ "main", "master" ] | |
pull_request: | |
branches: [ "main", "master" ] | |
jobs: | |
visibility-check: | |
outputs: | |
visibility: ${{ steps.drv.outputs.visibility }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Determine repository visibility | |
id: drv | |
run: | | |
visibility=$(gh api /repos/$GITHUB_REPOSITORY --jq '.visibility') | |
echo "visibility=$visibility" >> $GITHUB_OUTPUT | |
env: | |
GH_TOKEN: ${{ github.token }} | |
gitleaks: | |
name: gitleaks | |
needs: visibility-check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: prepare-gitleaks | |
run: | | |
arc=$(uname -p) | |
[ "$arc" = "x86_64" ] && export arc="x64" || echo "$arc" | |
os=$(uname -s | tr '[:upper:]' '[:lower:]' ) | |
gitleaksVersion="8.22.1" | |
gl_full=$(printf "gitleaks_%s_%s_%s.tar.gz" "$gitleaksVersion" "$os" "$arc") | |
gl_download_link=$(printf "https://github.com/gitleaks/gitleaks/releases/download/v%s/%s" "$gitleaksVersion" "$gl_full") | |
wget $gl_download_link -q | |
tar -xzf $gl_full | |
- name: gitleaks-scan | |
run: | | |
if [ $VISIBILITY == "public" ]; then | |
./gitleaks detect -f sarif -r gitleaks.sarif --redact --exit-code 0 | |
else | |
./gitleaks detect --redact -v --exit-code 0 | |
fi | |
env: | |
VISIBILITY: ${{ needs.visibility-check.outputs.visibility }} | |
- name: gitleaks-result-upload | |
if: needs.visibility-check.outputs.visibility == 'public' | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: gitleaks.sarif | |
semgrep: | |
name: semgrep | |
needs: visibility-check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: prepare-semgrep | |
run: | | |
python3 -m pip install semgrep | |
- name: semgrep-scan | |
run: | | |
if [ $VISIBILITY == "public" ]; then | |
semgrep ci --config=auto --sarif --output=semgrep.sarif || true | |
else | |
semgrep ci --config=auto --text || true | |
fi | |
env: | |
VISIBILITY: ${{ needs.visibility-check.outputs.visibility }} | |
- name: semgrep-result-upload | |
if: needs.visibility-check.outputs.visibility == 'public' | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: semgrep.sarif | |
sbom-scan: | |
name: grype-sbom | |
needs: visibility-check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: anchore/scan-action@v3 | |
id: scan | |
if: needs.visibility-check.outputs.visibility == 'public' | |
with: | |
path: "." | |
output-format: sarif | |
fail-build: false | |
- uses: anchore/scan-action@v3 | |
id: scan-private | |
if: needs.visibility-check.outputs.visibility == 'private' | |
with: | |
path: "." | |
output-format: table | |
fail-build: false | |
- name: sbom-result-upload | |
if: needs.visibility-check.outputs.visibility == 'public' | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: ${{ steps.scan.outputs.sarif }} |