Skip to content

Migrate from Fossa to local Trivy license check #1

Migrate from Fossa to local Trivy license check

Migrate from Fossa to local Trivy license check #1

Workflow file for this run

name: License Check
# This check can be executed locally as follows:
#
# Install Trivy, see https://aquasecurity.github.io/trivy/v0.18.3/installation/
# $ brew install aquasecurity/trivy/trivy
#
# Lock dependencies
# $ ./gradlew clean cyclonedxBom
#
# Check for licenses
# $ trivy sbom --scanners license --severity UNKNOWN,HIGH,CRITICAL --format table --config .github/trivy/license-policy-trivy.yaml build/reports/bom.json
on:
pull_request: {}
# TODO release published and attach full report
jobs:
trivy-license-check:
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set up JDK 21
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: 'temurin'
java-version: 21
cache: 'gradle'
- name: Create SBOM
run: ./gradlew clean cyclonedxBom
# TODO on release: all severities + exit-code 0
- name: Check for forbidden licenses
run: >
docker run --rm
-v "$PWD:/project"
aquasec/trivy:0.51.1
sbom --scanners license --severity UNKNOWN,HIGH,CRITICAL
--format json
--config /project/.github/trivy-license-config.yaml
--exit-code 1
/project/build/reports/bom.json
>> trivy-licenses.json
- name: Markdown table
if: always()
run: |
echo "| Dependency | License | Category | Severity |" > trivy-licenses.md
echo "|------------|---------|----------|----------|" >> trivy-licenses.md
cat trivy-licenses.json | jq --raw-output '.Results[] | select(.Licenses) | .Licenses[] | "| \(.PkgName) | \(.Name) | \(.Category) | \(.Severity) |"' >> trivy-licenses.md
- name: Add failure Job summary
if: failure() && github.event.pull_request
run: |
echo '**License violations or unknown licenses found in dependencies:**' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
cat trivy-licenses.md >> $GITHUB_STEP_SUMMARY
- name: Add success Job summary
if: success() && github.event.pull_request
run: |
echo 'All dependencies have allowed licenses.' >> $GITHUB_STEP_SUMMARY
# - name: Read to env
# id: licenses
# if: always() && github.event. TODO release
# uses: guibranco/github-file-reader-action-v2@a19627ed0e64d536a7db4b936799e66383557c01 # v2.0.486
# with:
# path: trivy-licenses.md
# TODO always() add file to release