Skip to content

Commit cc211ba

Browse files
committed
scripts: check-for-epoch-bump.sh: Improve epoch parsing
It was failing for me when I had a comment after the epoch. Signed-off-by: dann frazier <dann.frazier@chainguard.dev>
1 parent 9834e1f commit cc211ba

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

scripts/check-for-epoch-bump.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,30 @@ if [ "$#" -lt 1 ]; then
1010
exit 1
1111
fi
1212

13+
epoch_grep() {
14+
grep -E '^[[:space:]]+epoch:'
15+
}
16+
17+
epoch_sed() {
18+
sed -r 's/^[[:space:]]+epoch:[[:space:]]+([0-9])+/\1/'
19+
}
20+
1321
for yaml_file in "$@"; do
1422
echo "Checking $yaml_file:"
1523

1624
# Extract the epoch from the current file using grep and sed
17-
epoch_local=$(grep -E '^[[:space:]]*epoch:' "$yaml_file" | sed 's/.*epoch:[[:space:]]*//')
25+
# (not assuming `yq` is available)
26+
epoch_line="$(epoch_grep < "$yaml_file")"
27+
epoch_local="$(echo "$epoch_line" | epoch_sed)"
1828
if [ -z "$epoch_local" ]; then
1929
echo "Warning: 'epoch' field not found in $yaml_file"
2030
echo ""
2131
continue
2232
fi
2333

2434
# Extract the epoch from the file on the main branch using git show
25-
epoch_main=$(git show main:"$yaml_file" 2>/dev/null | grep -E '^[[:space:]]*epoch:' | sed 's/.*epoch:[[:space:]]*//')
35+
epoch_main_line="$(git show main:"$yaml_file" 2>/dev/null | epoch_grep)"
36+
epoch_main="$(echo "$epoch_main_line" | epoch_sed)"
2637
if [ -z "$epoch_main" ]; then
2738
echo "Warning: 'epoch' field not found in $yaml_file on branch 'main'"
2839
echo ""

0 commit comments

Comments
 (0)