Skip to content

Commit

Permalink
feat: add devops.sh for git tag and go mod tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
searKing committed Oct 12, 2024
1 parent 8aaa4e9 commit 065df7b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions devops.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! /bin/bash
#
# Copyright 2024 The searKing Author. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
#

set -euo pipefail

cur_path=$(cd "$(dirname "$0")";pwd)
cd "${cur_path}"

echo "$0" "$*"

args_dir="."
args_tag=""
args_clean_only=OFF
while getopts cd:t:h option; do
case $option in
c) args_clean_only=ON ;;
d) args_dir=$OPTARG ;;
t) args_tag=$OPTARG ;;
h)
echo './devops.sh -d GO-MOD-TIDY-ROOT-DIR-PATH' ;
echo './devops.sh -d GO-MOD-TIDY-ROOT-DIR-PATH' -t 'TAG-VERSION' ;;
?) exit 1 ;;
esac
done

if [[ -z "$args_dir" ]]; then
echo "root dir should not be empty"
exit 1
fi

if [[ -n "$args_tag" ]]; then
git_args=('')
if [ "${args_clean_only}"x = "ON"x ]; then
git_args=(-d)
fi
# cmd="path=\$\(dirname \"\${1#./}\"\);if [ \"\$path\" == \".\" ]; then git tag ${git_args[*]} \"\${TAG}"; else git tag ${git_args[*]} \"\$\{path\}/\$\{TAG\}\"\; fi\;"
cmd="path=\$(dirname \"\${1#./}\");if [ \"\$path\" == \".\" ]; then git tag ${git_args[*]} \"\${TAG}\"; else git tag ${git_args[*]} \"\${path}/\${TAG}\"; fi;"
echo "$cmd"
TAG="${args_tag}" find "${args_dir}" -type f -name "go.mod" -not -path "./.*" -not -path "./*/testdata/*" -exec bash -c "$cmd" sh {} \;
if [ "${args_clean_only}"x = "ON"x ]; then
echo "'$args_tag' tag deleted finished."
else
echo "'$args_tag' tag create finished."
fi
exit 1
fi

# find "${args_dir}" -type f -name "go.mod" -not -path "./.*" -exec bash -c 'cd $(dirname "$1"); go mod tidy; echo $(dirname "${1#./}")' sh {} \;
# echo "go mod tidy finished."

0 comments on commit 065df7b

Please sign in to comment.