Skip to content

Commit 92771e2

Browse files
ihudakclaude
andcommitted
ci: skip security scans gracefully when secrets are unavailable
The Snyk and SonarCloud workflows were failing on every run for auth/config reasons, not code: - Snyk hard-failed with 401 Unauthorized because no SNYK_TOKEN secret is configured. Guard the scan on a job-level SNYK_TOKEN env so a missing token skips the scan (with a "Snyk Unavailable" notice) instead of failing the job. - SonarCloud reported misleading green checks on Dependabot PRs (which cannot access repository secrets, so the scan was silently skipped), while pushes to main failed against an unauthorized token. Skip the job entirely for Dependabot so PR checks no longer masquerade as passing; pushes to main and normal PRs still run the real scan. The scans themselves still require valid secrets to be configured (see PR description). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7a09b85 commit 92771e2

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

.github/workflows/snyk.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414
# Requires SNYK_TOKEN to be added as a repository secret:
1515
# Settings → Secrets and variables → Actions → New repository secret
16+
# When the secret is absent (e.g. forks or Dependabot PRs, which do not
17+
# receive repository secrets) the scan is skipped instead of failing with
18+
# a 401 Unauthorized.
19+
env:
20+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
1621
steps:
1722
- uses: actions/checkout@v7
1823

@@ -21,8 +26,13 @@ jobs:
2126
go-version-file: go.mod
2227

2328
- name: Run Snyk to check for vulnerabilities
29+
if: env.SNYK_TOKEN != ''
2430
uses: snyk/actions/golang@master
2531
env:
26-
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
32+
SNYK_TOKEN: ${{ env.SNYK_TOKEN }}
2733
with:
2834
args: --severity-threshold=high
35+
36+
- name: Snyk Unavailable
37+
if: env.SNYK_TOKEN == ''
38+
run: echo "Skipping Snyk scan because SNYK_TOKEN is not available in this workflow context."

.github/workflows/sonar.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88

99
jobs:
1010
sonar:
11+
# Dependabot PRs (and forks) cannot access repository secrets, so the
12+
# SonarCloud scan cannot run there. Skip the job for Dependabot instead of
13+
# reporting a misleading green "passing" check. Pushes to main and normal
14+
# PRs still run the real scan.
15+
if: github.actor != 'dependabot[bot]'
1116
runs-on: ubuntu-latest
1217
env:
1318
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)