Skip to content

Commit 84bcdc9

Browse files
authored
KAFKA-17540: Create script for updating a reference of latest cached trunk commit (#17204)
Uses the `gh` CLI to find the latest trunk commit which has been cached by GitHub actions. By basing PRs off of this ref rather than HEAD, we will see fewer cache misses in our CI builds. Reviewers: Chia-Ping Tsai <[email protected]>, David Arthur <[email protected]>
1 parent 06d2649 commit 84bcdc9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

committer-tools/update-cache.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
if ! git config --get alias.update-cache > /dev/null; then
20+
printf '\e[36m%s\n\n %s\n\e[0m\n' \
21+
'Hint: you can create a Git alias to execute this script. Example:' \
22+
"git config alias.update-cache '!bash $(realpath "$0")'"
23+
fi
24+
25+
key="$(
26+
gh cache list \
27+
--key 'gradle-home-v1|Linux-X64|test' \
28+
--sort 'created_at' \
29+
--limit 1 \
30+
--json 'key' \
31+
--jq '.[].key'
32+
)"
33+
34+
sha="$(cut -d '-' -f 5 <<< "$key")"
35+
36+
if ! git show "$sha" &> /dev/null; then
37+
printf '\e[33m%s\n%s\e[0m\n' \
38+
"Cannot update 'trunk-cached' because SHA $sha" \
39+
"does not exist locally. Please update your remote and try again."
40+
else
41+
if git branch -f trunk-cached "$sha" &> /dev/null; then
42+
rel_date="$(git show --no-patch $sha --date=relative --pretty=format:'%cr')"
43+
printf '%s\n' "Local branch 'trunk-cached' successfully updated to $(head -c 10 <<< "$sha") (from $rel_date)."
44+
else
45+
printf '\e[31m%s\e[0m\n' "Failed to update ref for 'trunk-cached' and commit $(head -c 10 <<< "$sha")."
46+
fi
47+
fi

0 commit comments

Comments
 (0)