Add github to check and automatically update the Zarf Injector component upon renovate execution (or other PR) #8
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: Zarf Injector Update | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
update-injector-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
- name: Extract Zarf version | |
id: zarf_version | |
run: | | |
# Extract the Zarf version from the zarf-config.yaml file | |
zarf_version=$(grep 'agent_image_tag:' zarf-config.yaml | cut -d'"' -f2) | |
echo "Zarf Version: $zarf_version" | |
echo "zarf_version=$zarf_version" >> $GITHUB_ENV | |
- name: Clone zarf-dev repository and checkout version | |
run: | | |
git clone https://github.com/zarf-dev/zarf.git | |
cd zarf | |
git checkout ${{ env.zarf_version }} # Use the dynamically extracted version | |
cp zarf-config.toml ../ | |
cd .. | |
- name: Parse and update zarf-config.yaml | |
run: | | |
# Extract values from the zarf-config.toml file | |
version=$(grep 'injector_version =' zarf-config.toml | cut -d"'" -f2) | |
amd64_shasum=$(grep 'injector_amd64_shasum =' zarf-config.toml | cut -d"'" -f2) | |
arm64_shasum=$(grep 'injector_arm64_shasum =' zarf-config.toml | cut -d"'" -f2) | |
# Log extracted values (optional for debugging) | |
echo "Injector Version: $version" | |
echo "Injector AMD64 SHA: $amd64_shasum" | |
echo "Injector ARM64 SHA: $arm64_shasum" | |
# Update the local zarf-config.yaml file with these values | |
sed -i "s/injector_version: .*/injector_version: \"$version\"/" zarf-config.yaml | |
sed -i "s/injector_amd64_shasum: .*/injector_amd64_shasum: $amd64_shasum/" zarf-config.yaml | |
sed -i "s/injector_arm64_shasum: .*/injector_arm64_shasum: $arm64_shasum/" zarf-config.yaml | |
- name: Check for changes | |
id: git_status | |
run: | | |
if git diff --quiet; then | |
echo "No changes detected." | |
echo "changes=false" >> $GITHUB_ENV | |
else | |
echo "Changes detected." | |
echo "changes=true" >> $GITHUB_ENV | |
fi | |
- name: Commit and push changes | |
if: env.changes == 'true' | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "GitHub Actions Bot" | |
git add zarf-config.yaml | |
git commit -m "Update Zarf injector version and shasums from zarf-config.toml" | |
git push |