Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit fcbf70f

Browse files
authored
docs: document github action caching (#6301)
1 parent 15e6413 commit fcbf70f

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
GitHub Action
2+
----------------
3+
4+
The following is an example of how one could cache the data directory using GitHub Actions.
5+
Note that this configuration is setup for Maven but could be altered to support gradle or
6+
even the CLI.
7+
8+
**WARNING** this configuration uses a single API key configured in secrets. If multiple actions
9+
use the same API Key you could hit the NVD rate limits.
10+
11+
12+
```yaml
13+
name: Vulnerability Scan
14+
15+
on:
16+
pull_request:
17+
workflow_dispatch:
18+
19+
jobs:
20+
owasp-scan:
21+
if: github.actor != 'dependabot[bot]'
22+
runs-on: ubuntu-20.04
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Set up JDK 17
27+
uses: actions/setup-java@v3
28+
with:
29+
java-version: 17
30+
distribution: 'adopt'
31+
server-id: github
32+
server-username: MAVEN_USERNAME
33+
server-password: MAVEN_PASSWORD
34+
cache: 'maven'
35+
36+
- name: Get Date
37+
id: get-date
38+
run: |
39+
echo "datetime=$(/bin/date -u "+%Y%m%d%H")" >> $GITHUB_OUTPUT
40+
shell: bash
41+
42+
- name: Restore cached Maven dependencies
43+
uses: actions/cache/restore@v3
44+
with:
45+
path: ~/.m2/repository
46+
# Using datetime in cache key as OWASP database may change, without the pom changing
47+
key: ${{ runner.os }}-maven-${{ steps.get-date.outputs.datetime }}-${{ hashFiles('**/pom.xml') }}
48+
restore-keys: |
49+
${{ runner.os }}-maven-${{ steps.get-date.outputs.datetime }}
50+
${{ runner.os }}-maven-
51+
52+
- name: Build & scan
53+
id: scan
54+
run: |
55+
mvn --no-transfer-progress clean package -DskipTests -DnvdApiKey=${{secrets.nvdApiKey}} -DskipITs -Dmax.cvss.score=8 \
56+
org.owasp:dependency-check-maven:check -l ${{github.workspace}}/mvn-output.txt
57+
env:
58+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME}}
59+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD}}
60+
61+
- name: Cache Maven dependencies
62+
uses: actions/cache/save@v3
63+
if: always()
64+
with:
65+
path: ~/.m2/repository
66+
key: ${{ runner.os }}-maven-${{ steps.get-date.outputs.datetime }}-${{ hashFiles('**/pom.xml') }}
67+
```

src/site/markdown/data/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ have a few options:
2222
2. [Mirror the NVD](./mirrornvd.html) locally within your organization
2323
3. Build the H2 database on one node and [cache the H2 database](./cacheh2.md).
2424
4. Use a more robust [centralized database](./database.html) with a single update node
25+
5. In GitHub Actions utilize the cache action; [example here](./cache-action.md).
2526

2627
## CISA Known Exploited Vulnerabilities
2728

0 commit comments

Comments
 (0)