diff --git a/.github/actions/update-images/action.yaml b/.github/actions/update-images/action.yaml new file mode 100644 index 0000000..d3e7ef1 --- /dev/null +++ b/.github/actions/update-images/action.yaml @@ -0,0 +1,10 @@ +name: update-images +description: "Update all findable images for all zarf packages in repo" + +runs: + using: composite + steps: + - name: Run script + run: | + ./.github/actions/update-images/update-images.sh + shell: bash diff --git a/.github/actions/update-images/update-images.sh b/.github/actions/update-images/update-images.sh new file mode 100755 index 0000000..d27da56 --- /dev/null +++ b/.github/actions/update-images/update-images.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# set -x + +update() { + IMG_YAML="$(zarf dev find-images --no-progress | grep -v '#')" + COMPONENT_UPDATES="$(echo "$IMG_YAML" | yq '.components[].name')" + FLAVOR="$1" + FLAVOR_CHECK="" + + if ! [ -z "$FLAVOR" ]; then + FLAVOR_CHECK="| select(.only.flavor == \"$FLAVOR\")" + fi + + for component in $COMPONENT_UPDATES; do + NEW_IMAGES=$(echo "$IMG_YAML" | yq ".components[] | select(.name == \"$component\") | .images | .. style=\"double\" | . style=\"flow\"") + echo $NEW_IMAGES + cat zarf.yaml | yq "(.components[] | select(.name == \"$component\") ${FLAVOR_CHECK} | .images) |= $NEW_IMAGES" > zarf.yaml.tmp + mv zarf.yaml.tmp zarf.yaml + done +} + +parse_flavors() { + FLAVORS="$(yq '.components[].only.flavor' zarf.yaml | grep -v null)" + if [ -z "$FLAVORS" ]; then + echo "No flavors found in zarf.yaml" + update + else + echo "Flavors found in zarf.yaml: $FLAVORS" + for flavor in $FLAVORS; do + export ZARF_CONFIG="zarf-config-ci.yaml" + yq --null-input ".package.create.flavor = \"$flavor\"" > $ZARF_CONFIG + update $flavor + done + rm -f $ZARF_CONFIG + export ZARF_CONFIG="" + fi +} + +ZARF_PKGS="$(find . -type f -name "zarf.yaml" -exec dirname {} \;)" + +for pkgDir in $ZARF_PKGS; do + pushd $pkgDir + parse_flavors + popd +done diff --git a/.github/workflows/image-update.yaml b/.github/workflows/image-update.yaml new file mode 100644 index 0000000..26a3032 --- /dev/null +++ b/.github/workflows/image-update.yaml @@ -0,0 +1,36 @@ +name: Update Images + +on: + pull_request: + branches: + - renovate/* + +# Abort prior jobs in the same workflow / PR +concurrency: + group: test-${{ github.ref }}-${{ inputs.package }} + cancel-in-progress: true + +permissions: + contents: write + pull-requests: write + +jobs: + test: + runs-on: "ubuntu-latest" + timeout-minutes: 10 + name: Update Images + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Update Images + uses: ./.github/actions/update-images + + - name: Commit and push changes + run: | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + git config --global user.name "${{ github.actor }}" + git add . + git commit -m "chore: update images" + git push diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e6908ed..7756fb9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -18,7 +18,7 @@ permissions: jobs: test: runs-on: "ubuntu-latest" - timeout-minutes: 30 + timeout-minutes: 20 name: Test strategy: matrix: