Skip to content

Commit 06a04a3

Browse files
committed
Updates tag-all.sh script to include show
1 parent 6dd6e21 commit 06a04a3

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

scripts/tag-all.sh

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ NC='\033[0m' # No Color
1717
# Function to show help
1818
show_help() {
1919
echo "USAGE: $0 <version>"
20+
echo " $0 show"
2021
echo " $0 --help"
2122
echo
2223
echo " <version> Semantic version (vX.Y.Z)"
24+
echo " show Show latest tags for all repos"
2325
echo
2426
echo "EXAMPLE: $0 v6.4.6"
27+
echo " $0 show"
2528
}
2629

2730
#------------------------------------------------
@@ -31,6 +34,33 @@ if [ $# -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
3134
exit 0
3235
fi
3336

37+
if [ "$1" = "show" ]; then
38+
# Show mode - display latest tags
39+
echo -e "${YELLOW}[tag-all]${NC} Showing latest tags:"
40+
echo
41+
42+
# Show root repo tag
43+
echo -e "${GREEN}Root repository:${NC}"
44+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "No tags found")
45+
echo " Latest tag: $LATEST_TAG"
46+
echo
47+
48+
# Show submodule tags
49+
SUBMODULES=$(git submodule status | awk '{print $2}')
50+
if [ -n "$SUBMODULES" ]; then
51+
echo -e "${GREEN}Submodules:${NC}"
52+
for SUBMODULE in $SUBMODULES; do
53+
if [ -d "$SUBMODULE" ]; then
54+
cd "$SUBMODULE" || continue
55+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "No tags found")
56+
echo " $SUBMODULE: $LATEST_TAG"
57+
cd "$SCRIPT_DIR/.." || exit 1
58+
fi
59+
done
60+
fi
61+
exit 0
62+
fi
63+
3464
if [ $# -ne 1 ]; then
3565
echo -e "${RED}Error: Invalid number of arguments${NC}"
3666
echo
@@ -69,7 +99,9 @@ for SUBMODULE in $SUBMODULES; do
6999
done
70100

71101
echo
72-
echo -e "${YELLOW}WARNING:${NC} This will FORCE TAG and FORCE PUSH version $VERSION to all submodules above."
102+
echo -e "${YELLOW}WARNING:${NC} This will FORCE TAG and FORCE PUSH version $VERSION to:"
103+
echo " - Root repository (trueblocks-core)"
104+
echo " - All submodules listed above"
73105
echo -e "${YELLOW}WARNING:${NC} Any existing tags with this version will be overwritten."
74106
echo
75107
read -p "Are you sure you want to continue? (y/N): " -n 1 -r
@@ -81,6 +113,47 @@ fi
81113

82114
echo
83115

116+
#------------------------------------------------
117+
# Tag and push root repository first
118+
echo -e "${YELLOW}[tag-all]${NC} Processing root repository"
119+
120+
# Check if root is on main branch
121+
CURRENT_BRANCH=$(git branch --show-current)
122+
if [ "$CURRENT_BRANCH" != "main" ]; then
123+
echo -e "${RED}Error: Root repository is not on main branch (currently on: $CURRENT_BRANCH)${NC}"
124+
exit 1
125+
fi
126+
127+
# Check for uncommitted changes in root
128+
if ! git diff-index --quiet HEAD --; then
129+
echo -e "${RED}Error: Root repository has uncommitted changes${NC}"
130+
git status --porcelain
131+
exit 1
132+
fi
133+
134+
# Check for untracked files in root
135+
if [ -n "$(git status --porcelain)" ]; then
136+
echo -e "${RED}Error: Root repository has untracked or staged files${NC}"
137+
git status --porcelain
138+
exit 1
139+
fi
140+
141+
# Force tag the root repository
142+
echo -e "${YELLOW}[tag-all]${NC} Tagging root repository with $VERSION"
143+
if ! git tag -f "$VERSION"; then
144+
echo -e "${RED}Error: Failed to tag root repository${NC}"
145+
exit 1
146+
fi
147+
148+
# Force push the tag from root
149+
echo -e "${YELLOW}[tag-all]${NC} Force pushing root tag to remote"
150+
if ! git push -f origin "$VERSION"; then
151+
echo -e "${RED}Error: Failed to push tag for root repository${NC}"
152+
exit 1
153+
fi
154+
155+
echo -e "${GREEN}[tag-all]${NC} Successfully tagged root repository"
156+
84157
#------------------------------------------------
85158
# Process each submodule
86159
for SUBMODULE in $SUBMODULES; do
@@ -142,5 +215,5 @@ for SUBMODULE in $SUBMODULES; do
142215
done
143216

144217
echo
145-
echo -e "${GREEN}[tag-all]${NC} Successfully tagged all submodules with version: $VERSION"
218+
echo -e "${GREEN}[tag-all]${NC} Successfully tagged root repository and all submodules with version: $VERSION"
146219
echo -e "${GREEN}[tag-all]${NC} Done."

0 commit comments

Comments
 (0)