trigger config warehouse #8
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: Render Manifests | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'guestbook/**' | |
| permissions: | |
| contents: write | |
| jobs: | |
| render: | |
| name: Render ${{ matrix.env }} Manifests | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - env: dev | |
| values-file: environments/dev-values.yaml | |
| branch: env/dev | |
| release-name: guestbook-dev | |
| - env: staging | |
| values-file: environments/staging-values.yaml | |
| branch: env/staging | |
| release-name: guestbook-staging | |
| - env: prod | |
| values-file: environments/prod-values.yaml | |
| branch: env/prod | |
| release-name: guestbook-prod | |
| steps: | |
| - name: Checkout main branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| path: source | |
| - name: Setup Helm | |
| uses: azure/setup-helm@v4 | |
| - name: Render Manifests | |
| run: | | |
| mkdir -p rendered/guestbook | |
| helm template ${{ matrix.release-name }} source/guestbook \ | |
| -f source/guestbook/${{ matrix.values-file }} \ | |
| --output-dir rendered/guestbook | |
| # helm template --output-dir creates a nested structure like: | |
| # rendered/guestbook/guestbook/templates/deployment.yaml | |
| # Flatten it to: | |
| # rendered/guestbook/deployment.yaml | |
| find rendered/guestbook -name '*.yaml' -mindepth 3 -exec mv {} rendered/guestbook/ \; | |
| find rendered/guestbook -type d -empty -delete | |
| - name: Checkout env branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ matrix.branch }} | |
| path: env-branch | |
| fetch-depth: 0 | |
| continue-on-error: true | |
| - name: Create orphan branch if it doesn't exist | |
| if: failure() | |
| run: | | |
| mkdir -p env-branch | |
| cd env-branch | |
| git init | |
| git checkout --orphan ${{ matrix.branch }} | |
| git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git | |
| - name: Update rendered manifests | |
| run: | | |
| rm -rf env-branch/guestbook | |
| cp -r rendered/guestbook env-branch/guestbook | |
| - name: Commit and push | |
| run: | | |
| cd env-branch | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes to rendered manifests for ${{ matrix.env }}" | |
| else | |
| git commit -m "render: ${{ matrix.env }} manifests from ${{ github.sha }}" | |
| git push origin HEAD:${{ matrix.branch }} | |
| echo "Pushed rendered manifests to ${{ matrix.branch }}" | |
| fi |