|
| 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 | +``` |
0 commit comments