Skip to content

Commit b22ff4f

Browse files
committed
feat(docker-build): enhance reporting
1 parent d49dfff commit b22ff4f

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

.github/workflows/docker-build.yml

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ jobs:
6666
username: ${{ secrets.username }}
6767
password: ${{ secrets.password }}
6868

69-
- name: Run Hadolint Dockerfile linter
70-
if: ${{ inputs.hadolint }}
71-
uses: hadolint/[email protected]
72-
with:
73-
dockerfile: ${{ inputs.dockerfile }}
74-
output-file: hadolint.txt
75-
no-fail: true
76-
7769
- name: Build Docker Image
7870
if: ${{ inputs.push }}
7971
uses: docker/build-push-action@v6
@@ -91,6 +83,7 @@ jobs:
9183
docker save -o vuln-image.tar ${{ inputs.image-name }}:${{ inputs.image-tag }}
9284
9385
- name: Run Trivy vulnerability scanner
86+
id: trivy
9487
if: ${{ inputs.security-scan }}
9588
uses: aquasecurity/[email protected]
9689
with:
@@ -102,29 +95,32 @@ jobs:
10295
hide-progress: true
10396
output: trivy.txt
10497

105-
- name: Update Pull Request with Security Scan Results
106-
uses: actions/github-script@v7
98+
- name: Find existing Trivy comment
99+
if: github.event_name == 'pull_request' && inputs.security-scan && inputs.security-report == 'comment'
100+
id: find_trivy
101+
uses: peter-evans/find-comment@v3
102+
with:
103+
issue-number: ${{ github.event.pull_request.number }}
104+
comment-author: 'github-actions[bot]'
105+
body-includes: 'Trivy Security Scan Results'
106+
107+
- name: Create or update Trivy comment
107108
if: github.event_name == 'pull_request' && inputs.security-scan && inputs.security-report == 'comment'
109+
uses: peter-evans/create-or-update-comment@v4
108110
with:
109-
script: |
110-
const fs = require('fs');
111-
const trivyResults = fs.readFileSync('trivy.txt', 'utf8');
112-
113-
const output = `
111+
token: ${{ secrets.GITHUB_TOKEN }}
112+
issue-number: ${{ github.event.pull_request.number }}
113+
comment-id: ${{ steps.find_trivy.outputs.comment-id }}
114+
edit-mode: replace
115+
body: |
116+
<!-- trivy-scan -->
114117
### 🔒 Trivy Security Scan Results
115118
<details><summary>Click to expand detailed results</summary>
116-
117-
\`\`\`
118-
${trivyResults}
119-
\`\`\`
119+
120+
```bash
121+
${{ steps.trivy.outputs.report }}
122+
```
120123
</details>
121-
`;
122-
123-
await github.rest.issues.createComment({
124-
issue_number: context.issue.number,
125-
owner: context.repo.owner,
126-
repo: context.repo.repo,
127-
body: output
128124
});
129125
130126
- name: Upload Trivy scan results to GitHub Security tab
@@ -133,29 +129,38 @@ jobs:
133129
with:
134130
sarif_file: 'trivy-results.sarif'
135131

136-
- name: Update Pull Request with Hadolint Results
137-
uses: actions/github-script@v7
132+
- name: Run Hadolint Dockerfile linter
133+
id: hadolint
134+
if: ${{ inputs.hadolint }}
135+
uses: hadolint/[email protected]
136+
with:
137+
dockerfile: ${{ inputs.dockerfile }}
138+
output-file: hadolint.txt
139+
no-fail: true
140+
141+
- name: Find existing Hadolint comment
142+
if: github.event_name == 'pull_request' && inputs.hadolint
143+
id: find_hadolint
144+
uses: peter-evans/find-comment@v3
145+
with:
146+
issue-number: ${{ github.event.pull_request.number }}
147+
comment-author: 'github-actions[bot]'
148+
body-includes: 'Hadolint Dockerfile Lint Results'
149+
150+
- name: Create or update Hadolint comment
138151
if: github.event_name == 'pull_request' && inputs.hadolint
152+
uses: peter-evans/create-or-update-comment@v4
139153
with:
140-
script: |
141-
const fs = require('fs');
142-
const hadolintResults = fs.readFileSync('hadolint.txt', 'utf8').trim();
143-
144-
if (hadolintResults.length > 0) {
145-
const output = `
146-
### 🐳 Hadolint Dockerfile Lint Results
147-
<details><summary>Click to expand</summary>
148-
149-
\`\`\`
150-
${hadolintResults}
151-
\`\`\`
152-
</details>
153-
`;
154-
155-
await github.rest.issues.createComment({
156-
issue_number: context.issue.number,
157-
owner: context.repo.owner,
158-
repo: context.repo.repo,
159-
body: output
160-
});
161-
}
154+
token: ${{ secrets.GITHUB_TOKEN }}
155+
issue-number: ${{ github.event.pull_request.number }}
156+
comment-id: ${{ steps.find_hadolint.outputs.comment-id }}
157+
edit-mode: replace
158+
body: |
159+
<!-- hadolint-scan -->
160+
### 🐳 Hadolint Dockerfile Lint Results
161+
<details><summary>Click to expand</summary>
162+
163+
```bash
164+
${{ steps.hadolint.outputs.report }}
165+
```
166+
</details>

0 commit comments

Comments
 (0)