|
14 | 14 | uses: ./.github/workflows/get_image.yaml |
15 | 15 | with: |
16 | 16 | image-base-name: "dev_image_with_extras" |
17 | | - generate-sarif: |
| 17 | + image-scan: |
18 | 18 | strategy: |
19 | 19 | fail-fast: false |
20 | 20 | matrix: |
@@ -67,77 +67,11 @@ jobs: |
67 | 67 | - run: | |
68 | 68 | for f in "sarif/${{ matrix.artifact }}/"*; do |
69 | 69 | jq '.runs[].tool.driver.name = "trivy-images"' < "$f" > tmp |
70 | | - mv tmp "$f" |
| 70 | + # The runAutomationDetails's id field must contain a unique category as required by the CodeQL SARIF uploader |
| 71 | + # This value will be interpreted like so: "${category}/${run_id}" |
| 72 | + filename=$(basename "$f")/ |
| 73 | + jq --arg id "$filename" '.runAutomationDetails.id = $id/' < tmp > "$f" |
71 | 74 | done |
72 | | - - name: Upload artifacts |
73 | | - uses: actions/upload-artifact@v4 |
74 | | - with: |
75 | | - name: sarif-${{ matrix.artifact }} |
76 | | - path: sarif/ |
77 | | - retention-days: 1 |
78 | | - |
79 | | - collect-sarifs: |
80 | | - # GitHub Actions matrix job outputs cannot be directly used as job outputs |
81 | | - # because matrix jobs create multiple output values (one per matrix combination). |
82 | | - # We need a separate job to collect all SARIF files from all artifacts |
83 | | - # and create a single unified matrix for the upload job. |
84 | | - needs: generate-sarif |
85 | | - runs-on: oracle-8cpu-32gb-x86-64 |
86 | | - outputs: |
87 | | - matrix: ${{ steps.combine-sarifs.outputs.matrix }} |
88 | | - has-sarifs: ${{ steps.combine-sarifs.outputs.has-sarifs }} |
89 | | - steps: |
90 | | - - name: Download all artifacts |
91 | | - uses: actions/download-artifact@v4 |
92 | | - with: |
93 | | - pattern: sarif-* |
94 | | - merge-multiple: true |
95 | | - - id: combine-sarifs |
96 | | - run: | |
97 | | - # With merge-multiple: true, all artifacts are in the same directory |
98 | | - # Find all SARIF files regardless of subdirectory structure |
99 | | - all_files=() |
100 | | - while IFS= read -r -d '' file; do |
101 | | - echo "Found file: $file" |
102 | | - all_files+=("$file") |
103 | | - done < <(find . -name "*.sarif" -type f -print0) |
104 | | -
|
105 | | - echo "Total files found: ${#all_files[@]}" |
106 | | -
|
107 | | - if [ ${#all_files[@]} -eq 0 ]; then |
108 | | - echo "matrix={\"include\":[]}" >> $GITHUB_OUTPUT |
109 | | - echo "has-sarifs=false" >> $GITHUB_OUTPUT |
110 | | - else |
111 | | - matrix_json=$(printf '%s\n' "${all_files[@]}" | jq -R -s ' |
112 | | - split("\n") | map(select(length > 0)) | { |
113 | | - include: map({ |
114 | | - file: ., |
115 | | - category: ("trivy-images-" + (split("/")[1]) + "-" + (split("/")[-1] | split(".")[0])), |
116 | | - artifact: ("sarif-" + (split("/")[1])) |
117 | | - }) |
118 | | - }' | jq -c '.') |
119 | | -
|
120 | | - echo "matrix=$matrix_json" >> $GITHUB_OUTPUT |
121 | | - echo "has-sarifs=true" >> $GITHUB_OUTPUT |
122 | | - fi |
123 | | -
|
124 | | - upload-sarif: |
125 | | - needs: collect-sarifs |
126 | | - if: needs.collect-sarifs.outputs.has-sarifs == 'true' |
127 | | - strategy: |
128 | | - matrix: ${{ fromJson(needs.collect-sarifs.outputs.matrix) }} |
129 | | - runs-on: oracle-8cpu-32gb-x86-64 |
130 | | - permissions: |
131 | | - actions: read |
132 | | - contents: read |
133 | | - security-events: write |
134 | | - steps: |
135 | | - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
136 | | - - name: Download artifacts |
137 | | - uses: actions/download-artifact@v4 |
138 | | - with: |
139 | | - name: ${{ matrix.artifact }} |
140 | 75 | - uses: github/codeql-action/upload-sarif@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3.28.13 |
141 | 76 | with: |
142 | | - sarif_file: ${{ matrix.file }} |
143 | | - category: ${{ matrix.category }} |
| 77 | + sarif_file: sarif/${{ matrix.artifact }} |
0 commit comments