feat: use dyn client to create/patch resources instead of kubectl app… #33
This file contains 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: Build & publish images | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
REGISTRY: ghcr.io | |
REGISTRY_PATH: ${{ github.repository }} | |
jobs: | |
get-changed-dirs: | |
runs-on: ubuntu-latest | |
outputs: | |
dirs: ${{ steps.get-changed-dirs.outputs.all_changed_and_modified_files }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 | |
- name: Get changed dirs | |
uses: tj-actions/changed-files@03334d095e2739fa9ac4034ec16f66d5d01e9eba # v44.5.1 | |
id: get-changed-dirs | |
with: | |
dir_names: "true" | |
matrix: "true" | |
dir_names_max_depth: 1 | |
files: | | |
example-controller/**/* | |
gitops/**/* | |
!**/*.md | |
- name: Echo changed dirs | |
run: echo "${{ steps.get-changed-dirs.outputs.all_changed_and_modified_files }}" | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
needs: | |
- get-changed-dirs | |
if: ${{ needs.get-changed-dirs.outputs.dirs != '[]' }} | |
strategy: | |
fail-fast: false | |
matrix: | |
dirs: ${{ fromJson(needs.get-changed-dirs.outputs.dirs) }} | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0 | |
- name: Log in to the Container registry | |
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Read VERSION file | |
id: version | |
run: | | |
version=$(cat ${{ matrix.dirs }}/VERSION) | |
echo "version=$version" >> $GITHUB_OUTPUT | |
- name: Build and push Docker image | |
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 | |
id: push | |
with: | |
context: ${{ matrix.dirs }} | |
file: ${{ matrix.dirs }}/Dockerfile | |
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
tags: ${{ env.REGISTRY }}/${{ env.REGISTRY_PATH }}/${{ matrix.dirs }}:${{ steps.version.outputs.version }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Attest build provenance | |
uses: actions/attest-build-provenance@v1 | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
id: attest | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.REGISTRY_PATH }}/${{ matrix.dirs }} | |
subject-digest: ${{ steps.push.outputs.digest }} | |
push-to-registry: true |