1818 - name : Checkout repository
1919 uses : actions/checkout@v2
2020
21- - name : Setup Go environment
22- uses : actions/setup-go@v5
23- with :
24- go-version : " 1.24"
25-
26- - name : Install golangci-lint
27- run :
go install github.com/golangci/golangci-lint/cmd/[email protected] 28-
2921 - name : Run Go lint
30- run : |
31- basedir=$(pwd)
32- failed='false'
33- for i in $(find images -type f -name go.mod);do
34- dir=$(echo $i | sed 's/go.mod$//')
35- cd $basedir/$dir
36- # check all editions
37- for edition in $GO_BUILD_TAGS ;do
38- echo "Running linter in $dir (edition: $edition)"
39- golangci-lint run --build-tags $edition
40- if [ $? -ne 0 ]; then
41- echo "Linter failed in $dir (edition: $edition)"
42- failed='true'
43- fi
44- done
45- done
46- if [ $failed == 'true' ]; then
47- exit 1
48- fi
22+ uses : deckhouse/modules-actions/go_linter@v2
4923
5024 go_tests :
5125 name : Go tests for images
5529 - name : Checkout repository
5630 uses : actions/checkout@v2
5731
58- - name : Setup Go environment
59- uses : actions/setup-go@v5
60- with :
61- go-version : " 1.24"
62-
6332 - name : Run Go tests
64- run : |
65- basedir=$(pwd)
66- failed='false'
67- for i in $(find images -type f -name '*_test.go');do
68- dir=$(echo $i | sed 's/[a-z_A-Z0-9-]*_test.go$//')
69- cd $basedir/$dir
70- # check all editions
71- for edition in $GO_BUILD_TAGS ;do
72- echo "Running tests in $dir (edition: $edition)"
73- go test -v -tags $edition
74- if [ $? -ne 0 ]; then
75- echo "Tests failed in $dir (edition: $edition)"
76- failed='true'
77- fi
78- done
79- done
80- if [ $failed == 'true' ]; then
81- exit 1
82- fi
33+ uses : deckhouse/modules-actions/go_tests@v2
8334
8435 go_test_coverage :
8536 name : Go test coverage for images
8940 - name : Checkout repository
9041 uses : actions/checkout@v2
9142
92- - name : Setup Go environment
93- uses : actions/setup-go@v5
94- with :
95- go-version : " 1.24"
96-
9743 - name : Run Go test coverage count
98- run : |
99- if [ ! -d "images" ]; then
100- echo "No images/ directory found. Please run this script from the root of the repository."
101- exit 1
102- fi
103-
104- find images/ -type f -name "go.mod" | while read -r gomod; do
105- dir=$(dirname "$gomod")
106-
107- echo "Test coverage in $dir"
108-
109- cd "$dir" || continue
110-
111- for tag in $GO_BUILD_TAGS; do
112- echo " Build tag: $tag"
113-
114- go test ./... -cover -tags "$tag"
115- done
116-
117- cd - > /dev/null
118-
119- echo "----------------------------------------"
120- done
44+ uses : deckhouse/modules-actions/go_test_coverage@v2
12145
12246 go_modules_check :
12347 name : Go modules version
@@ -127,83 +51,5 @@ jobs:
12751 - name : Checkout repository
12852 uses : actions/checkout@v2
12953
130- - name : Setup Go environment
131- uses : actions/setup-go@v5
132- with :
133- go-version : " 1.24"
134-
13554 - name : Run Go modules version check
136- run : |
137- search_dir=$(pwd)"/images"
138-
139- if [ ! -d "$search_dir" ]; then
140- echo "Directory $search_dir does not exist."
141- exit 1
142- fi
143-
144- temp_dir=$(mktemp -d)
145- touch "$temp_dir/incorrect_alert"
146-
147- trap 'rm -rf "$temp_dir"' EXIT
148-
149- find images/ -type f -name "go.mod" | while read -r gomod; do
150- dir=$(dirname "$gomod")
151-
152- echo "Checking $dir"
153-
154- cd "$dir" || continue
155-
156- go list -m all | grep deckhouse | grep -v '=>' | while IFS= read -r line; do
157- module_name=$(echo "$line" | awk '{print $1}')
158- module_version=$(echo "$line" | awk '{print $2}')
159-
160- if [ -z "$module_version" ]; then
161- echo " Checking module name $module_name"
162- correct_module_name="github.com"/"$GITHUB_REPOSITORY"/"$dir"
163- if [ "$module_name" != "$correct_module_name" ]; then
164- echo " Incorrect module name: $module_name, expected: $correct_module_name"
165- echo " Incorrect module name: $module_name, expected: $correct_module_name" >> "$temp_dir/incorrect_alert"
166- else
167- echo " Correct module name: $module_name"
168- fi
169- else
170- echo " Checking module tag $module_name"
171- repository=$(echo "$line" | awk '{print $1}' | awk -F'/' '{ print "https://"$1"/"$2"/"$3".git" }')
172- pseudo_tag=$(echo "$line" | awk '{print $2}')
173-
174- echo " Cloning repo $repository into $temp_dir"
175- if [ ! -d "$temp_dir/$repository" ]; then
176- git clone "$repository" "$temp_dir/$repository" >/dev/null 2>&1
177- fi
178-
179- cd "$temp_dir/$repository" || continue
180-
181- commit_info=$(git log -1 --pretty=format:"%H %cd" --date=iso-strict -- api/*)
182- short_hash=$(echo "$commit_info" | awk '{print substr($1,1,12)}')
183- commit_date=$(echo "$commit_info" | awk '{print $2}')
184- commit_date=$(date -u -d "$commit_date" +"%Y%m%d%H%M%S")
185- actual_pseudo_tag="v0.0.0-"$commit_date"-"$short_hash
186- pseudo_tag_date=$(echo $pseudo_tag | awk -F'-' '{ print $2 }')
187- echo " Latest pseudo tag for $repository: $pseudo_tag"
188- echo " Actual pseudo tag for $repository: $actual_pseudo_tag"
189-
190- if [[ "$pseudo_tag" != "$actual_pseudo_tag" ]]; then
191- echo " Incorrect pseudo tag for repo $repository in file "$go_mod_file" (current: "$pseudo_tag", actual:"$actual_pseudo_tag")"
192- echo " Incorrect pseudo tag for repo $repository in file "$go_mod_file" (current: "$pseudo_tag", actual:"$actual_pseudo_tag")" >> $temp_dir"/incorrect_alert"
193- fi
194-
195- cd - >/dev/null 2>&1
196- fi
197- done
198-
199- cd - > /dev/null
200-
201- echo "----------------------------------------"
202- done
203-
204- alert_lines_count=$(cat $temp_dir"/incorrect_alert" | wc -l)
205-
206- if [ $alert_lines_count != 0 ]; then
207- echo "We have non-actual pseudo-tags or modules names in repository's go.mod files"
208- exit 1
209- fi
55+ uses : deckhouse/modules-actions/go_modules_check@v2
0 commit comments