Skip to content

Commit 3936b34

Browse files
committed
Add syncing of new docker image versions upon dependabot PR creation
1 parent 58a9876 commit 3936b34

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "Sync Docker Image Tags"
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update-images:
12+
runs-on: ubuntu-latest
13+
if: github.actor == 'dependabot[bot]'
14+
steps:
15+
- name: "Checkout PR branch"
16+
uses: actions/checkout@v3
17+
with:
18+
ref: ${{ github.head_ref }}
19+
fetch-depth: 0
20+
21+
- name: "Replace Docker image tags everywhere"
22+
run: |
23+
set -euo pipefail
24+
25+
# get old FROM lines from master branch in Dockerfiles inside allowed directory
26+
OLD_LINES=$(git grep '^FROM ' origin/master -- tests/tck-build-logic/src/main/resources/allowed-docker-images | sed 's/.*:FROM //')
27+
28+
# get new FROM lines from PR branch
29+
NEW_LINES=$(git grep '^FROM ' HEAD -- tests/tck-build-logic/src/main/resources/allowed-docker-images | sed 's/.*:FROM //')
30+
31+
# replace all occurrences across repo
32+
paste <(echo "$OLD_LINES") <(echo "$NEW_LINES") | while read OLD NEW; do
33+
if [[ -n "$OLD" && -n "$NEW" && "$OLD" != "$NEW" ]]; then
34+
echo "Replacing $OLD → $NEW"
35+
grep -rl "$OLD" . | xargs sed -i "s|$OLD|$NEW|g" || true
36+
fi
37+
done
38+
39+
# commit and push changes
40+
git config --local user.name "github-actions"
41+
git config --local user.email "[email protected]"
42+
git add .
43+
if ! git diff --cached --quiet; then
44+
git commit -m "Sync Docker image tags across repo"
45+
git push origin "${GITHUB_HEAD_REF}"
46+
else
47+
echo "No changes to commit"
48+
fi

0 commit comments

Comments
 (0)