-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (63 loc) · 2.98 KB
/
go_modules_check.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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" =~ ^replace ]]; then
continue
fi
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