update image digests #20
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: update image digests | |
on: | |
schedule: | |
- cron: 0 1 * * * | |
workflow_dispatch: {} | |
jobs: | |
update-image-digests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | |
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main | |
- name: configure system | |
run: | | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
gh auth login --with-token < <(echo ${{ secrets.GITHUB_TOKEN }}) | |
gh auth status | |
- name: update select images | |
run: ./hack/update-sync-image-digests.sh | |
- name: determine changes | |
id: determine-changes | |
run: | | |
if git ls-files --others --modified --deleted --exclude-standard | grep -E 'config.yaml'; then | |
echo "changes=true" >> $GITHUB_OUTPUT | |
fi | |
- name: determine existing branch | |
id: branch | |
if: ${{ steps.determine-changes.outputs.changes == 'true' }} | |
run: | | |
TIMESTAMP="$(git log -n1 --pretty='format:%cd' --date=format:'%Y-%m-%d-%H-%M')" | |
NEW_BRANCH="config-yaml-image-update-for-${TIMESTAMP}" | |
EXISTING_BRANCH="$(gh pr list --label image-digest-update --json author,title,headRefName | jq -r '. | select(.[] | .title | contains("update sync config.yaml")) | select(.[] | .author.login | contains("github-actions[bot]")) | .[0].headRefName')" | |
if [ -n "$EXISTING_BRANCH" ]; then | |
NEW_BRANCH="$EXISTING_BRANCH" | |
echo "has-existing=true" >> $GITHUB_OUTPUT | |
fi | |
echo "timestamp=$TIMESTAMP" >> $GITHUB_OUTPUT | |
echo "new-branch-name=$NEW_BRANCH" >> $GITHUB_OUTPUT | |
- name: commit and push if there are changes | |
if: ${{ steps.determine-changes.outputs.changes == 'true' }} | |
env: | |
TIMESTAMP: ${{ steps.branch.outputs.timestamp }} | |
NEW_BRANCH: ${{ steps.branch.outputs.new-branch-name }} | |
HAS_EXISTING: ${{ steps.branch.outputs.has-existing }} | |
run: | | |
git add ./config.yaml | |
git branch "${NEW_BRANCH}" | |
git checkout "${NEW_BRANCH}" | |
git commit -s -m "chore: update sync config.yaml images for ${TIMESTAMP}" | |
git push -f origin "${NEW_BRANCH}" | |
ACTION=create | |
if [ "$HAS_EXISTING" = true ]; then | |
ACTION=edit | |
fi | |
gh pr "$ACTION" --title "Update sync config.yaml images ${TIMESTAMP}" --body "updates sync config.yaml images for ${TIMESTAMP}" |