-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (109 loc) · 3.71 KB
/
Copy pathsnyk.yml
File metadata and controls
128 lines (109 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Snyk Security
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
schedule:
# Run monthly on the 1st at 8:00 AM UTC (free tier limit)
- cron: '0 8 1 * *'
workflow_dispatch:
jobs:
snyk-info:
name: Snyk Configuration Check
runs-on: ubuntu-latest
steps:
- name: Check Snyk Token and provide info
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: |
if [ -z "$SNYK_TOKEN" ]; then
echo "ℹ️ Snyk security scanning is not configured."
echo "To enable Snyk scanning, add SNYK_TOKEN to repository secrets."
echo "Visit https://snyk.io to get your token."
echo "This is optional - the build will continue without security scanning."
else
echo "✅ Snyk token is configured. Security scanning will run on appropriate triggers."
fi
snyk:
name: Snyk Security Scan
runs-on: ubuntu-latest
# Run on PR, releases, and monthly schedule (free tier optimized)
if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: 21
distribution: 'temurin'
cache: maven
- name: Build project
run: mvn clean compile -DskipTests
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/maven@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high --sarif-file-output=snyk.sarif
- name: Upload Snyk results to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v4
if: always() && hashFiles('snyk.sarif') != ''
with:
sarif_file: snyk.sarif
snyk-monitor:
name: Snyk Monitor
runs-on: ubuntu-latest
# Only monitor on tags/releases to conserve free tier usage
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: 21
distribution: 'temurin'
cache: maven
- name: Build project
run: mvn clean compile -DskipTests
- name: Run Snyk monitor
uses: snyk/actions/maven@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
args: --project-name=inqwise-errors
snyk-container:
name: Snyk Container Scan
runs-on: ubuntu-latest
# Only run on releases and manual dispatch to conserve free tier
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: 21
distribution: 'temurin'
cache: maven
- name: Build JAR
run: mvn clean package -DskipTests
- name: Build Docker image for scanning
run: |
cat > Dockerfile.scan << EOF
FROM eclipse-temurin:21-jre-alpine
COPY target/inqwise-errors-*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
EOF
docker build -f Dockerfile.scan -t inqwise-errors:scan .
- name: Run Snyk to check Docker image for vulnerabilities
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: inqwise-errors:scan
args: --severity-threshold=high