Skip to content

Commit 21c6815

Browse files
committed
ci: testing some dockerfile validation and visualization
ci: mermaids with colors Potential fix for code scanning alert no. 3: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> feat: store dockerfile deps as artifact instead of committed file Store source of truth in GitHub artifacts (90-day retention) instead of committing to repo. PR builds download from main and post informational comments without blocking merges.
1 parent f521075 commit 21c6815

3 files changed

Lines changed: 551 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Dockerfile Dependency Validation
2+
permissions:
3+
contents: read
4+
pull-requests: write
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- 'Dockerfile'
10+
push:
11+
branches:
12+
- main
13+
paths:
14+
- 'Dockerfile'
15+
16+
jobs:
17+
validate-dockerfile-deps:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.11'
26+
27+
# On main: generate and upload source of truth
28+
- name: Generate source of truth
29+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
30+
run: |
31+
python3 tools/dockerfile-deps.py --generate-sot
32+
echo "✅ Generated source of truth"
33+
34+
- name: Upload source of truth artifact
35+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: dockerfile-deps-sot
39+
path: .dockerfile-deps.json
40+
retention-days: 90
41+
42+
# On PR: download source of truth and validate
43+
- name: Download source of truth from main
44+
if: github.event_name == 'pull_request'
45+
uses: dawidd6/action-download-artifact@v6
46+
with:
47+
workflow: dockerfile-deps.yml
48+
name: dockerfile-deps-sot
49+
path: .
50+
branch: main
51+
search_artifacts: true
52+
continue-on-error: true
53+
54+
- name: Validate Dockerfile dependencies
55+
if: github.event_name == 'pull_request'
56+
id: validate
57+
run: |
58+
if [ ! -f .dockerfile-deps.json ]; then
59+
echo "⚠️ No source of truth found from main branch. Generating report without validation."
60+
python3 tools/dockerfile-deps.py > report.md
61+
echo "has_sot=false" >> $GITHUB_OUTPUT
62+
else
63+
set +e
64+
python3 tools/dockerfile-deps.py --validate > report.md
65+
EXIT_CODE=$?
66+
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
67+
echo "has_sot=true" >> $GITHUB_OUTPUT
68+
fi
69+
70+
- name: Add report to job summary
71+
if: github.event_name == 'pull_request'
72+
run: |
73+
cat report.md >> $GITHUB_STEP_SUMMARY
74+
75+
- name: Comment on PR with changes
76+
if: github.event_name == 'pull_request' && steps.validate.outputs.has_sot == 'true' && steps.validate.outputs.exit_code != '0'
77+
uses: actions/github-script@v7
78+
with:
79+
script: |
80+
const fs = require('fs');
81+
const report = fs.readFileSync('report.md', 'utf8');
82+
83+
// Extract only the validation sections
84+
const lines = report.split('\n');
85+
let output = [];
86+
let inValidationSection = false;
87+
88+
for (const line of lines) {
89+
if (line.startsWith('## Build Order') || line.startsWith('## Dependency Graph')) {
90+
break;
91+
}
92+
if (line.startsWith('# Dockerfile Dependency Analysis') ||
93+
line.startsWith('**Dockerfile:**') ||
94+
line.startsWith('**Total Stages:**')) {
95+
output.push(line);
96+
continue;
97+
}
98+
if (line.startsWith('## Source of Truth Validation') ||
99+
line.startsWith('## Topological Validation')) {
100+
inValidationSection = true;
101+
}
102+
if (inValidationSection) {
103+
output.push(line);
104+
}
105+
}
106+
107+
const shortReport = output.join('\n').trim();
108+
109+
await github.rest.issues.createComment({
110+
owner: context.repo.owner,
111+
repo: context.repo.repo,
112+
issue_number: context.issue.number,
113+
body: `${shortReport}\n\n---\n*This is informational only - your PR will not be blocked. The source of truth will be updated when this PR merges to main.*`
114+
});

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ wasm/confidence_resolver.wasm
1818
# Ignore e2e test environment files (contain credentials)
1919
.env.test
2020

21+
# Ignore Dockerfile dependency source of truth (stored as GitHub artifact)
22+
.dockerfile-deps.json
23+
2124

0 commit comments

Comments
 (0)