Skip to content

Commit beb7441

Browse files
authored
Merge pull request #16 from chainguard-dev/better-epoch-parsing
scripts: check-for-epoch-bump.sh: Improve epoch parsing
2 parents 393a8c7 + cc211ba commit beb7441

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

scripts/check-for-epoch-bump.sh

Lines changed: 14 additions & 3 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 ""
@@ -36,4 +47,4 @@ for yaml_file in "$@"; do
3647
echo "⚠️ Epoch HAS NOT been increased compared to main: $epoch_local <= $epoch_main"
3748
fi
3849

39-
done
50+
done

0 commit comments

Comments
 (0)