File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ endif
190190 $(SED_I) "s/golang:1\.[0-9][0-9]*/golang:$(GOVERSION)/g" $(shell git-ls-files-unstaged | grep Dockerfile)
191191 $(SED_I) "s/golang:1\.[0-9][0-9]*/golang:$(GOVERSION)/g" $(shell git-ls-files-unstaged | grep \.mk$)
192192 $(SED_I) "s/go-version: '1\.[0-9][0-9].x'/go-version: '$(GOVERSION).x'/g" $(shell git-ls-files-unstaged | grep \.github\/workflows | grep -v previous.yaml)
193+ $(MAKE) checkandupdateprecommithooks
193194
194195.PHONY : bufimageutilupdateexpectations
195196bufimageutilupdateexpectations :
@@ -203,3 +204,9 @@ newtodos:
203204.PHONY : newtodofiles
204205newtodofiles :
205206 @bash make/buf/scripts/newtodos.bash | grep -v FUTURE | cut -f 1 -d : | sort | uniq
207+
208+ .PHONY : checkandupdateprecommithooks
209+ checkandupdateprecommithooks :
210+ @bash make/buf/scripts/checkandupdateprecommithooks.bash
211+
212+ postupgrade :: checkandupdateprecommithooks
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -eo pipefail
4+
5+ DIR=" $( CDPATH= cd " $( dirname " ${0} " ) /../../.." && pwd) "
6+ cd " ${DIR} "
7+
8+ GO_VERSION=$( grep ' ^go ' go.mod | awk ' {print $2}' )
9+ # If the version in go.mod does not include the patch version, e.g. go 1.24, for the
10+ # .pre-commit-hook.yaml configuration, we'll need to add a 0.
11+ if [[ ! " ${GO_VERSION} " =~ ' ^([0-9]+\.){3}$' ]]; then
12+ GO_VERSION=" ${GO_VERSION} .0"
13+ fi
14+
15+ function lesser_version() {
16+ echo -e " $1 \n$2 " | sort -V | head -n 1
17+ }
18+
19+ function update_pre_commit_hooks() {
20+ yq .[].language_version=\" ${GO_VERSION} \" .pre-commit-hooks.yaml > .pre-commit-hooks.yaml.tmp
21+ mv .pre-commit-hooks.yaml.tmp .pre-commit-hooks.yaml
22+ }
23+
24+ for version in $( yq " .[].language_version" .pre-commit-hooks.yaml)
25+ do
26+ LESSER_VERSION=$( lesser_version " ${GO_VERSION} " " ${version} " )
27+ if [ ${version} == " ${LESSER_VERSION} " ]; then
28+ echo " found lower pre-commit hook version ${version} compared to go.mod version ${GO_VERSION} "
29+ update_pre_commit_hooks
30+ break
31+ fi
32+ done
You can’t perform that action at this time.
0 commit comments