Merge: Add auto-synth workflow and keep synthesized dist file #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Image Factory CDK8s Synth | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'image-factory/images.yaml' | ||
| - 'image-factory/cdk8s/**' | ||
| - 'image-factory/state/**' | ||
| - '.github/workflows/image-factory-synth.yml' | ||
| workflow_dispatch: | ||
| jobs: | ||
| auto-synth: | ||
| name: Auto-synthesize Kargo Resources | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout PR branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.11' | ||
| - name: Install Task | ||
| uses: pnorton5432/setup-task@v1 | ||
| - name: Setup CDK8s environment | ||
| run: task cdk8s:setup | ||
| working-directory: image-factory | ||
| - name: Synthesize Kargo manifests | ||
| run: task cdk8s:synth | ||
| working-directory: image-factory | ||
| - name: Check if synthesis generated changes | ||
| id: check_changes | ||
| run: | | ||
| if git diff --quiet image-factory/cdk8s/dist/image-factory.k8s.yaml; then | ||
| echo "has_changes=false" >> $GITHUB_OUTPUT | ||
| echo "✅ Kargo resources are already up to date" | ||
| else | ||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||
| echo "📝 Synthesis generated new Kargo resources" | ||
| echo "" | ||
| echo "Changes:" | ||
| git diff --stat image-factory/cdk8s/dist/image-factory.k8s.yaml | ||
| fi | ||
| - name: Commit synthesized resources to PR branch | ||
| if: steps.check_changes.outputs.has_changes == 'true' | ||
| run: | | ||
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
| git config --local user.name "github-actions[bot]" | ||
| git add image-factory/cdk8s/dist/image-factory.k8s.yaml | ||
| git commit -m "Auto-synth: Regenerate Kargo resources from images.yaml | ||
| Synthesized by GitHub Actions from: | ||
| - Commit: ${{ github.event.pull_request.head.sha }} | ||
| - PR: #${{ github.event.pull_request.number }}" | ||
| git push | ||
| - name: Comment on PR | ||
| if: steps.check_changes.outputs.has_changes == 'true' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: '✅ Kargo resources automatically synthesized and committed to this PR branch.' | ||
| }) | ||