2
2
set -e
3
3
4
4
# External PCap Service Release Helper Script
5
- # Usage: ./release.sh <version> [--push]
5
+ # Usage: ./release.sh <version> [--push] [--force]
6
6
7
7
VERSION=" $1 "
8
- PUSH_FLAG=" $2 "
8
+ PUSH_FLAG=" "
9
+ FORCE_FLAG=" "
10
+
11
+ # Parse arguments
12
+ shift
13
+ while [[ $# -gt 0 ]]; do
14
+ case $1 in
15
+ --push)
16
+ PUSH_FLAG=" --push"
17
+ shift
18
+ ;;
19
+ --force)
20
+ FORCE_FLAG=" --force"
21
+ shift
22
+ ;;
23
+ * )
24
+ echo " Unknown option: $1 "
25
+ exit 1
26
+ ;;
27
+ esac
28
+ done
9
29
10
30
if [ -z " $VERSION " ]; then
11
- echo " Usage: $0 <version> [--push]"
31
+ echo " Usage: $0 <version> [--push] [--force] "
12
32
echo " "
13
33
echo " Examples:"
14
- echo " $0 1.0.1 # Prepare release (update version, commit, create tag)"
15
- echo " $0 1.0.1 --push # Prepare and push to trigger GitHub Actions"
34
+ echo " $0 1.0.1 # Prepare release (update version, commit, create tag)"
35
+ echo " $0 1.0.1 --push # Prepare and push to trigger GitHub Actions"
36
+ echo " $0 1.0.1 --force # Force overwrite existing version/tag"
37
+ echo " $0 1.0.1 --push --force # Force overwrite and push immediately"
38
+ echo " "
39
+ echo " Options:"
40
+ echo " --push Push changes and tag to remote repository immediately"
41
+ echo " --force Overwrite existing version/tag, force push if needed"
16
42
echo " "
17
43
exit 1
18
44
fi
@@ -37,8 +63,12 @@ CURRENT_VERSION=$(grep '#define PCAP_SERVICE_VERSION ' pcapservice.h | awk -F '"
37
63
echo " Current version in source: $CURRENT_VERSION "
38
64
echo " Target version: $VERSION "
39
65
40
- if [ " $CURRENT_VERSION " = " $VERSION " ]; then
66
+ if [ " $CURRENT_VERSION " = " $VERSION " ] && [ -z " $FORCE_FLAG " ] ; then
41
67
echo " ⚠️ Version is already set to $VERSION in source code"
68
+ echo " Use --force to overwrite existing version"
69
+ exit 1
70
+ elif [ " $CURRENT_VERSION " = " $VERSION " ] && [ -n " $FORCE_FLAG " ]; then
71
+ echo " ⚠️ Version is already set to $VERSION in source code (--force specified, continuing)"
42
72
else
43
73
echo " 📝 Updating version in source code..."
44
74
sed -i.bak " s/#define PCAP_SERVICE_VERSION \" .*\" /#define PCAP_SERVICE_VERSION \" $VERSION \" /" pcapservice.h
50
80
if ! git diff --quiet pcapservice.h; then
51
81
echo " 📦 Committing version update..."
52
82
git add pcapservice.h
53
- git commit -m " bump version to $VERSION "
83
+ if [ -n " $FORCE_FLAG " ]; then
84
+ # Force commit even if there might be conflicts
85
+ git commit -m " bump version to $VERSION " || git commit --amend -m " bump version to $VERSION "
86
+ else
87
+ git commit -m " bump version to $VERSION "
88
+ fi
54
89
echo " ✅ Version update committed"
55
90
else
56
91
echo " ℹ️ No changes to commit"
59
94
# Create tag
60
95
TAG_NAME=" v$VERSION "
61
96
if git rev-parse " $TAG_NAME " > /dev/null 2>&1 ; then
62
- echo " ⚠️ Tag $TAG_NAME already exists"
97
+ if [ -n " $FORCE_FLAG " ]; then
98
+ echo " ⚠️ Tag $TAG_NAME already exists (--force specified, recreating)"
99
+ git tag -d " $TAG_NAME " # Delete local tag
100
+ git tag -a " $TAG_NAME " -m " External PCap Service v$VERSION "
101
+ echo " ✅ Tag $TAG_NAME recreated"
102
+ else
103
+ echo " ⚠️ Tag $TAG_NAME already exists"
104
+ echo " Use --force to overwrite existing tag"
105
+ exit 1
106
+ fi
63
107
else
64
108
echo " 🏷️ Creating tag $TAG_NAME ..."
65
109
git tag -a " $TAG_NAME " -m " External PCap Service v$VERSION "
@@ -72,22 +116,42 @@ echo ""
72
116
73
117
if [ " $PUSH_FLAG " = " --push" ]; then
74
118
echo " 🚢 Pushing changes and tag to trigger GitHub Actions..."
75
- git push origin HEAD
76
- git push origin " $TAG_NAME "
119
+
120
+ if [ -n " $FORCE_FLAG " ]; then
121
+ echo " Using --force push for tag (will overwrite remote tag if exists)"
122
+ git push origin HEAD
123
+ git push origin " $TAG_NAME " --force
124
+ else
125
+ git push origin HEAD
126
+ git push origin " $TAG_NAME "
127
+ fi
128
+
77
129
echo " "
78
130
echo " ✅ Changes pushed! GitHub Actions will now build and release."
79
131
echo " View progress at: https://github.com/whatpulse/linux-external-pcap-service/actions"
80
132
else
81
133
echo " Next steps:"
82
134
echo " 1. Review the changes: git log --oneline -n 2"
83
- echo " 2. Push to trigger release: git push origin HEAD && git push origin $TAG_NAME "
84
- echo " Or run: $0 $VERSION --push"
135
+
136
+ if [ -n " $FORCE_FLAG " ]; then
137
+ echo " 2. Push to trigger release (with force): git push origin HEAD && git push origin $TAG_NAME --force"
138
+ echo " Or run: $0 $VERSION --push --force"
139
+ else
140
+ echo " 2. Push to trigger release: git push origin HEAD && git push origin $TAG_NAME "
141
+ echo " Or run: $0 $VERSION --push"
142
+ fi
143
+
85
144
echo " "
86
145
echo " The GitHub Actions workflow will automatically:"
87
146
echo " • Build the service for Linux"
88
147
echo " • Create packages (deb, rpm, binary)"
89
148
echo " • Generate checksums"
90
149
echo " • Create GitHub release with all assets"
150
+
151
+ if [ -n " $FORCE_FLAG " ]; then
152
+ echo " "
153
+ echo " ⚠️ Force mode enabled - this will overwrite existing releases!"
154
+ fi
91
155
fi
92
156
93
157
echo " "
0 commit comments