File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33README_SECTIONS_DIR=" ./docs/readme-sections"
44README_PATH=" ./README.md"
5+ BADGES_PATH=" $README_SECTIONS_DIR /badges.md"
56MANIFEST=" $README_SECTIONS_DIR /github-manifest"
67
78if [[ $# -ne 1 ]]; then
1112
1213MODE=" $1 "
1314
15+ # Function to update badges with current OPA version
16+ update_badges () {
17+ # Extract OPA version using go command and jq
18+ OPA_VERSION=$( go list -m -json github.com/open-policy-agent/opa | jq -r ' .Version' )
19+
20+ if [[ -z " $OPA_VERSION " ]]; then
21+ echo " Error: Could not find OPA version using go list command" >&2
22+ exit 1
23+ fi
24+
25+ # Create a temporary file for badges
26+ badges_tmpfile=$( mktemp)
27+
28+ # Read the badges file and update the OPA badge line
29+ while IFS= read -r line; do
30+ if [[ $line =~ ^\!\[ OPA\ v[0-9]+\. [0-9]+\. [0-9]+\] ]]; then
31+ echo " " >> " $badges_tmpfile "
32+ else
33+ echo " $line " >> " $badges_tmpfile "
34+ fi
35+ done < " $BADGES_PATH "
36+
37+ # Check if badges need updating
38+ if ! cmp -s " $badges_tmpfile " " $BADGES_PATH " ; then
39+ if [[ " $MODE " == " write" ]]; then
40+ mv " $badges_tmpfile " " $BADGES_PATH "
41+ echo " Updated badges.md with OPA version $OPA_VERSION ."
42+ else
43+ rm " $badges_tmpfile "
44+ echo " README.md is out of date (badges need OPA version update to $OPA_VERSION ). Please run '$0 write' to update it."
45+ exit 1
46+ fi
47+ else
48+ rm " $badges_tmpfile "
49+ fi
50+ }
51+
52+ # Update badges first
53+ update_badges
54+
1455# Create a temporary file to hold the new content
1556tmpfile=$( mktemp)
1657
You can’t perform that action at this time.
0 commit comments