Skip to content

Commit e109191

Browse files
author
Codev User
committed
Add GitHub Action to auto-synthesize Image Factory Kargo resources
- Triggers on changes to images.yaml or cdk8s code - Auto-generates Kargo Warehouses and Stages from images.yaml - Commits synthesized manifests back to main branch - Validates synthesis on PRs with artifact upload - Eliminates manual 'task cdk8s:synth' requirement
1 parent b65ffac commit e109191

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Image Factory CDK8s Synth
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'image-factory/images.yaml'
9+
- 'image-factory/cdk8s/**'
10+
- '.github/workflows/image-factory-synth.yml'
11+
12+
pull_request:
13+
paths:
14+
- 'image-factory/images.yaml'
15+
- 'image-factory/cdk8s/**'
16+
- '.github/workflows/image-factory-synth.yml'
17+
18+
workflow_dispatch:
19+
20+
jobs:
21+
synth-and-commit:
22+
name: Synthesize Kargo Resources
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write
26+
pull-requests: write
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v4
36+
with:
37+
python-version: '3.11'
38+
39+
- name: Install Task
40+
uses: pnorton5432/setup-task@v1
41+
42+
- name: Setup CDK8s environment
43+
run: task cdk8s:setup
44+
working-directory: image-factory
45+
46+
- name: Synthesize Kargo manifests
47+
run: task cdk8s:synth
48+
working-directory: image-factory
49+
50+
- name: Check for changes
51+
id: check_changes
52+
run: |
53+
if git diff --quiet image-factory/.output/; then
54+
echo "has_changes=false" >> $GITHUB_OUTPUT
55+
echo "No changes detected in synthesized manifests"
56+
else
57+
echo "has_changes=true" >> $GITHUB_OUTPUT
58+
echo "Changes detected in synthesized manifests"
59+
fi
60+
61+
- name: Commit synthesized manifests
62+
if: steps.check_changes.outputs.has_changes == 'true' && github.ref == 'refs/heads/main'
63+
run: |
64+
git config --local user.email "action@github.com"
65+
git config --local user.name "GitHub Action"
66+
git add image-factory/.output/
67+
git commit -m "Auto-synth: Regenerate Kargo resources from images.yaml
68+
69+
Generated from commit ${{ github.sha }}
70+
71+
Changes:
72+
$(git diff HEAD~1 image-factory/images.yaml --stat || echo 'New enrollment')"
73+
git push
74+
75+
- name: Upload synthesized manifests (PR)
76+
if: steps.check_changes.outputs.has_changes == 'true' && github.event_name == 'pull_request'
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: synthesized-kargo-manifests
80+
path: image-factory/.output/
81+
82+
- name: Comment on PR
83+
if: steps.check_changes.outputs.has_changes == 'true' && github.event_name == 'pull_request'
84+
uses: actions/github-script@v7
85+
with:
86+
script: |
87+
github.rest.issues.createComment({
88+
issue_number: context.issue.number,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
body: '✅ Kargo resources synthesized successfully. New manifests will be auto-committed when merged to main.'
92+
})

0 commit comments

Comments
 (0)