Skip to content

Commit

Permalink
feat: auto image updating
Browse files Browse the repository at this point in the history
  • Loading branch information
corang committed Feb 9, 2024
1 parent 5f1614a commit 9bf10eb
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/actions/update-images/action.yaml
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions .github/actions/update-images/update-images.sh
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions .github/workflows/image-update.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:
jobs:
test:
runs-on: "ubuntu-latest"
timeout-minutes: 30
timeout-minutes: 20
name: Test
strategy:
matrix:
Expand Down

0 comments on commit 9bf10eb

Please sign in to comment.