Skip to content
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

[CI] Check Go modules version #30

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/go_modules_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Check Go modules version

on:
pull_request:
push:
branches:
- main

jobs:
test:
name: Check Go modules version
runs-on: [self-hosted, regular]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Run Go modules version check
run: |
search_dir=$(pwd)"/images"

if [ ! -d "$search_dir" ]; then
echo "Directory $search_dir does not exist."
exit 1
fi

temp_dir=$(mktemp -d)

trap 'rm -rf "$temp_dir"' EXIT

find "$search_dir" -name "go.mod" | while read -r go_mod_file; do
echo "Processing $go_mod_file"

while IFS= read -r line; do
if [[ "$line" == *github.com/deckhouse/sds-* || "$line" == *github.com/deckhouse/csi-* || "$line" == *github.com/deckhouse/virtualization ]]; then
repository=$(echo "$line" | awk '{print $1}' | awk -F'/' '{ print "https://"$1"/"$2"/"$3".git" }')
pseudo_tag=$(echo "$line" | awk '{print $2}')
echo "Cloning repo $repository into $temp_dir"

git clone "$repository" "$temp_dir/$repository" >/dev/null 2>&1

if [ -d "$temp_dir/$repository/api" ]; then
cd "$temp_dir/$repository" || continue

commit_info=$(git log -1 --pretty=format:"%H %cd" --date=iso-strict -- api/*)
short_hash=$(echo "$commit_info" | awk '{print substr($1,1,12)}')
commit_date=$(echo "$commit_info" | awk '{print $2}')
commit_date=$(date -u -d "$commit_date" +"%Y%m%d%H%M%S")
actual_pseudo_tag="v0.0.0-"$commit_date"-"$short_hash
pseudo_tag_date=$(echo $pseudo_tag | awk -F'-' '{ print $2 }')
echo "Latest commit in $repository: $short_hash $commit_date"

if [[ "$pseudo_tag_date" < "$commit_date" ]]; then
echo "Incorrect pseudo tag for repo $repository in file "$go_mod_file" (current: "$pseudo_tag", actual:"$actual_pseudo_tag")"
echo "Incorrect pseudo tag for repo $repository in file "$go_mod_file" (current: "$pseudo_tag", actual:"$actual_pseudo_tag")" >> $temp_dir"/incorrect_alert"
fi

cd - >/dev/null 2>&1
else
echo "No api directory in $repository"
fi

rm -rf "$temp_dir/$repository"
fi
done < "$go_mod_file"
done

alert_lines_count=$(cat $temp_dir"/incorrect_alert" | wc -l)

if [ $alert_lines_count != 0 ]; then
echo "We have non-actual pseudo-tags in repository's go.mod files"
exit 1
fi
2 changes: 1 addition & 1 deletion images/controller/src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module d8-controller
go 1.22.2

require (
github.com/deckhouse/csi-nfs/api v0.0.0-20240704080754-e01c61835a0f
github.com/deckhouse/csi-nfs/api v0.0.0-20240803013516-738ee1ca87bc
github.com/go-logr/logr v1.4.1
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.0
Expand Down
4 changes: 2 additions & 2 deletions images/controller/src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckhouse/csi-nfs/api v0.0.0-20240704080754-e01c61835a0f h1:7OVfWIlhYsA+/x91TgWf96dAaaZpo1UxHDYX/srt8jE=
github.com/deckhouse/csi-nfs/api v0.0.0-20240704080754-e01c61835a0f/go.mod h1:/vXhdSgMvU4dP2MvOHOFZua9MvJoAPLM/hk6p7rE+Jc=
github.com/deckhouse/csi-nfs/api v0.0.0-20240803013516-738ee1ca87bc h1:FRil0A1OjAHQl5Hkf2eVcU6/jrtLKMVfIOo5RDQf5NM=
github.com/deckhouse/csi-nfs/api v0.0.0-20240803013516-738ee1ca87bc/go.mod h1:/vXhdSgMvU4dP2MvOHOFZua9MvJoAPLM/hk6p7rE+Jc=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
Expand Down
Loading