Skip to content

Commit 4358071

Browse files
committed
Fix release target
1 parent c7f351c commit 4358071

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,10 @@ add_custom_target(package DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}")
5454

5555
# create a release (by pushing a tag to the repository)
5656

57-
find_program(GIT git REQUIRED)
58-
find_program(GREP grep REQUIRED)
59-
6057
add_custom_target(
6158
release
6259
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
63-
COMMAND "${GIT}" diff-index --quiet HEAD -- # check for uncommitted changes
64-
COMMAND "${GIT}" branch --show-current | "${GREP}" -qx main # check for main branch
65-
COMMAND "${GIT}" cherry -v origin/main | "${GREP}" grep -q "'^'" # check for unpushed commits
66-
COMMAND "${GIT}" tag "v${CMAKE_PROJECT_VERSION}"
67-
COMMAND "${GIT}" push "v${CMAKE_PROJECT_VERSION}")
60+
COMMAND bash release.sh "${CMAKE_PROJECT_VERSION}")
6861

6962
# optional examples
7063

release.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Exit on any error
4+
set -e
5+
6+
# Check if VERSION parameter is provided
7+
if [ $# -eq 0 ]; then
8+
echo "Error: VERSION parameter is required"
9+
echo "Usage: $0 <VERSION>"
10+
exit 1
11+
fi
12+
13+
VERSION=$1
14+
15+
# Check for uncommitted changes
16+
if ! git diff-index --quiet HEAD --; then
17+
echo "Error: There are uncommitted changes in the repository"
18+
exit 1
19+
fi
20+
21+
# Check if on main branch
22+
if [ "$(git branch --show-current)" != "main" ]; then
23+
echo "Error: You must be on the main branch"
24+
exit 1
25+
fi
26+
27+
# Check for unpushed commits
28+
if [ -n "$(git cherry -v origin/main)" ]; then
29+
echo "Error: There are unpushed commits"
30+
exit 1
31+
fi
32+
33+
# Create and push tag
34+
git tag "v$VERSION"
35+
git push origin "v$VERSION"
36+
37+
echo "Successfully created and pushed tag v$VERSION"

0 commit comments

Comments
 (0)