|
| 1 | +name: SBOM Monthly Audit |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # First Monday of each month at 09:00 UTC |
| 6 | + - cron: '0 9 1-7 * 1' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + branch: |
| 10 | + description: 'Branch to audit (leave empty for current)' |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + issues: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + audit: |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + ref: ${{ inputs.branch || github.ref }} |
| 26 | + fetch-depth: 1 |
| 27 | + submodules: recursive |
| 28 | + |
| 29 | + - name: Install PyYAML |
| 30 | + run: pip install pyyaml --break-system-packages |
| 31 | + |
| 32 | + - name: Run license verification |
| 33 | + id: verify |
| 34 | + continue-on-error: true |
| 35 | + run: | |
| 36 | + python3 Tools/ci/generate_sbom.py --verify-licenses --source-dir . 2>&1 | tee /tmp/sbom-verify.txt |
| 37 | + echo "exit_code=$?" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + - name: Check for issues |
| 40 | + id: check |
| 41 | + run: | |
| 42 | + if grep -q "NOASSERTION" /tmp/sbom-verify.txt; then |
| 43 | + echo "has_issues=true" >> "$GITHUB_OUTPUT" |
| 44 | + # Extract NOASSERTION lines |
| 45 | + grep "NOASSERTION" /tmp/sbom-verify.txt | grep -v "skipped" > /tmp/sbom-issues.txt || true |
| 46 | + # Extract copyleft lines |
| 47 | + sed -n '/Copyleft licenses detected/,/^$/p' /tmp/sbom-verify.txt > /tmp/sbom-copyleft.txt || true |
| 48 | + else |
| 49 | + echo "has_issues=false" >> "$GITHUB_OUTPUT" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Create issue if problems found |
| 53 | + if: steps.check.outputs.has_issues == 'true' |
| 54 | + uses: actions/github-script@v7 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + const fs = require('fs'); |
| 58 | +
|
| 59 | + const fullOutput = fs.readFileSync('/tmp/sbom-verify.txt', 'utf8'); |
| 60 | + let issueLines = ''; |
| 61 | + try { |
| 62 | + issueLines = fs.readFileSync('/tmp/sbom-issues.txt', 'utf8'); |
| 63 | + } catch (e) { |
| 64 | + issueLines = 'No specific NOASSERTION lines captured.'; |
| 65 | + } |
| 66 | + let copyleftLines = ''; |
| 67 | + try { |
| 68 | + copyleftLines = fs.readFileSync('/tmp/sbom-copyleft.txt', 'utf8'); |
| 69 | + } catch (e) { |
| 70 | + copyleftLines = ''; |
| 71 | + } |
| 72 | +
|
| 73 | + const date = new Date().toISOString().split('T')[0]; |
| 74 | + const branch = '${{ inputs.branch || github.ref_name }}'; |
| 75 | +
|
| 76 | + // Check for existing open issue to avoid duplicates |
| 77 | + const existing = await github.rest.issues.listForRepo({ |
| 78 | + owner: context.repo.owner, |
| 79 | + repo: context.repo.repo, |
| 80 | + labels: 'sbom-audit', |
| 81 | + state: 'open', |
| 82 | + }); |
| 83 | +
|
| 84 | + if (existing.data.length > 0) { |
| 85 | + // Update existing issue with new findings |
| 86 | + await github.rest.issues.createComment({ |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + issue_number: existing.data[0].number, |
| 90 | + body: `## Monthly audit update (${date})\n\nIssues still present:\n\n\`\`\`\n${issueLines}\n\`\`\`\n${copyleftLines ? `\n### Copyleft warnings\n\`\`\`\n${copyleftLines}\n\`\`\`` : ''}`, |
| 91 | + }); |
| 92 | + return; |
| 93 | + } |
| 94 | +
|
| 95 | + await github.rest.issues.create({ |
| 96 | + owner: context.repo.owner, |
| 97 | + repo: context.repo.repo, |
| 98 | + title: `chore(sbom): license audit found NOASSERTION entries on ${branch} (${date})`, |
| 99 | + labels: ['sbom-audit'], |
| 100 | + assignees: ['mrpollo'], |
| 101 | + body: [ |
| 102 | + `## SBOM Monthly Audit -- ${branch} -- ${date}`, |
| 103 | + '', |
| 104 | + 'The automated SBOM license audit found submodules with unresolved licenses.', |
| 105 | + '', |
| 106 | + '### NOASSERTION entries', |
| 107 | + '', |
| 108 | + '```', |
| 109 | + issueLines, |
| 110 | + '```', |
| 111 | + '', |
| 112 | + copyleftLines ? `### Copyleft warnings\n\n\`\`\`\n${copyleftLines}\n\`\`\`\n` : '', |
| 113 | + '### How to fix', |
| 114 | + '', |
| 115 | + '1. Check the submodule repo for a LICENSE file', |
| 116 | + '2. Add an override to `Tools/ci/license-overrides.yaml`', |
| 117 | + '3. Run `python3 Tools/ci/generate_sbom.py --verify-licenses --source-dir .` to confirm', |
| 118 | + '', |
| 119 | + '### Full output', |
| 120 | + '', |
| 121 | + '<details>', |
| 122 | + '<summary>Click to expand</summary>', |
| 123 | + '', |
| 124 | + '```', |
| 125 | + fullOutput, |
| 126 | + '```', |
| 127 | + '', |
| 128 | + '</details>', |
| 129 | + '', |
| 130 | + 'cc @mrpollo', |
| 131 | + ].join('\n'), |
| 132 | + }); |
0 commit comments