-
Notifications
You must be signed in to change notification settings - Fork 565
🌱 Add go-version check to avoid upgrade versions for those that we cannot support yet #3561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
camilamacedo86
merged 2 commits into
operator-framework:master
from
camilamacedo86:add-goversion-checl
Apr 30, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: go-verdiff | ||
on: | ||
pull_request: | ||
paths: | ||
- '**.mod' | ||
- '.github/workflows/go-verdiff.yaml' | ||
branches: | ||
- main | ||
jobs: | ||
go-verdiff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Check golang version | ||
run: hack/tools/check-go-version.sh "${{ github.event.pull_request.base.sha }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
|
||
########################################### | ||
# Check Go version in go.mod files | ||
# and ensure it is not greater than the | ||
# version in the main go.mod file. | ||
# Also check if the version in the main | ||
# go.mod file is updated in the | ||
# submodules. | ||
# This script is intended to be run | ||
# as part of the CI pipeline to ensure | ||
# that the version of Go that we can use | ||
# is not accidentally upgraded. | ||
# Source: https://github.com/operator-framework/operator-controller/blob/main/hack/tools/check-go-version.sh | ||
# | ||
# PS: We have the intention to centralize | ||
# this implementation in the future. | ||
########################################### | ||
|
||
|
||
BASE_REF=${1:-main} | ||
GO_VER=$(sed -En 's/^go (.*)$/\1/p' "go.mod") | ||
OLDIFS="${IFS}" | ||
IFS='.' MAX_VER=(${GO_VER}) | ||
IFS="${OLDIFS}" | ||
|
||
if [ ${#MAX_VER[*]} -ne 3 -a ${#MAX_VER[*]} -ne 2 ]; then | ||
echo "Invalid go version: ${GO_VER}" | ||
exit 1 | ||
fi | ||
|
||
GO_MAJOR=${MAX_VER[0]} | ||
GO_MINOR=${MAX_VER[1]} | ||
GO_PATCH=${MAX_VER[2]} | ||
|
||
RETCODE=0 | ||
|
||
check_version () { | ||
local whole=$1 | ||
local file=$2 | ||
OLDIFS="${IFS}" | ||
IFS='.' ver=(${whole}) | ||
IFS="${OLDIFS}" | ||
|
||
if [ ${ver[0]} -gt ${GO_MAJOR} ]; then | ||
echo "${file}: ${whole}: Bad golang version (expected ${GO_VER} or less)" | ||
return 1 | ||
fi | ||
if [ ${ver[1]} -gt ${GO_MINOR} ]; then | ||
echo "${file}: ${whole}: Bad golang version (expected ${GO_VER} or less)" | ||
return 1 | ||
fi | ||
|
||
if [ ${#ver[*]} -eq 2 ] ; then | ||
return 0 | ||
fi | ||
if [ ${#ver[*]} -ne 3 ] ; then | ||
echo "${file}: ${whole}: Badly formatted golang version" | ||
return 1 | ||
fi | ||
|
||
if [ ${ver[1]} -eq ${GO_MINOR} -a ${ver[2]} -gt ${GO_PATCH} ]; then | ||
echo "${file}: ${whole}: Bad golang version (expected ${GO_VER} or less)" | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
echo "Found golang version: ${GO_VER}" | ||
|
||
for f in $(find . -name "*.mod"); do | ||
v=$(sed -En 's/^go (.*)$/\1/p' ${f}) | ||
if [ -z ${v} ]; then | ||
echo "${f}: Skipping, no version found" | ||
continue | ||
fi | ||
if ! check_version ${v} ${f}; then | ||
RETCODE=1 | ||
fi | ||
old=$(git grep -ohP '^go .*$' "${BASE_REF}" -- "${f}") | ||
old=${old#go } | ||
new=$(git grep -ohP '^go .*$' "${f}") | ||
new=${new#go } | ||
# If ${old} is empty, it means this is a new .mod file | ||
if [ -z "${old}" ]; then | ||
continue | ||
fi | ||
# Check if patch version remains 0: X.x.0 <-> X.x | ||
if [ "${new}.0" == "${old}" -o "${new}" == "${old}.0" ]; then | ||
continue | ||
fi | ||
if [ "${new}" != "${old}" ]; then | ||
echo "${f}: ${v}: Updated golang version from ${old}" | ||
RETCODE=1 | ||
fi | ||
done | ||
|
||
exit ${RETCODE} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.