fix(ci): update script permissions and add docker cleanup functionality (#4523)

This commit is contained in:
hailaz
2025-11-25 14:55:56 +08:00
committed by GitHub
parent a4883e6e3d
commit cdead46c79
4 changed files with 239 additions and 23 deletions

52
.github/workflows/scripts/ci-main.sh vendored Normal file → Executable file
View File

@ -6,56 +6,62 @@ coverage=$1
for file in `find . -name go.mod`; do
dirpath=$(dirname $file)
echo $dirpath
# ignore mssql tests as its docker service failed
# TODO remove this ignoring codes after the mssql docker service OK
if [ "mssql" = $(basename $dirpath) ]; then
# clean docker containers and images to free disk space
bash .github/workflows/scripts/ci-main-clean.sh "$dirpath"
continue 1
fi
# package kubecm was moved to sub ci procedure.
if [ "kubecm" = $(basename $dirpath) ]; then
continue 1
fi
# examples directory was moved to sub ci procedure.
if [[ $dirpath =~ "/examples/" ]]; then
continue 1
fi
if [[ $file =~ "/testdata/" ]]; then
echo "ignore testdata path $file"
continue 1
fi
# Check if it's a contrib directory
if [[ $dirpath =~ "/contrib/" ]]; then
# Check if go version meets the requirement
if ! go version | grep -qE "go${LATEST_GO_VERSION}"; then
echo "ignore path $dirpath as go version is not ${LATEST_GO_VERSION}: $(go version)"
# clean docker containers and images to free disk space
bash .github/workflows/scripts/ci-main-clean.sh "$dirpath"
continue 1
fi
fi
if [[ $file =~ "/testdata/" ]]; then
echo "ignore testdata path $file"
continue 1
fi
if [[ $dirpath = "." ]]; then
# No space left on device error sometimes occurs in CI pipelines, so clean the cache before tests.
go clean -cache
fi
# if [[ $dirpath = "." ]]; then
# # No space left on device error sometimes occurs in CI pipelines, so clean the cache before tests.
# go clean -cache
# fi
cd $dirpath
go mod tidy
go build ./...
# test with coverage
if [ "${coverage}" = "coverage" ]; then
go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1
if grep -q "/gogf/gf/.*/v2" go.mod; then
sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out
fi
go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1
if grep -q "/gogf/gf/.*/v2" go.mod; then
sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out
fi
else
go test ./... -race || exit 1
go test ./... -race || exit 1
fi
cd -
# clean docker containers and images to free disk space
bash .github/workflows/scripts/ci-main-clean.sh "$dirpath"
done