|
1 | | -name: "action-test" |
| 1 | +name: "SBOM Action Tests" |
2 | 2 | on: |
3 | 3 | push: |
4 | 4 | pull_request: |
5 | 5 |
|
6 | 6 | jobs: |
7 | | - test-as-action: |
| 7 | + test-repository: |
8 | 8 | runs-on: ubuntu-24.04 |
9 | 9 | steps: |
10 | | - - name: Checkout |
| 10 | + - name: Checkout repository |
11 | 11 | uses: actions/checkout@v4 |
| 12 | + |
| 13 | + - name: Test file target type (repository) |
| 14 | + id: repo-test |
| 15 | + uses: ./ |
12 | 16 | with: |
13 | | - path: ./ |
14 | | - fetch-depth: 0 |
15 | | - fetch-tags: true |
| 17 | + target: ${{ github.workspace }} |
| 18 | + target_type: file |
| 19 | + output_dir: "/tmp/sbom" |
| 20 | + name: "repo" |
| 21 | + output_file: "repository_sbom.json" |
| 22 | + vuln: true |
| 23 | + vuln_output_format: "sarif" |
| 24 | + vuln_output_file: "repository_vuln.sarif" |
16 | 25 |
|
17 | | - - name: Download artifact |
| 26 | + - name: Validate Repository SBOM |
18 | 27 | shell: bash |
19 | | - run: curl -o /tmp/Core-15.0.iso https://distro.ibiblio.org/tinycorelinux/15.x/x86/release/Core-15.0.iso |
| 28 | + run: | |
| 29 | + echo "## File Target (Repository)" >> $GITHUB_STEP_SUMMARY |
| 30 | + if jq -e '.components[] | select(.name == "lodash" or .name == "yaml")' /tmp/sbom/repository_sbom.json > /dev/null 2>&1; then |
| 31 | + echo "✅ Repository SBOM contains expected packages" >> $GITHUB_STEP_SUMMARY |
| 32 | + echo "RESULT=PASS" >> $GITHUB_ENV |
| 33 | + else |
| 34 | + echo "❌ Repository SBOM missing expected packages" >> $GITHUB_STEP_SUMMARY |
| 35 | + echo "RESULT=FAIL" >> $GITHUB_ENV |
| 36 | + exit 1 |
| 37 | + fi |
20 | 38 |
|
21 | | - - name: Scan repo |
22 | | - uses: ./ |
23 | | - with: |
24 | | - target: ./ |
25 | | - output-dir: "/tmp/test/sbom" |
26 | | - vuln-report: True |
| 39 | + test-directory: |
| 40 | + runs-on: ubuntu-24.04 |
| 41 | + steps: |
| 42 | + - name: Checkout repository |
| 43 | + uses: actions/checkout@v4 |
27 | 44 |
|
28 | | - - name: Scan directory |
| 45 | + - name: Test directory target type |
| 46 | + id: dir-test |
29 | 47 | uses: ./ |
30 | 48 | with: |
31 | 49 | target: /usr/local/bin |
32 | | - output-dir: "/tmp/test/sbom" |
33 | | - syft-version: "1.10.0" |
| 50 | + target_type: file |
34 | 51 | name: "usrlocalbin" |
| 52 | + output_format: "spdx-json" |
| 53 | + syft_version: "1.21.0" |
| 54 | + |
| 55 | + - name: Validate Directory SBOM |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + echo "## Directory Target" >> $GITHUB_STEP_SUMMARY |
| 59 | + if jq -e '(.spdxVersion != null) and (.name | contains("usrlocalbin"))' /tmp/sbom/usrlocalbin_sbom.json > /dev/null 2>&1; then |
| 60 | + echo "✅ Directory SBOM contains correct metadata" >> $GITHUB_STEP_SUMMARY |
| 61 | + echo "RESULT=PASS" >> $GITHUB_ENV |
| 62 | + else |
| 63 | + echo "❌ Directory SBOM has incorrect metadata" >> $GITHUB_STEP_SUMMARY |
| 64 | + echo "RESULT=FAIL" >> $GITHUB_ENV |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: List files |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + find /tmp/sbom -type f -name "*.json" | sort |
| 72 | +
|
| 73 | + test-iso: |
| 74 | + runs-on: ubuntu-24.04 |
| 75 | + steps: |
| 76 | + - name: Checkout repository |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Download test iso |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + # Download ISO for testing |
| 83 | + curl -o /tmp/Core-15.0.iso https://distro.ibiblio.org/tinycorelinux/15.x/x86/release/Core-15.0.iso |
35 | 84 |
|
36 | | - - name: Scan iso |
| 85 | + - name: Test ISO target type |
| 86 | + id: iso-test |
37 | 87 | uses: ./ |
38 | 88 | with: |
39 | 89 | target: /tmp/Core-15.0.iso |
40 | | - output-dir: "/tmp/test/sbom" |
| 90 | + target_type: iso |
41 | 91 | version: "15.0" |
| 92 | + output_dir: "/tmp/sbom" |
42 | 93 | name: "tinycorelinux" |
43 | | - vuln-report: False |
44 | 94 |
|
45 | | - - name: Ensure generated sbom file for repo contains the expected content |
| 95 | + - name: Validate ISO SBOM |
46 | 96 | shell: bash |
47 | 97 | run: | |
48 | | - if jq -e '.components[] | select(.name == "lodash")' /tmp/test/sbom/repo_sbom_*.json > /dev/null; then |
49 | | - echo "lodash is present in the JSON file." |
50 | | - exit 0 |
| 98 | + echo "## ISO Target" >> $GITHUB_STEP_SUMMARY |
| 99 | + if jq -e '.metadata.component.name == "tinycorelinux"' /tmp/sbom/tinycorelinux_15.0_sbom.json > /dev/null 2>&1; then |
| 100 | + echo "✅ ISO SBOM contains correct metadata" >> $GITHUB_STEP_SUMMARY |
| 101 | + echo "RESULT=PASS" >> $GITHUB_ENV |
51 | 102 | else |
52 | | - echo "lodash is NOT present in the JSON file." |
| 103 | + echo "❌ ISO SBOM missing expected components" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "RESULT=FAIL" >> $GITHUB_ENV |
53 | 105 | exit 1 |
54 | 106 | fi |
55 | 107 |
|
56 | | - - name: Ensure generated sbom file for iso contains the expected content |
| 108 | + test-image: |
| 109 | + runs-on: ubuntu-24.04 |
| 110 | + steps: |
| 111 | + - name: Checkout repository |
| 112 | + uses: actions/checkout@v4 |
| 113 | + |
| 114 | + - name: Download test image |
57 | 115 | shell: bash |
58 | 116 | run: | |
59 | | - if jq -e '.components[] | select(.version == "6.6.8-tinycore")' /tmp/test/sbom/iso_tinycorelinux_15.0.json > /dev/null; then |
60 | | - echo "tinycore is present in the JSON file." |
61 | | - exit 0 |
62 | | - else |
63 | | - echo "tinycore is NOT present in the JSON file." |
64 | | - exit 1 |
65 | | - fi |
| 117 | + docker pull alpine:latest |
| 118 | + docker save alpine:latest > /tmp/alpine.tar |
66 | 119 |
|
67 | | - - name: Ensure generated sbom file for dir contains the expected content |
68 | | - shell: bash |
| 120 | + - name: Test image target type (tarball) |
| 121 | + id: image-test |
| 122 | + uses: ./ |
| 123 | + with: |
| 124 | + target: /tmp/alpine.tar |
| 125 | + target_type: image |
| 126 | + output_dir: "/tmp/sbom" |
| 127 | + |
| 128 | + - name: Validate container image SBOM |
69 | 129 | run: | |
70 | | - if jq -e '.components[] | select(.purl == "pkg:golang/github.com/anchore/syft@v1.10.0")' /tmp/test/sbom/dir_bin_undefined.json > /dev/null; then |
71 | | - echo "syft is present in the JSON file." |
72 | | - exit 0 |
| 130 | + if jq -e '.metadata.component.type == "container"' /tmp/sbom/alpine_latest_sbom.json > /dev/null 2>&1; then |
| 131 | + echo "✅ Container image SBOM has correct type" |
73 | 132 | else |
74 | | - echo "syft is NOT present in the JSON file." |
| 133 | + echo "❌ Container image SBOM missing expected type" |
75 | 134 | exit 1 |
76 | 135 | fi |
77 | 136 |
|
78 | | - - name: Print the content of generated sbom file |
79 | | - shell: bash |
80 | | - run: | |
81 | | - for sbom in /tmp/test/sbom/*.json; do |
82 | | - echo "Content of $sbom" |
83 | | - cat $sbom |
84 | | - done |
85 | | - for sbom in /tmp/test/sbom/reports/*.html; do |
86 | | - echo "Content of vulnerability result for SBOM: $sbom" |
87 | | - cat $sbom |
88 | | - done |
| 137 | + test-summary: |
| 138 | + needs: [test-repository, test-directory, test-iso, test-image] |
| 139 | + if: always() |
| 140 | + runs-on: ubuntu-24.04 |
| 141 | + steps: |
| 142 | + - name: Tests summary |
| 143 | + run: echo "All tests completed" |
0 commit comments