Skip to content

Commit

Permalink
[CI] Check Go modules version (#82)
Browse files Browse the repository at this point in the history
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
  • Loading branch information
duckhawk authored Aug 14, 2024
1 parent 969dc81 commit 1507497
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
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/agent/src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module agent
go 1.22.2

require (
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240709091744-c9d24f05db41
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b
github.com/go-logr/logr v1.4.1
github.com/google/go-cmp v0.6.0
github.com/onsi/ginkgo/v2 v2.17.1
Expand Down
4 changes: 2 additions & 2 deletions images/agent/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/sds-node-configurator/api v0.0.0-20240709091744-c9d24f05db41 h1:kfnAfII4E8yWkDZ4FJIPO9/OvXkMIQDPLB3zzNBo8Wg=
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240709091744-c9d24f05db41/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0=
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b h1:EYmHWTWcWMpyxJGZK05ZxlIFnh9s66DRrxLw/LNb/xw=
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0=
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 v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
Expand Down
2 changes: 1 addition & 1 deletion images/sds-health-watcher-controller/src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.3
require (
github.com/cloudflare/cfssl v1.5.0
github.com/deckhouse/deckhouse v1.62.4
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240709091744-c9d24f05db41
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b
github.com/go-logr/logr v1.4.1
github.com/prometheus/client_golang v1.19.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions images/sds-health-watcher-controller/src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ 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/deckhouse v1.62.4 h1:Jgd9TSGLRE/0nYsg3KabMvguVp+d6oqt/GTxO7EHgO4=
github.com/deckhouse/deckhouse v1.62.4/go.mod h1:uJICbx/itedld6N9uv3srI6Hdt+m4P6IQyocUrtySVY=
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240709091744-c9d24f05db41 h1:kfnAfII4E8yWkDZ4FJIPO9/OvXkMIQDPLB3zzNBo8Wg=
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240709091744-c9d24f05db41/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0=
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b h1:EYmHWTWcWMpyxJGZK05ZxlIFnh9s66DRrxLw/LNb/xw=
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0=
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 v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
Expand Down

0 comments on commit 1507497

Please sign in to comment.